openGL, masking, alphas, & FOG
This is a gerneral question about how to handle transparentcy in OpenGL scenes where fog is enabled.
Let's say I'm trying to create trees or some other complex object by first drawing a mask texture and then the image texture. With the mask texture, everything but the mask is completely transparent, so if I'm applying this texture to a quad, the quad's shape is completely invisible.
Ditto for the image, where everything but the image is invisible, so you don't see the polygon it's applied to.
This technique works fine with no fog -- the polygon is completely invisible and the effect looks good. But with fog enabled, the fog makes the polygon visible and the effect sucks. Does anyone know a technique for getting around this problem? I can turn off fog while I draw the image, but then that image isn't affected by the fog and so it looks stupid. What do the pros do?
Would greatly appreciate suggestions or links to tutorials that deal with this issue.:D
(Example of sliding texture on transparent quad...I'm just experimenting with the technique here, don't worry about what it's supposed to be...)
Code:
glEnable( GL_BLEND );
glDisable( GL_LIGHTING );
// glDisable( GL_FOG );
glDepthMask ( GL_FALSE );
glMatrixMode( GL_TEXTURE );
glPushMatrix();
glTranslatef(0.0f, scroll, 0.0f);
glMatrixMode( GL_MODELVIEW );
glPushMatrix();
glBindTexture( GL_TEXTURE_2D, texture[4] ); //apply mask
glShadeModel( GL_FLAT );
glBlendFunc( GL_DST_COLOR, GL_ZERO );
glBegin( GL_QUADS );
glTexCoord2f(0.0f, 0.0f); glVertex3f(0.0f, 0.0f, 5.0f);
glTexCoord2f(0.0f, 1.0f); glVertex3f(0.0f, 10.0f, 5.0f);
glTexCoord2f(1.0f, 1.0f); glVertex3f(10.0f, 10.0f, 5.0f);
glTexCoord2f(1.0f, 0.0f); glVertex3f(10.0f, 0.0f, 5.0f);
glEnd();
// glEnable( GL_FOG );
glBindTexture ( GL_TEXTURE_2D, texture[2] ); //apply image
glBlendFunc( GL_ONE, GL_ONE );
glBegin( GL_QUADS );
glTexCoord2f(0.0f, 0.0f); glVertex3f(0.0f, 0.0f, 5.0f);
glTexCoord2f(0.0f, 1.0f); glVertex3f(0.0f, 10.0f, 5.0f);
glTexCoord2f(1.0f, 1.0f); glVertex3f(10.0f, 10.0f, 5.0f);
glTexCoord2f(1.0f, 0.0f); glVertex3f(10.0f, 0.0f, 5.0f);
glEnd();
glShadeModel( GL_SMOOTH );
glPopMatrix();
glMatrixMode( GL_TEXTURE );
glPopMatrix();
glMatrixMode( GL_MODELVIEW);
glDisable(GL_BLEND);
glDepthMask( GL_TRUE );
glEnable( GL_LIGHTING );