I’ve been doing a simple demo to implement shadow volumes, but I think I’m doing a mistake related to the stencil buffer part (because i end up with all the screen being shadowed)
Here is the code related to the stencil buffer:
glColorMask(GL_FALSE, GL_FALSE, GL_FALSE, GL_FALSE);
glDepthMask(GL_FALSE);
glEnable(GL_CULL_FACE);
glEnable(GL_STENCIL_TEST);
glEnable(GL_POLYGON_OFFSET_FILL);
glPolygonOffset(0.0f, 100.0f);
glCullFace(GL_FRONT);
glStencilFunc(GL_ALWAYS, 0x0, 0xff);
glStencilOp(GL_KEEP, GL_INCR, GL_KEEP);
RS_Render_Shadow_Volume(obj,obj->poligono[i].a,obj->poligono[i].b,obj->poligono[i].c, obj->pos, luz0.pos);
glCullFace(GL_BACK);
glStencilFunc(GL_ALWAYS, 0x0, 0xff);
glStencilOp(GL_KEEP, GL_DECR, GL_KEEP);
RS_Render_Shadow_Volume(obj,obj->poligono[i].a,obj->poligono[i].b,obj->poligono[i].c, obj->pos, luz0.pos);
glDisable(GL_POLYGON_OFFSET_FILL);
glDisable(GL_CULL_FACE);
glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE);
glDepthMask(GL_TRUE);
glStencilFunc(GL_NOTEQUAL, 0x0, 0xff);
glStencilOp(GL_REPLACE, GL_REPLACE, GL_REPLACE);
RS_Draw_Shadow();
glDisable(GL_STENCIL_TEST);
Here is the screenshoot where you can see that the shadow volumes are right (writing the shadows to the color buffer)