Original Post
I am having major problems with my stencil shadows. They turn out white!!! Here is an image:
Here is the code I am using to render the scene and calculating the shadow: The RenderLevel(..) and RenderPlayer(..) functions just render the world geometry and the player model, nothing special is done there. Though, I have noticed that whenever I change the Clear Color to something, the shadow changes color as well. And if I set it to black, I don't see the shadow at all (i.e. as with blending.. black is turned completely transparent). So, something is definately wrong. If you need to look at other pieces of the code, let me know. [Edited by - azjerei on January 15, 2005 3:45:18 AM]
Here is the code I am using to render the scene and calculating the shadow:
//---------------------------------------------------------------
//
// void RenderSceneWithShadows()
//
// Render the world geometry, with stencil shadows.
//
//---------------------------------------------------------------
void RenderSceneWithShadows(int lightingFlicker)
{
// Disable writing to the depth and color buffers, we only
// want to write to the stencil buffer.
glColorMask(GL_FALSE, GL_FALSE, GL_FALSE, GL_FALSE);
glDepthMask(GL_FALSE);
// Enable stencil buffer.
glEnable(GL_STENCIL_TEST);
// Set the stencil buffer to 1.
glStencilFunc(GL_ALWAYS, 1, 0xFFFFFFFF);
glStencilOp(GL_REPLACE, GL_REPLACE, GL_REPLACE);
// Render the level geometry.
RenderLevel(0, false);
// Turn on color and depth buffers.
glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE);
glDepthMask(GL_TRUE);
// Only write to the stencil buffer (value is 1) and keep the buffer content.
glStencilFunc(GL_EQUAL, 1, 0xFFFFFFFF);
glStencilOp(GL_KEEP, GL_KEEP, GL_KEEP);
// Render level geometry in the second pass.
RenderLevel(lightingFlicker, true);
// Push on a new matrix.
glPushMatrix();
glColor4f(0.0f, 0.0f, 0.0f, 0.5f);
// Disable texturing, lighting and depth test, and enable blending.
glDisable(GL_TEXTURE_2D);
glDisable(GL_LIGHTING);
glDisable(GL_DEPTH_TEST);
glEnable(GL_BLEND);
glStencilOp(GL_KEEP, GL_KEEP, GL_INCR);
float groundplane[4] = {0.0, 1.0f, 0.0, 1.0f};
// Calculate the projected shadow.
shadowmatrix(floorShadow, groundplane, SunPosition);
glMultMatrixf((float *) floorShadow);
// Render player.
RenderPlayer(0, false);
// Re-enable texturing, lighting and depth test, and disable blending.
glEnable(GL_TEXTURE_2D);
glEnable(GL_LIGHTING);
glEnable(GL_DEPTH_TEST);
glDisable(GL_BLEND);
// Pop the matrix.
glPopMatrix();
// Create a new matrix.
glPushMatrix();
// Disable the stencil buffer.
glDisable(GL_STENCIL_TEST);
// Render player model.
RenderPlayer(lightingFlicker, true);
// Pop the matrix (never liked those movies anyways :P).
glPopMatrix();
}