I try to use the blending functionalities in order to make a enable/disable effect on my buttons of my GUI.
Here's some code that might be better to explain what's going on.
void CCheckBox::RenderComponent () {
if ( !bEnabled ) {
glEnable ( GL_BLEND );
glBlendFunc ( GL_SRC_ALPHA, GL_ONE );
glDepthMask ( GL_FALSE );
glColor4f ( 0.5f,0.5f,0.5f,1.0f );
}
if ( bChecked ) {
glBindTexture ( GL_TEXTURE_2D, ulChecked );
}
else {
glBindTexture ( GL_TEXTURE_2D, ulUnchecked );
}
glPushMatrix ();
glTranslatef ( lPosX, -lPosY, 0 );
glBegin ( GL_QUADS );
glTexCoord2f ( 0.0f, 0.0f );
glVertex3f ( 0.0f, -lHeight, 0.0f );
glTexCoord2f ( 1.0f, 0.0f );
glVertex3f ( lWidth, -lHeight, 0.0f );
glTexCoord2f ( 1.0f, 1.0f );
glVertex3f ( lWidth, 0.0f, 0.0f );
glTexCoord2f ( 0.0f, 1.0f );
glVertex3f ( 0.0f, 0.0f, 0.0f );
glEnd ();
glPopMatrix();
if ( !bEnabled ) {
glDepthMask ( GL_TRUE );
glDisable ( GL_BLEND );
}
}
Now I have two checkboxes. When both are enabled they look right, but when one is disabled and the other one enabled, they both look the same way, which means they look disable.
When I replace a part of the code by :
void CCheckBox::RenderComponent () {
glEnable ( GL_BLEND );
glBlendFunc ( GL_SRC_ALPHA, GL_ONE );
glDepthMask ( GL_FALSE );
if ( !bEnabled ) {
glColor4f ( 0.5f,0.5f,0.5f,1.0f );
}
else {
glColor4f ( 1.0f,1.0f,1.0f,1.0f );
}
...
glPopMatrix();
glDepthMask ( GL_TRUE );
glDisable ( GL_BLEND );
}
everything is working like it should.
The only thing is that I cannot understand why the first code doesn't work... Someone an idea ? I don't believe that this beahiour is due to the fact that I share the same texture (unsigned int) which is a static member of my CCheckBox class...
Thx in advance