Hello,
I have a black and white texture and want to set the value in the stencil buffer corresponding to the white pixels. So far I have tried using blending to make the black portion of a textured quad face transparent before rendering, but this appears to set all the stencil values to 1, not just the non-transparent white ones. I thought I could use glColorMask to only render white pixels, but this function doesn’t work as I expected - is there a function that would cull the black pixels upon rendering?
The code I have is as follows:
glBindTexture( GL_TEXTURE_2D, stencil_tex );
glBlendFunc( GL_ONE, GL_ONE );
glStencilFunc( GL_ALWAYS, 1, 1 );
glStencilOp( GL_REPLACE, GL_REPLACE, GL_REPLACE );
glBegin( GL_QUADS );
{
glTexCoord2f( 0.0f, 0.0f ); glVertex3f( -1.7f, -1.7f, 1.7f );
glTexCoord2f( 1.0f, 0.0f ); glVertex3f( 1.7, -1.7f, 1.7f );
glTexCoord2f( 1.0f, 1.0f ); glVertex3f( 1.7f, 1.7f, 1.7f );
glTexCoord2f( 0.0f, 1.0f ); glVertex3f( -1.7f, 1.7f, 1.7f );
}
glEnd();
The effect I am trying to achieve is rendering a black and white texture onto the face of a quad, then for everything else that is rendered on top of the textured quad I want only the bits directly over the non-white part of the texture to render. My thinking is if I can put the white portion of the texture into the stencil buffer then use that to cull pixels over the white values of the texture.
Thanks for your time,
-Ross