I am trying to cap solids that have been sliced by a clipping plane. I thought I knew just what to do, but my results said differently.
The first thing I do is set up a clipping plane with glClipPlane. Next, I prepare the stencil buffer with:
glClear(… | GL_STENCIL_BUFFER_BIT);
glStencilFunc(GL_ALWAYS, 1, 1);
glStencilOp(GL_INCR, GL_INCR, GL_INCR);
Next, I draw my scene normally. My expectations are that OpenGL will update the depth and color buffers, while at the same time incrementing the value in the stencil buffer whenever the color buffer is drawn to.
Next, I set up the stencil buffer so that drawing will only take place where the stencil buffer is 1:
glStencilFunc(GL_EQUAL, 1, 1);
glStencilOp(GL_KEEP, GL_KEEP, GL_KEEP);
Next, I draw a polygon that fills the entire viewport and is drawn on the near plane. I do so with depth testing disabled.
Finally, I disable stencil testing:
Does anyone see the error of my ways?
Thanks for any help,
- Moe -