trying to implement stencil shadows

Hi, i am trying to implement stencil shadows using the increment/decrement approach… but i am having problems… It doesn’t work .

Here is the code and i realize that it is probably completely wrong but any help would be much appreciated

glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
glEnable(GL_CULL_FACE);
// Render scene normally
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();

// Render scene normally
glEnable(GL_LIGHTING);
TheCam.Update(); // set up glulookat to look at (0,0,0)
DrawScene();

glDisable(GL_LIGHTING);
glDepthMask(GL_FALSE);

// Render scene and increment stencil buffer when depth test passes
glCullFace(GL_BACK);
glColorMask(GL_FALSE,GL_FALSE,GL_FALSE,GL_FALSE);
glStencilOp(GL_KEEP,GL_KEEP,GL_INCR);
glStencilMask(1);
glStencilFunc(GL_ALWAYS,0,1);
glEnable(GL_STENCIL_TEST);

glLoadIdentity();
gluLookAt(lightPosition[0],lightPosition[1],lightPosition[2]+.5,0,0,0,0,1,0);
DrawScene();

// Render scene and decrement stencil buffer when depth test passes
glStencilOp(GL_KEEP,GL_KEEP,GL_DECR);
glCullFace(GL_FRONT);
glStencilFunc(GL_ALWAYS,0,1);

glLoadIdentity();
gluLookAt(lightPosition[0],lightPosition[1],lightPosition[2]+.5,0,0,0,0,1,0);
DrawScene();

// Reder only when stencil == 0
glCullFace(GL_BACK);
glDisable(GL_STENCIL_TEST);
glColorMask(GL_TRUE,GL_TRUE,GL_TRUE,GL_TRUE);
glStencilOp(GL_KEEP,GL_KEEP,GL_KEEP);
glStencilFunc(GL_EQUAL,0,0);

glDepthMask(GL_TRUE);
glLoadIdentity();
DrawScene();

After reading your codes, I get nothing wrong.So I think that maybe the error is not in these codes.Several months ago, when I studied using Stencil Buffer,I made a mistake that I fogot tell opengl to prepare stencil buffer for me.If you had the same mistake,you should check the codes which you use to initialize opengl.Good Luck

you should draw shadow volumes to the stencil buffer, not the scene.

Ok I will try your ideas when i get home [ ]
Thanks for you help.