I put a quad as a mask and another quad as the texture onto each other. Almost like the NeHe tutorial teaches about masking. NeHe writes there:
“…we draw this image right on top of the mask. Same texture coordinates, same vertices.”
I tried that in my own program, but after that I got a strange result. I only saw the mask (black/white textured quad). The “foreground” texture wasn’t there. I changed the vertices’ coordinates and put the quad (coloured) nearer the viewer and the “foreground” texture appeared, the masking was made.
I think this error came of the fact that the two quads were overlapping each other. But if I draw the b/w mask first and after that the coloured one, the second should appear and the first should disappear.
My code looks the following:
(in the main loop)
glEnable(GL_BLEND);
glBlendFunc(GL_DST_COLOR, GL_ZERO);
draw_mask(4);//draws the b/w mask
glBlendFunc(GL_ONE,GL_ONE);
draw_mask(5);//draws the image
glDisable(GL_BLEND);
//****************************************************
(the drawing funcion)
void draw_mask(int num){
glEnable(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D, background[num]);
glBegin(GL_QUADS);
glNormal3f(0.0f, 0.0f, 1.0f);
glTexCoord2f(0, 0);
glVertex3f(218.419,-60.65,492.828);
glTexCoord2f(0, 1);
glVertex3f(218.731, -51.77, 494.277);
glTexCoord2f(1, 1);
glVertex3f( 227.529,-51.72, 492.38);
glTexCoord2f(1, 0);
glVertex3f(227.216, -60.65, 490.93);
glEnd();}
After that I see only the b/w mask. How can this be?