void RendererOpenGL::RenderTexturedRect( const RenderElement& _TexturedRect ) #endif { PROFILING( "Render Texture" ); // Get settings #ifdef MULTIPLE_RENDER_ELEMENTS const CFoundation::Vector2Di& vPosition = _spTexturedRect->GetPosition(); const Texture& mask = _spTexturedRect->GetMask(); const Texture& texture = _spTexturedRect->GetTexture(); const CFoundation::RectF16& rectTexture = _spTexturedRect->GetRelativeTextureRect(); const CFoundation::Vector2Du& vSize = _spTexturedRect->GetSize(); bool bBgVisible = _spTexturedRect->IsBgVisible(); const CFoundation::Color& bgColor = _spTexturedRect->GetBgColor(); Float16 f16Angle = _spTexturedRect->GetAngle(); #else const CFoundation::Vector2Di& vPosition = _TexturedRect.GetPosition(); const Texture& mask = _TexturedRect.GetMask(); const Texture& texture = _TexturedRect.GetTexture(); const CFoundation::RectF16& rectTexture = _TexturedRect.GetRelativeTextureRect(); const CFoundation::Vector2Du& vSize = _TexturedRect.GetSize(); bool bBgVisible = _TexturedRect.IsBgVisible(); const CFoundation::Color& bgColor = _TexturedRect.GetBgColor(); Float16 f16Angle = _TexturedRect.GetAngle(); #endif // Compute size Float16 f16HalfWidth = vSize.GetX() * 0.5f; Float16 f16HalfHeight = vSize.GetY() * 0.5f; Unsigned32 u32Width = vSize.GetX(); Unsigned32 u32Height = vSize.GetY(); // Render mask if ( mask.IsValid() ) { // Enable stencil buffer glClear( GL_STENCIL_BUFFER_BIT ); glEnable( GL_STENCIL_TEST ); glStencilOp( GL_KEEP, GL_KEEP, GL_REPLACE ); glStencilFunc( GL_ALWAYS, 1, 1 ); // Enable mask glEnable( GL_TEXTURE_2D ); glBindTexture( GL_TEXTURE_2D, mask.GetID() ); // Draw only non-transparent pixels into the stencil buffer glEnable( GL_ALPHA_TEST ); glAlphaFunc( GL_GREATER, 0.01f ); // Draw nothing on the screen glColorMask( 0, 0, 0, 0 ); // Move to right position glLoadIdentity(); glTranslated( vPosition.GetX(), vPosition.GetY(), 0 ); // Draw mask into stencil buffer glBegin( GL_QUADS ); glTexCoord2f( rectTexture.GetLeft(), rectTexture.GetBottom() ); glVertex3d( 0, 0, 0 ); glTexCoord2f( rectTexture.GetRight(), rectTexture.GetBottom() ); glVertex3d( u32Width, 0, 0 ); glTexCoord2f( rectTexture.GetRight(), rectTexture.GetTop() ); glVertex3d( u32Width, u32Height, 0 ); glTexCoord2f( rectTexture.GetLeft(), rectTexture.GetTop() ); glVertex3d( 0, u32Height, 0 ); glEnd(); // Draw again on the screen glColorMask( 1, 1, 1, 1 ); // Setup stencil test for background/texture glStencilFunc( GL_EQUAL, 1, 1 ); glStencilOp( GL_KEEP, GL_KEEP, GL_KEEP ); } // Render background if ( bBgVisible ) { glLoadIdentity(); glDisable( GL_TEXTURE_2D ); Drawer::GetInstance().DrawSolidRect( CFoundation::RectI32( vPosition, vSize ), bgColor, f16Angle ); } // Render texture glLoadIdentity(); glEnable( GL_TEXTURE_2D ); glBindTexture( GL_TEXTURE_2D, texture.GetID() ); // Set color Float16 f16R, f16G, f16B, f16A; bgColor.ToRGBA( f16R, f16G, f16B, f16A ); glColor4f( f16R, f16G, f16B, f16A ); // Translation //glTranslated( vPosition.GetX(), vPosition.GetY(), 0.0f ); glTranslatef( vPosition.GetX() + f16HalfWidth, vPosition.GetY() + f16HalfHeight, 0.0f ); // Rotate glRotatef( f16Angle, 0.0f, 0.0f, 1.0f ); // Render texture glBegin( GL_QUADS ); glTexCoord2f( rectTexture.GetLeft(), rectTexture.GetBottom() ); glVertex3f( -f16HalfWidth, -f16HalfHeight, 0 ); glTexCoord2f( rectTexture.GetRight(), rectTexture.GetBottom() ); glVertex3f( f16HalfWidth, -f16HalfHeight, 0 ); glTexCoord2f( rectTexture.GetRight(), rectTexture.GetTop() ); glVertex3f( f16HalfWidth, f16HalfHeight, 0 ); glTexCoord2f( rectTexture.GetLeft(), rectTexture.GetTop() ); glVertex3f( -f16HalfWidth, f16HalfHeight, 0 ); glEnd(); if ( mask.IsValid() ) { glClear( GL_STENCIL_BUFFER_BIT ); glDisable( GL_STENCIL_TEST ); } }
void RendererOpenGL::RenderRect( const RenderElement& _Rect ) #endif { glLoadIdentity(); glDisable( GL_TEXTURE_2D ); #ifdef MULTIPLE_RENDER_ELEMENTS Drawer::GetInstance().DrawSolidRect( CFoundation::RectI32( _spRect->GetPosition(), _spRect->GetSize() ), _spRect->GetColor(), _spRect->GetAngle() ); #else Drawer::GetInstance().DrawSolidRect( CFoundation::RectI32( _Rect.GetPosition(), _Rect.GetSize() ), _Rect.GetColor(), _Rect.GetAngle() ); #endif }