Hi everyone,
I am trying to create volume shadows and have succeeded in determining and rendering volumes themselves, but have problems with rendering just the right parts with stencil buffers.
So the code is:
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);
ShadowVolume.drawVolume(shadowPlane, lightToDropShadow, [6, 0, 6])
glCullFace(GL_BACK);
glStencilFunc(GL_ALWAYS, 0x0, 0xff);
glStencilOp(GL_KEEP, GL_DECR, GL_KEEP);
ShadowVolume.drawVolume(shadowPlane, lightToDropShadow, [6, 0, 6])
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);
draw_shadow();
glDisable(GL_STENCIL_TEST);
this was the part where I try to capture just the parts of the rendered objects wich are affected by the shadow. draw_shadow is just a function that fills the whole screen with black color:
//draw shadow
glPushMatrix();
glLoadIdentity();
glMatrixMode(GL_PROJECTION);
glPushMatrix();
glLoadIdentity();
glOrtho(0, 1, 1, 0, 0, 1);
glDisable(GL_DEPTH_TEST);
glColor3f(0.0, 0.0, 0.0);
glBegin(GL_QUADS);
glVertex2i(0, 0.5);
glVertex2i(0.5, 1);
glVertex2i(1, 1);
glVertex2i(1, 0);
glEnd();
glEnable(GL_DEPTH_TEST);
glPopMatrix();
glMatrixMode(GL_MODELVIEW);
glPopMatrix();
Well, what happens is - everything is covered with that color of shadow. the whole screen.
Can anyone, please, help me? What do I do wrong? Maybe I’m ommiting something?