Hi,
got a question with the stencil buffer. The following code
doesn’t work. I want to draw some shapes into the stencil buffer.
Then I clear the color buffer and draw some other shapes into
the color buffer. At last I want to draw a rectangle over the whole
screen, but only where the stencil buffer is filled.
Thats my source:
// Now draw the shapes for stencil mask:
glEnable(GL_STENCIL_TEST);
glClearStencil(0);
glClear(GL_STENCIL_BUFFER_BIT);
glStencilFunc(GL_ALWAYS, 1, 1);
glStencilOp(GL_REPLACE, GL_REPLACE, GL_REPLACE);
DrawStencilShapes();
// Now draw some shapes which are not stenciled:
glDisable(GL_STENCIL_TEST);
glClear(GL_COLOR_BUFFER_BIT);
DrawShapes();
// Now draw a gray polygon over the whole screen, but only
// where the stencil was written with 1 before:
glEnable(GL_STENCIL_TEST);
glStencilFunc(GL_EQUAL, 1, 1);
glStencilOp(GL_KEEP, GL_KEEP, GL_KEEP);
glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
glShadeModel(GL_SMOOTH);
glDisable(GL_LIGHTING);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho (-50, 50, -50, 50, -150, 150);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glViewport(0,0,drawSizeX,drawSizeY);
glTranslatef(0,0,-80);
glDisable(GL_DEPTH_TEST);
glDisable(GL_CULL_FACE);
glBegin(GL_POLYGON);
glColor3f(0.7f, 0.7f, 0.7f);
glVertex2f(-50, 50);
glVertex2f( 50, 50);
glVertex2f( 50,-50);
glVertex2f(-50,-50);
glEnd();
glEnable(GL_CULL_FACE);
glEnable(GL_DEPTH_TEST);
glDisable(GL_STENCIL_TEST);
Any suggestions?
Thanks!