bool CG8bitSparseImage::Create (int cxWidth, int cyHeight, BYTE InitialValue) // Create // // Create an images of the given size and initial value { // Compute the number of tiles that we need for this image m_xTileCount = AlignUp(cxWidth, m_cxTile) / m_cxTile; m_yTileCount = AlignUp(cyHeight, m_cyTile) / m_cyTile; // Set the initial value m_Tiles.SetByte(InitialValue); // Done m_cxWidth = cxWidth; m_cyHeight = cyHeight; ResetClipRect(); return true; }
void DrawBackgnd() { int i; // playfield counter PLAYFIELD *pPlay; // playfield pointer int prevX, prevY; // save interger part of position Common::Point ptWin; // window top left if (pCurBgnd == NULL) return; // no current background // scroll each background playfield for (i = 0; i < pCurBgnd->numPlayfields; i++) { // get pointer to correct playfield pPlay = pCurBgnd->fieldArray + i; // save integer part of position prevX = fracToInt(pPlay->fieldX); prevY = fracToInt(pPlay->fieldY); // update scrolling pPlay->fieldX += pPlay->fieldXvel; pPlay->fieldY += pPlay->fieldYvel; // convert fixed point window pos to a int ptWin.x = fracToInt(pPlay->fieldX); ptWin.y = fracToInt(pPlay->fieldY); // set the moved flag if the playfield has moved if (prevX != ptWin.x || prevY != ptWin.y) pPlay->bMoved = true; // sort the display list for this background - just in case somebody has changed object Z positions SortObjectList((OBJECT *)&pPlay->pDispList); // generate clipping rects for all objects that have moved etc. FindMovingObjects((OBJECT *)&pPlay->pDispList, &ptWin, &pPlay->rcClip, false, pPlay->bMoved); // clear playfield moved flag pPlay->bMoved = false; } // merge the clipping rectangles MergeClipRect(); // redraw all playfields within the clipping rectangles const RectList &clipRects = GetClipRects(); for (RectList::const_iterator r = clipRects.begin(); r != clipRects.end(); ++r) { // clear the clip rectangle on the virtual screen // for each background playfield for (i = 0; i < pCurBgnd->numPlayfields; i++) { Common::Rect rcPlayClip; // clip rect for this playfield // get pointer to correct playfield pPlay = pCurBgnd->fieldArray + i; // convert fixed point window pos to a int ptWin.x = fracToInt(pPlay->fieldX); ptWin.y = fracToInt(pPlay->fieldY); if (IntersectRectangle(rcPlayClip, pPlay->rcClip, *r)) // redraw all objects within this clipping rect UpdateClipRect((OBJECT *)&pPlay->pDispList, &ptWin, &rcPlayClip); } } // transfer any new palettes to the video DAC PalettesToVideoDAC(); // update the screen within the clipping rectangles for (RectList::const_iterator r = clipRects.begin(); r != clipRects.end(); ++r) { UpdateScreenRect(*r); } g_system->updateScreen(); // delete all the clipping rectangles ResetClipRect(); }
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(); } } }