void nuiDrawContext::SetOrthoProjectionMatrix(const nuiRect& rRect, float Left, float Right, float Bottom, float Top, float Near, float Far) { nuiMatrix m; m.SetOrtho(Left, Right, Bottom, Top, Near, Far); m.Translate(-1.0f, 1.0f, 0.0f); LoadProjectionMatrix(rRect, m); }
void nuiDrawContext::Set2DProjectionMatrix(const nuiRect& rRect) { //printf("Set2DProjectionMatrix: %s\n", rRect.GetValue().GetChars()); nuiMatrix m; m.Translate(-1.0f, 1.0f, 0.0f); m.Scale(2.0f/rRect.GetWidth(), -2.0f/rRect.GetHeight(), 1.0f); LoadProjectionMatrix(rRect, m); }
void nuiDrawContext::SetFrustumProjectionMatrix(const nuiRect& rRect, float Left, float Right, float Bottom, float Top, float Near, float Far) { nuiMatrix m; m.SetFrustum(Left, Right, Bottom, Top, Near, Far); LoadProjectionMatrix(rRect, m); }
void nuiDrawContext::SetPerspectiveProjectionMatrix(const nuiRect& rRect, float FovY, float Aspect, float Near, float Far) { nuiMatrix m; m.SetPerspective(FovY, Aspect, Near, Far); LoadProjectionMatrix(rRect, m); }
void nuiDrawContext::LoadProjectionIdentity() { nuiMatrix m; LoadProjectionMatrix(nuiRect(0.0f, 0.0f, mWidth, mHeight), m); }
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(); } } }