void nuiDrawContext::DrawImageQuad(float x0, float y0, float x1, float y1, float x2, float y2, float x3, float y3, const nuiRect& rSource) { bool texturing = mCurrentState.mTexturing; if (!texturing) EnableTexturing(true); nuiSize tx0,tx1,tx2,tx3; nuiSize ty0,ty1,ty2,ty3; tx0 = rSource.mLeft; ty0 = rSource.mTop; tx1 = rSource.mRight; ty1 = rSource.mTop; tx2 = rSource.mRight; ty2 = rSource.mBottom; tx3 = rSource.mLeft; ty3 = rSource.mBottom; mCurrentState.mpTexture[0]->ImageToTextureCoord(tx0, ty0); mCurrentState.mpTexture[0]->ImageToTextureCoord(tx1, ty1); mCurrentState.mpTexture[0]->ImageToTextureCoord(tx2, ty2); mCurrentState.mpTexture[0]->ImageToTextureCoord(tx3, ty3); nuiRenderArray* pArray = new nuiRenderArray(GL_TRIANGLE_STRIP); pArray->Reserve(4); pArray->EnableArray(nuiRenderArray::eVertex, true); pArray->EnableArray(nuiRenderArray::eTexCoord, true); pArray->EnableArray(nuiRenderArray::eColor, true); // 1 pArray->SetTexCoords(tx0,ty0); pArray->SetVertex(x0, y0); pArray->SetColor(mCurrentState.mFillColor); pArray->PushVertex(); pArray->SetTexCoords(tx3,ty3); pArray->SetVertex(x3, y3); pArray->PushVertex(); pArray->SetTexCoords(tx1,ty1); pArray->SetVertex(x1, y1); pArray->PushVertex(); // 2 pArray->SetTexCoords(tx2,ty2); pArray->SetVertex(x2, y2); pArray->PushVertex(); DrawArray(pArray); if (!texturing) EnableTexturing(texturing); }
void nuiDrawContext::DrawShape(nuiShape* pShape, nuiShapeMode Mode, float Quality) { NGL_ASSERT(pShape != NULL); PushState(); switch (Mode) { case eStrokeShape: { nuiRenderObject* pObject = pShape->Outline(Quality, mCurrentState.mLineWidth, mCurrentState.mLineJoin, mCurrentState.mLineCap); SetFillColor(GetStrokeColor()); SetTexture(mpAATexture); EnableTexturing(true); EnableBlending(true); SetBlendFunc(nuiBlendTransp);//GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); DrawObject(*pObject); delete pObject; } break; case eFillShape: { nuiTessellator* pTess = new nuiTessellator(pShape); pTess->SetFill(true); nuiRenderObject* pObject = pTess->Generate(Quality); DrawObject(*pObject); delete pObject; delete pTess; } break; case eStrokeAndFillShape: { { nuiRenderObject* pObject = pShape->Fill(Quality); DrawObject(*pObject); delete pObject; } { nuiRenderObject* pObject = pShape->Outline(Quality, mCurrentState.mLineWidth, mCurrentState.mLineJoin, mCurrentState.mLineCap); SetFillColor(GetStrokeColor()); SetTexture(mpAATexture); EnableTexturing(true); EnableBlending(true); SetBlendFunc(nuiBlendTransp);//GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); DrawObject(*pObject); delete pObject; } } break; case eDefault: //? break; } PopState(); }
void GL::EnableTexturing(GLenum aTextureTarget, GLenum aTextureId, TexgenComponents aTexgenComponents, const Matrix& aTransform) { GLfloat coefficients[] = { aTransform._11, aTransform._21, aTransform._31, aTransform._12, aTransform._22, aTransform._32 }; EnableTexturing(aTextureTarget, aTextureId, aTexgenComponents, coefficients); }
void ProcessNaviMesh(Render2 *render, Scene::Node *node, System::Object* o) { if (!o) return; AI::NaviMesh *mesh = (AI::NaviMesh*)o; auto m_frame = render->GetCurrentFrame(); if (m_frame->IsEnabledNaviMeshRendering()) { if (mesh) { auto r = Gpu::AsRenderable(*mesh, m_frame->GetVideoDriver()); m_frame->PushAllState(); m_frame->EnableTexturing(false); m_frame->EnableLighting(false); m_frame->EnableBlending(true); m_frame->SetDiffuseColor(0, 0, 1.0, .5); m_frame->Submit(r, true); m_frame->PopAllState(); } } render->ProcessChildren(node); }
void nuiDrawContext::DrawShade(const nuiRect& rSourceRect, const nuiRect& rShadeRect, const nuiColor& rTint) { bool texturing = mCurrentState.mTexturing; bool blending = mCurrentState.mBlending; nuiBlendFunc blendfunc; blendfunc = mCurrentState.mBlendFunc; if (!blending) EnableBlending(true); if (blendfunc != nuiBlendTransp) SetBlendFunc(nuiBlendTransp); nuiSize ShadeSize = rSourceRect.mLeft - rShadeRect.mLeft; nuiTexture* pShade = ::nuiTexture::GetTexture(nglString(_T("NUI_Shade_LUT"))); if (!pShade) { // Left shadow const uint32 size = 16; uint8 pLUT[size * 4]; uint i; for (i = 0; i<size; i++) { pLUT[0+(i*4)] = 0; pLUT[1+(i*4)] = 0; pLUT[2+(i*4)] = 0; float p = (float)i * (255.0f / (float)size); pLUT[3+(i*4)] = ToBelow(p); } nglImageInfo info(false); info.mBitDepth = 32; info.mBufferFormat = eImageFormatRaw; info.mBytesPerLine = size * 4; info.mBytesPerPixel = 4; info.mHeight = 1; info.mWidth = size; info.mpBuffer = (char*)pLUT; info.mPixelFormat = eImagePixelRGBA; pShade = nuiTexture::GetTexture(info, true); pShade->SetSource(_T("NUI_Shade_LUT")); NGL_ASSERT(pShade); pShade->SetMinFilter(GL_LINEAR); pShade->SetMagFilter(GL_LINEAR); #ifndef _OPENGL_ES_ pShade->SetWrapS(GL_CLAMP); pShade->SetWrapT(GL_CLAMP); #else pShade->SetWrapS(GL_CLAMP_TO_EDGE); pShade->SetWrapT(GL_CLAMP_TO_EDGE); #endif pShade->SetEnvMode(GL_MODULATE); } nuiColor transp(rTint); nuiColor opaque(rTint); transp.Multiply(0.0f); opaque.Multiply(SHADE_ALPHA); if (!texturing) EnableTexturing(true); SetTexture(pShade); nuiRenderArray* pArray = new nuiRenderArray(GL_TRIANGLES); pArray->EnableArray(nuiRenderArray::eVertex); pArray->EnableArray(nuiRenderArray::eColor); pArray->EnableArray(nuiRenderArray::eTexCoord); pArray->Reserve(42); // Top Left: pArray->SetColor(transp); pArray->SetTexCoords(0, 0); pArray->SetVertex(rSourceRect.mLeft-ShadeSize,rSourceRect.mTop); pArray->PushVertex(); pArray->SetColor(transp); pArray->SetTexCoords(1, 0); pArray->SetVertex(rSourceRect.mLeft,rSourceRect.mTop); pArray->PushVertex(); pArray->SetColor(opaque); pArray->SetTexCoords(1, 0); pArray->SetVertex(rSourceRect.mLeft,rSourceRect.mTop+ShadeSize); pArray->PushVertex(); /// pArray->SetColor(transp); pArray->SetTexCoords(0, 0); pArray->SetVertex(rSourceRect.mLeft-ShadeSize,rSourceRect.mTop); pArray->PushVertex(); pArray->SetColor(opaque); pArray->SetTexCoords(1, 0); pArray->SetVertex(rSourceRect.mLeft,rSourceRect.mTop+ShadeSize); pArray->PushVertex(); pArray->SetTexCoords(0, 0); pArray->SetColor(opaque); pArray->SetVertex(rSourceRect.mLeft-ShadeSize,rSourceRect.mTop+ShadeSize); pArray->PushVertex(); // Left pArray->SetColor(opaque); pArray->SetTexCoords(0, 0); pArray->SetVertex(rSourceRect.mLeft-ShadeSize,rSourceRect.mTop+ShadeSize); pArray->PushVertex(); pArray->SetColor(opaque); pArray->SetTexCoords(1, 0); pArray->SetVertex(rSourceRect.mLeft,rSourceRect.mTop+ShadeSize); pArray->PushVertex(); pArray->SetColor(opaque); pArray->SetTexCoords(1, 0); pArray->SetVertex(rSourceRect.mLeft,rSourceRect.mBottom); pArray->PushVertex(); /// pArray->SetColor(opaque); pArray->SetTexCoords(0, 0); pArray->SetVertex(rSourceRect.mLeft-ShadeSize,rSourceRect.mTop+ShadeSize); pArray->PushVertex(); pArray->SetColor(opaque); pArray->SetTexCoords(1, 0); pArray->SetVertex(rSourceRect.mLeft,rSourceRect.mBottom); pArray->PushVertex(); pArray->SetColor(opaque); pArray->SetTexCoords(0, 0); pArray->SetVertex(rSourceRect.mLeft-ShadeSize,rSourceRect.mBottom); pArray->PushVertex(); // Left Corner: pArray->SetColor(opaque); pArray->SetTexCoords(0, 0); pArray->SetVertex(rSourceRect.mLeft-ShadeSize,rSourceRect.mBottom); pArray->PushVertex(); pArray->SetColor(opaque); pArray->SetTexCoords(1, 0); pArray->SetVertex(rSourceRect.mLeft,rSourceRect.mBottom); pArray->PushVertex(); pArray->SetColor(transp); pArray->SetTexCoords(1, 0); pArray->SetVertex(rSourceRect.mLeft,rSourceRect.mBottom+ShadeSize); pArray->PushVertex(); /// pArray->SetColor(opaque); pArray->SetTexCoords(0, 0); pArray->SetVertex(rSourceRect.mLeft-ShadeSize,rSourceRect.mBottom); pArray->PushVertex(); pArray->SetColor(transp); pArray->SetTexCoords(1, 0); pArray->SetVertex(rSourceRect.mLeft,rSourceRect.mBottom+ShadeSize); pArray->PushVertex(); pArray->SetColor(transp); pArray->SetTexCoords(0, 0); pArray->SetVertex(rSourceRect.mLeft-ShadeSize,rSourceRect.mBottom+ShadeSize); pArray->PushVertex(); // bottom shadow pArray->SetColor(opaque); pArray->SetTexCoords(1, 0); pArray->SetVertex(rSourceRect.mLeft,rSourceRect.mBottom); pArray->PushVertex(); pArray->SetColor(opaque); pArray->SetTexCoords(1, 0); pArray->SetVertex(rSourceRect.mRight,rSourceRect.mBottom); pArray->PushVertex(); pArray->SetColor(opaque); pArray->SetTexCoords(0, 0); pArray->SetVertex(rSourceRect.mRight,rSourceRect.mBottom+ShadeSize); pArray->PushVertex(); /// pArray->SetColor(opaque); pArray->SetTexCoords(1, 0); pArray->SetVertex(rSourceRect.mLeft,rSourceRect.mBottom); pArray->PushVertex(); pArray->SetColor(opaque); pArray->SetTexCoords(0, 0); pArray->SetVertex(rSourceRect.mRight,rSourceRect.mBottom+ShadeSize); pArray->PushVertex(); pArray->SetColor(opaque); pArray->SetTexCoords(0, 0); pArray->SetVertex(rSourceRect.mLeft,rSourceRect.mBottom+ShadeSize); pArray->PushVertex(); // Right Corner pArray->SetColor(opaque); pArray->SetTexCoords(1, 0); pArray->SetVertex(rSourceRect.mRight,rSourceRect.mBottom); pArray->PushVertex(); pArray->SetColor(opaque); pArray->SetTexCoords(0, 0); pArray->SetVertex(rSourceRect.mRight+ShadeSize,rSourceRect.mBottom); pArray->PushVertex(); pArray->SetColor(transp); pArray->SetTexCoords(0, 0); pArray->SetVertex(rSourceRect.mRight+ShadeSize,rSourceRect.mBottom+ShadeSize); pArray->PushVertex(); /// pArray->SetColor(opaque); pArray->SetTexCoords(1, 0); pArray->SetVertex(rSourceRect.mRight,rSourceRect.mBottom); pArray->PushVertex(); pArray->SetColor(transp); pArray->SetTexCoords(0, 0); pArray->SetVertex(rSourceRect.mRight+ShadeSize,rSourceRect.mBottom+ShadeSize); pArray->PushVertex(); pArray->SetColor(transp); pArray->SetTexCoords(1, 0); pArray->SetVertex(rSourceRect.mRight,rSourceRect.mBottom+ShadeSize); pArray->PushVertex(); // Right pArray->SetColor(opaque); pArray->SetTexCoords(1, 0); pArray->SetVertex(rSourceRect.mRight,rSourceRect.mTop+ShadeSize); pArray->PushVertex(); pArray->SetColor(opaque); pArray->SetTexCoords(0, 0); pArray->SetVertex(rSourceRect.mRight+ShadeSize,rSourceRect.mTop+ShadeSize); pArray->PushVertex(); pArray->SetColor(opaque); pArray->SetTexCoords(0, 0); pArray->SetVertex(rSourceRect.mRight+ShadeSize,rSourceRect.mBottom); pArray->PushVertex(); /// pArray->SetColor(opaque); pArray->SetTexCoords(1, 0); pArray->SetVertex(rSourceRect.mRight,rSourceRect.mTop+ShadeSize); pArray->PushVertex(); pArray->SetColor(opaque); pArray->SetTexCoords(0, 0); pArray->SetVertex(rSourceRect.mRight+ShadeSize,rSourceRect.mBottom); pArray->PushVertex(); pArray->SetColor(opaque); pArray->SetTexCoords(1, 0); pArray->SetVertex(rSourceRect.mRight,rSourceRect.mBottom); pArray->PushVertex(); // Top Right pArray->SetColor(transp); pArray->SetTexCoords(1, 0); pArray->SetVertex(rSourceRect.mRight,rSourceRect.mTop); pArray->PushVertex(); pArray->SetColor(transp); pArray->SetTexCoords(0, 0); pArray->SetVertex(rSourceRect.mRight+ShadeSize,rSourceRect.mTop); pArray->PushVertex(); pArray->SetColor(opaque); pArray->SetTexCoords(0, 0); pArray->SetVertex(rSourceRect.mRight+ShadeSize,rSourceRect.mTop+ShadeSize); pArray->PushVertex(); /// pArray->SetColor(transp); pArray->SetTexCoords(1, 0); pArray->SetVertex(rSourceRect.mRight,rSourceRect.mTop); pArray->PushVertex(); pArray->SetColor(opaque); pArray->SetTexCoords(0, 0); pArray->SetVertex(rSourceRect.mRight+ShadeSize,rSourceRect.mTop+ShadeSize); pArray->PushVertex(); pArray->SetColor(opaque); pArray->SetTexCoords(1, 0); pArray->SetVertex(rSourceRect.mRight,rSourceRect.mTop+ShadeSize); pArray->PushVertex(); DrawArray(pArray); if (!texturing) EnableTexturing(false); if (!blending) EnableBlending(blending); if (blendfunc != nuiBlendTransp) SetBlendFunc(blendfunc); }