glDepthFunc(GL_LESS);
glDepthMask(0);
glEnable(GL_STENCIL_TEST);
glStencilFunc(GL_ALWAYS,128,0xff);
glStencilOp(GL_KEEP,GL_INCR,GL_KEEP);
glColorMask(0,0,0,0);
// render the front facing polygons and the cap
if(pMesh) pMesh->RenderGL();
// Now the front facing silhouette walls
glFrontFace(GL_CW); // walls have reversed Culling
glDrawElements(GL_QUADS,m_Silhouette.Walls.GetSize(),GL_UNSIGNED_SHORT,&m_Silhouette.Walls[0]);
glFrontFace(GL_CCW);
glDrawElements(GL_TRIANGLES,m_Silhouette.Caps.GetSize(),GL_UNSIGNED_SHORT,&m_Silhouette.Caps[0]);
// now change the stencil op and render the back facing walls
glStencilOp(GL_KEEP,GL_DECR,GL_KEEP);
glDrawElements(GL_QUADS,m_Silhouette.Walls.GetSize(),GL_UNSIGNED_SHORT,&m_Silhouette.Walls[0]);
Note that my Shadow Polygons winding order is CW for front facing and CCW for back facing.
I don’t even get what you’re trying to do with that code
Especially this one is confusing: glStencilFunc(GL_ALWAYS,128,0xff);
Have you read the source of my demo above, I really think it would help, it’s not all that much code. Also check nVidia’s paper on the subject, it’s really helpful too.