//Draw the geometry only in the stencil buffer
//to avoid writing some unwanted value in the depth buffer.
glEnable(GL_STENCIL_TEST);
glDisable(GL_DEPTH_TEST);
glColorMask(GL_FALSE,GL_FALSE,GL_FALSE,GL_FALSE);
glStencilFunc(GL_ALWAYS, 0x1, 0x1);
glStencilOp(GL_KEEP, GL_KEEP, GL_INVERT);
//Draw concave geometry
//Draw the geometry only where the mask is 1 with depth test //enable
glEnable(GL_DEPTH_TEST);
glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE);
glStencilFunc(GL_EQUAL, 0x1, 0x1);
//Reset the stencil mask to 0 where it was 1. Useful if we want //to draw many concave geometry
glStencilOp(GL_KEEP,GL_INVERT,GL_INVERT);
//Draw concave geometry again
glDisable(GL_STENCIL_TEST);