void PictureWidget::Draw(const Point2i &/*mousePosition*/) { if (!loaded) { if (name.empty()) return; Profile *res = GetResourceManager().LoadXMLProfile("graphism.xml", false); SetSurface(LOAD_RES_IMAGE(name), type); // Needed to set the resizing ApplyScaling(type); } if (!spr) return; Surface & surf = GetMainWindow(); Point2i pos = GetPicturePosition(); spr->Blit(surf, pos); // Draw a transparency mask if (disabled) { surf.BoxColor(Rectanglei(pos, spr->GetSize()), defaultOptionColorBox); } }
/* Picture node example : <Picture file="menu/image.png" alpha="false" x="0" y="0" width="100" height="100" scale="true" antialiasing="true" /> */ bool PictureWidget::LoadXMLConfiguration() { if (NULL == profile || NULL == widgetNode) { //TODO error ... xml attributs not initialized ! return false; } XmlReader * xmlFile = profile->GetXMLDocument(); std::string file("menu/pic_not_found.png"); xmlFile->ReadStringAttr(widgetNode, "file", file); bool activeAlpha = false; xmlFile->ReadBoolAttr(widgetNode, "alpha", activeAlpha); file = profile->relative_path + file; Surface surface(file.c_str()); if (!activeAlpha) { surface = surface.DisplayFormat(); } else { surface = surface.DisplayFormatAlpha(); } ParseXMLGeometry(); ParseXMLMisc(); bool activeScale = false; xmlFile->ReadBoolAttr(widgetNode, "scale", activeScale); SetSurface(surface, activeScale ? FIT_SCALING : NO_SCALING); return true; }
/// <summary> /// Generates mipmaps if the specified texture has the levels to accommodate them. /// </summary> /// <param name="src">The DirectX texture to apply mipmaps to.</param> /// <param name="njs_texture">The Dremcast texture to receive the DirectX texture.</param> static void __fastcall GenerateMipmaps_c(IDirect3DTexture8* src, NJS_TEXMEMLIST* njs_texture) { if (src == nullptr || njs_texture == nullptr) return; if (blacklisted || src->GetLevelCount() > 1) goto ABORT; #ifndef PALLETIZED_MIPMAPS Uint32 format = njs_texture->texinfo.texsurface.PixelFormat; if (format == NJD_PIXELFORMAT_PALETTIZED_4BPP || format == NJD_PIXELFORMAT_PALETTIZED_8BPP) goto ABORT; #endif HRESULT result; D3DSURFACE_DESC info; result = src->GetLevelDesc(0, &info); if (!SUCCEEDED(result)) goto ABORT; IDirect3DTexture8* dest; result = Direct3D_Device->CreateTexture(info.Width, info.Height, 0, info.Usage, info.Format, info.Pool, &dest); if (!SUCCEEDED(result)) goto ABORT; result = CopyTexture(dest, src, info.Height); if (!SUCCEEDED(result)) goto ABORT; result = D3DXFilterTexture(dest, nullptr, D3DX_DEFAULT, D3DX_DEFAULT); if (!SUCCEEDED(result)) { PrintDebug("Mipmap generation failed with error code 0x%08X\n", result); dest->Release(); goto ABORT; } src->Release(); SetSurface(dest, &njs_texture->texinfo.texsurface); return; ABORT: SetSurface(src, &njs_texture->texinfo.texsurface); return; }
PictureWidget::PictureWidget(const Surface & s, ScalingType type) : Widget(s.GetSize(), false) , disabled(false) , type(type) , spr(NULL) { SetSurface(s, type); }
void nuiPainter::PopSurface() { nuiSurface* pSurface = mpSurfaceStack.top(); mpSurfaceStack.pop(); SetSurface(pSurface); if (pSurface) pSurface->Release(); }
bool Surface::SetDisplayFormatAlpha() { SDL_Surface *tmp = SDL_DisplayFormatAlpha(me); if(!tmp) return false; SetSurface(tmp); return true; }
void ImageSysData::Paint(SystemDraw& w, int x, int y, const Rect& src, Color c) { GuiLock __; x += w.GetOffset().x; y += w.GetOffset().y; Size sz = img.GetSize(); int len = sz.cx * sz.cy; Rect sr = src & sz; Size ssz = sr.Size(); if(sr.IsEmpty()) return; int kind = img.GetKind(); if(kind == IMAGE_EMPTY) return; if(kind == IMAGE_OPAQUE && !IsNull(c)) { w.DrawRect(x, y, sz.cx, sz.cy, c); return; } if(kind == IMAGE_OPAQUE && paintcount == 0 && sr == Rect(sz)) { SetSurface(w, x, y, sz.cx, sz.cy, ~img); paintcount++; return; } if(IsNull(c)) { if(!picture) { bool opaque = kind == IMAGE_OPAQUE; Pixmap pixmap = XCreatePixmap(Xdisplay, Xroot, sz.cx, sz.cy, opaque ? 24 : 32); picture = XRenderCreatePicture( Xdisplay, pixmap, XRenderFindStandardFormat(Xdisplay, opaque ? PictStandardRGB24 : PictStandardARGB32), 0, 0 ); XImage ximg; sInitXImage(ximg, sz); ximg.bitmap_pad = 32; ximg.bytes_per_line = 4 * sz.cx; ximg.bits_per_pixel = 32; ximg.blue_mask = 0x00ff0000; ximg.green_mask = 0x0000ff00; ximg.red_mask = 0x000000ff; ximg.bitmap_unit = 32; ximg.data = (char *)~img; ximg.depth = opaque ? 24 : 32; XInitImage(&ximg); GC gc = XCreateGC(Xdisplay, pixmap, 0, 0); XPutImage(Xdisplay, pixmap, gc, &ximg, 0, 0, 0, 0, sz.cx, sz.cy); XFreeGC(Xdisplay, gc); XFreePixmap(Xdisplay, pixmap); SysImageRealized(img); } XRenderComposite(Xdisplay, PictOpOver, picture, 0, XftDrawPicture(w.GetXftDraw()), sr.left, sr.top, 0, 0, x, y, ssz.cx, ssz.cy); } else { if(!picture8) { Pixmap pixmap = XCreatePixmap(Xdisplay, Xroot, sz.cx, sz.cy, 8); picture8 = XRenderCreatePicture(Xdisplay, pixmap, XRenderFindStandardFormat(Xdisplay, PictStandardA8), 0, 0); Buffer<byte> ab(len); byte *t = ab; const RGBA *s = ~img; const RGBA *e = s + len; while(s < e) *t++ = (s++)->a; XImage ximg; sInitXImage(ximg, sz); ximg.data = (char *)~ab; ximg.bitmap_unit = 8; ximg.bitmap_pad = 8; ximg.depth = 8; ximg.bytes_per_line = sz.cx; ximg.bits_per_pixel = 8; XInitImage(&ximg); GC gc = XCreateGC(Xdisplay, pixmap, 0, 0); XPutImage(Xdisplay, pixmap, gc, &ximg, 0, 0, 0, 0, sz.cx, sz.cy); XFreeGC(Xdisplay, gc); XFreePixmap(Xdisplay, pixmap); } XRenderComposite(Xdisplay, PictOpOver, sGetSolidFill(c), picture8, XftDrawPicture(w.GetXftDraw()), sr.left, sr.top, 0, 0, x, y, ssz.cx, ssz.cy); } }
int CBSPMapData_LW::LoadSpecificMapDataFromFile( const char *pFilename ) { int i; bool bResult = false; CLightWaveSceneLoader lightwave_scene; // load the LightWave scene file lightwave_scene.LoadFromFile( pFilename ); // MessageBox(NULL, "LW scene file has been loaded", "progress report", MB_OK); //First, we have to get the name of the mapfile in this "*.lws" file //The name of the mapfile has to be "_MAP_*.lwo" (* is can be an arbitrary string) // find the object file that has the filename starting with "_MAP_" CLWS_ObjectLayer* pObjectLayer = NULL; // char* pLWOFileName; // string strBodyFilename; char acBodyFilename[512]; for( i=0; i<lightwave_scene.GetNumObjectLayers(); i++ ) { pObjectLayer = lightwave_scene.GetObjectLayer(i); if( !pObjectLayer ) MessageBox(NULL, "invalid object layer", "error", MB_OK|MB_ICONWARNING); // pLWOFileName = pObjectLayer->GetObjectFilename().c_str(); string& strLWOFilename = pObjectLayer->GetObjectFilename(); CFileNameOperation::GetBodyFilenameBySlash( acBodyFilename, strLWOFilename.c_str() ); //find lwo2 file that represents the map object. if( strncmp( acBodyFilename, "_MAP_", 5 ) == 0 ) { // load the object bResult = m_LWO2Object.LoadLWO2Object(acBodyFilename); break; } } // compute normals on each face(polygon) in the LightWave object // m_LWO2Object.ComputeFaceNormals(); string log_filename = "DebugInfoFile\\lwo2_loaded_data.txt"; m_LWO2Object.WriteDebug(log_filename.c_str()); list<LWO2_Layer>::iterator itrLayer; this->m_aPlane.reserve(DEFAULT_NUM_PLANES); this->m_aMainFace.reserve(DEFAULT_NUM_MAINFACES); this->m_aInteriorFace.reserve(DEFAULT_NUM_MAINFACES); // itrLayer = m_LWO2Object.m_layer.begin(); list<LWO2_Layer>& lstLayer = m_LWO2Object.GetLayer(); itrLayer = lstLayer.begin(); for(; itrLayer != lstLayer.end() ; itrLayer++) { if( itrLayer->GetName() == "LYR_Slag" ) continue; if( itrLayer->GetName() == "LYR_Main" ) SetFace(&m_aMainFace, itrLayer); if( itrLayer->GetName() == "LYR_Interior" ) SetFace(&m_aInteriorFace, itrLayer); if( itrLayer->GetName() == "LYR_Skybox" ) SetFace(&m_aSkyboxFace, itrLayer); if( itrLayer->GetName() == "LYR_EnvLight" ) { C3DMeshModelBuilder_LW mesh_builder( &m_LWO2Object ); mesh_builder.BuildMeshFromLayer( *itrLayer ); m_EnvLightMesh = mesh_builder.GetArchive(); } /* if( itrLayer->GetName() == "LYR_BoundingVolume" ) SetFace; if( itrLayer->GetName() == "LYR_NoClip" ) SetFace;*/ } // Sort textures and others SetTextureFilename(); // set texture indices SetSurface(); // create additional filenames to support fake bumpy textures SetFakeBumpTextures(); //convert lightwave fog into generic fog CLWS_Fog* pLWSFog = lightwave_scene.GetFog(); if( pLWSFog ) { m_pFog = new SFog; m_pFog->cFogType = (char)pLWSFog->iType; m_pFog->fMinDist = pLWSFog->fMinDist; m_pFog->fMaxDist = pLWSFog->fMaxDist; m_pFog->fMinAmount = pLWSFog->fMinAmount; m_pFog->fMaxAmount = pLWSFog->fMaxAmount; m_pFog->color.fRed = pLWSFog->afColor[0]; // red m_pFog->color.fGreen = pLWSFog->afColor[1]; // green m_pFog->color.fBlue = pLWSFog->afColor[2]; // blue } // convert lightwave lights into generic lights SetLight( lightwave_scene ); // for occlusion testing CreateTriangleMesh(); // SetUVsForLightmaps(); return 1; }
void nuiGLPainter::ApplyTexture(const nuiRenderState& rState, bool ForceApply) { // if ((rState.mTexturing && !rState.mpTexture) || (!rState.mTexturing && rState.mpTexture)) // { // printf("bleh!\n"); // char* bleh = NULL; // bleh[0] = 0; // } // 2D Textures: std::map<nuiTexture*, TextureInfo>::const_iterator it = mTextures.find(rState.mpTexture); bool uptodate = (it == mTextures.end()) ? false : ( !it->second.mReload && it->second.mTexture >= 0 ); if (ForceApply || (mState.mpTexture != rState.mpTexture) || (mState.mpTexture && !uptodate)) { GLenum intarget = 0; GLenum outtarget = 0; if (mState.mpTexture) { outtarget = GetTextureTarget(mState.mpTexture->IsPowerOfTwo()); //mState.mpTexture->UnapplyGL(this); #TODO Un apply the texture nuiCheckForGLErrors(); mState.mpTexture->Release(); nuiCheckForGLErrors(); } //NGL_OUT(_T("Change texture to 0x%x (%ls)\n"), rState.mpTexture, rState.mpTexture?rState.mpTexture->GetSource().GetChars() : nglString::Empty.GetChars()); mState.mpTexture = rState.mpTexture ; if (mState.mpTexture) { intarget = GetTextureTarget(mState.mpTexture->IsPowerOfTwo()); mState.mpTexture->Acquire(); nuiSurface* pSurface = mState.mpTexture->GetSurface(); if (pSurface) { std::map<nuiSurface*, FramebufferInfo>::const_iterator it = mFramebuffers.find(pSurface); bool create = (it == mFramebuffers.end()) ? true : false; if (create || pSurface->IsDirty()) { PushClipping(); nuiRenderState s(mState);// PushState(); PushProjectionMatrix(); PushMatrix(); #ifdef _OPENGL_ES_ if (mpSurfaceStack.empty()) { // mDefaultFramebuffer = 0; // mDefaultRenderbuffer = 0; glGetIntegerv(GL_FRAMEBUFFER_BINDING_NUI, &mDefaultFramebuffer); glGetIntegerv(GL_RENDERBUFFER_BINDING_NUI, (GLint *) &mDefaultRenderbuffer); } #endif PushSurface(); SetState(nuiRenderState()); ResetClipRect(); mClip.Set(0, 0, pSurface->GetWidth(), pSurface->GetHeight()); LoadMatrix(nglMatrixf()); NGL_ASSERT(pSurface); SetSurface(pSurface); //Set2DProjectionMatrix(nuiRect(0.0f, 0.0f, pSurface->GetWidth(), pSurface->GetHeight())); nuiMatrix m; m.Translate(-1.0f, 1.0f, 0.0f); m.Scale(2.0f / pSurface->GetWidth(), -2.0f / pSurface->GetHeight(), 1.0f); LoadProjectionMatrix(nuiRect(pSurface->GetWidth(), pSurface->GetHeight()), m); // clear the surface with transparent black: // nuiRenderState s2(mState);// PushState(); // mState.mClearColor = nuiColor(0.0f, 0.0f, 0.0f, 0.0f); SetState(mState); // ClearColor(); // SetState(s2); ////////////////////////////// nuiDrawContext Ctx(nuiRect(pSurface->GetWidth(), pSurface->GetHeight())); Ctx.SetPainter(this); pSurface->Realize(&Ctx); Ctx.SetPainter(NULL); ////////////////////////////// PopSurface(); PopMatrix(); PopProjectionMatrix(); //PopState(); SetState(s); PopClipping(); } } UploadTexture(mState.mpTexture); nuiCheckForGLErrors(); } //NGL_OUT(_T("Change texture type from 0x%x to 0x%x\n"), outtarget, intarget); mTextureTarget = intarget; if (intarget != outtarget) { // Texture Target has changed if (outtarget) { glDisable(outtarget); nuiCheckForGLErrors(); } //NGL_OUT(_T("disable outtarget\n")); if (intarget && mState.mTexturing && mState.mpTexture) { mState.mTexturing = rState.mTexturing; //NGL_OUT(_T("enable intarget\n")); glEnable(intarget); nuiCheckForGLErrors(); } } else { // Texture Target have not changed if (mState.mTexturing != rState.mTexturing) // Have texture on/off changed? { // Should enable or disable texturing mState.mTexturing = rState.mTexturing; if (mState.mTexturing) { glEnable(mTextureTarget); nuiCheckForGLErrors(); } else { glDisable(mTextureTarget); nuiCheckForGLErrors(); } } } } if (ForceApply || (mState.mTexturing != rState.mTexturing)) { // Texture have not changed, but texturing may have been enabled / disabled mState.mTexturing = rState.mTexturing; if (mState.mpTexture) { if (mTextureTarget && mState.mTexturing) { //NGL_OUT(_T("Enable 0x%x\n"), mTextureTarget); glEnable(mTextureTarget); nuiCheckForGLErrors(); } else { //NGL_OUT(_T("Disable 0x%x\n"), mTextureTarget); glDisable(mTextureTarget); nuiCheckForGLErrors(); } } else { if (mTextureTarget) { //NGL_OUT(_T("Disable 0x%x\n"), mTextureTarget); glDisable(mTextureTarget); } nuiCheckForGLErrors(); } } }