I have rendered an objectA in a scene as follows. The scene has many other objects too.
void Draw()
{
if( glIsList( displayListID ) )
{
glPushAttrib( GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT|GL_ENABLE_BIT );
glEnable( GL_BLEND );
glEnable( GL_DEPTH_TEST );
//glDepthMask( GL_FALSE );
glBlendFunc( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA );
glEnable( GL_LINE_SMOOTH );
glEnable( GL_POINT_SMOOTH );
glEnable( GL_POLYGON_SMOOTH );
glMatrixMode( GL_MODELVIEW );
color.setAlpha(alpha); // set alpha transparent of this objectA
glCallList( displayListID );
//glDepthMask( GL_TRUE );
glDisable( GL_BLEND );
glPopAttrib();
}
}
Now here is the problem,
As shown, I comment out two lines //glDepthMask( GL_FALSE ); //glDepthMask( GL_TRUE );
the scene renders the objectA and other objects correctly in depth. However, the modification of the objectA alpha doesn't work anymore (i.e. color.setAlpha(alpha) ).
If I uncomment the above two lines, then alpha modification is back to work. However, the depth rendering is NOT correct. In other words, sometimes, the objectA should be behind other objects but it looks like the objectA is in front of all objects.
How do I fix this problem?
Thank you