Hi, I am learning to use the stencil buffer, but no matter what tutorial I follow I always have the problem of the stencil buffer not masking. So things that I draw that are not supposed to go outside the mask, do.
My Display Code is as:
glClearStencil(0);
glClearDepth(1.0f);
glClearColor (0.0,0.0,0.0,0.5);
glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
glLoadIdentity();
glTranslatef(0,0,-5);
glColorMask(GL_FALSE, GL_FALSE, GL_FALSE, GL_FALSE);
glDepthMask(GL_FALSE);
glEnable(GL_STENCIL_TEST);
glStencilFunc(GL_ALWAYS, 1, 0xFFFFFFFF);
glStencilOp(GL_REPLACE, GL_REPLACE, GL_REPLACE);
glBegin(GL_QUADS);
glVertex3f(-1, 0, -7);
glVertex3f(1, 0, -7);
glVertex3f(1, -2, 0);
glVertex3f(-1, -2, 0);
glEnd();
glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE);
glDepthMask(GL_TRUE);
glStencilFunc(GL_EQUAL, 1, 0xFFFFFFFF);
glStencilOp(GL_KEEP, GL_KEEP, GL_KEEP);
glPushMatrix();
glScalef(1.0f, -1.0f, 1.0f);
glTranslatef(0,2,-1);
glRotatef(rot,0,1,0);
square();
glPopMatrix();
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glColor4f(1,1,1,0.4);
glBindTexture(GL_TEXTURE_2D,texture[1]);
base();
glDisable(GL_BLEND);
glDisable(GL_STENCIL_TEST);
glPushMatrix();
glTranslatef(0,1,-1);
glRotatef(rot,0,1,0);
square();
glPopMatrix();
glutSwapBuffers();
rot++;
Any yet it draws my square(the one drawn in the stencil buffer) outside the supposed mask which is the same dimensions as base() if that means anything.
Thanks