Original Post
Hi, I'm trying to implement reflections with the Stencil Buffer. It all seems to work OK: the objects get reflected in the floor but I can see the objects on the other side of the floor. Here's the code for enabling the Stencil Buffer and doing the reflection:
glColorMask(0,0,0,0);
glEnable(GL_STENCIL_TEST);
glStencilFunc(GL_ALWAYS, 1, 1);
glStencilOp(GL_KEEP, GL_KEEP, GL_REPLACE);
glDisable(GL_DEPTH_TEST);
renderBSP(0);
glEnable(GL_DEPTH_TEST);
glColorMask(1,1,1,1);
glStencilFunc(GL_EQUAL, 1, 1);
glStencilOp(GL_KEEP, GL_KEEP, GL_KEEP);
glPushMatrix();
{
glScalef(1.0f, 1.0f, -1.0f);
glCullFace(GL_FRONT);
renderEntities(1);
glCullFace(GL_BACK);
}
glPopMatrix();
glDisable(GL_STENCIL_TEST);
renderBSP(1);
renderEntities(0);
glFlush();
SDL_GL_SwapBuffers();
Here is the (very minimal) code renderBSP(int)
if (bsp.faces.vNormal.x == 0 && bsp.faces.vNormal.y == 0 && bsp.faces.vNormal.z == 1)
{
if (blend == 1)
{
glEnable(GL_BLEND);
glColor4f(1.0f, 1.0f, 1.0f, 0.8f);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
}
}
glDrawElements(wireframe == 1 ? GL_TRIANGLES : GL_LINES, bsp.faces.numMeshVerts, GL_UNSIGNED_INT, &bsp.type1Faces[0]);
if (bsp.faces.vNormal.x == 0 && bsp.faces.vNormal.y == 0 && bsp.faces.vNormal.z == 1)
{
if (blend == 1)
{
glDisable(GL_BLEND);
}
}
The code in renderEntities(int) just draws the objects and translates the object so that it reflects in the floor correctly, as the floor isn't at 0. Basically, does any know how I can prevent the reflect object from appearing below the floor? Thanks Richard