Just trying to use the stencil buffer for the first and and my first test worked straight away. To write to the stencil I used
// Clear the stencil to 0
glEnable(GL_STENCIL_TEST);
glClearStencil(0);
glClear(GL_STENCIL_BUFFER_BIT);
// INCRease stencil to non-zero when draw
glStencilOp(GL_INCR, GL_INCR, GL_INCR);
// NEVER pass so nothing appears on screen
glStencilFunc(GL_NEVER, 0x0, 0x0);
// Single glDrawArrays call to draw the stencil shape I want.
glDisable(GL_STENCIL_TEST);
glStencilOp(GL_KEEP, GL_KEEP, GL_KEEP);
Then to render my image
glEnable(GL_STENCIL_TEST);
// Only show parts which where stencil is ZERO
glStencilFunc(GL_EQUAL, 0, 0xffffffff);
glStencilOp(GL_KEEP, GL_KEEP, GL_KEEP);
and I got no image for the parts where I drew to the stencil.
However, I then changed the GL_EQUAL to GL_NOTEQUAL and my entire image was visible. I thought it would invert the result i.e. I’d only see the image for where I drew to the stencil.
I’m obviously not unstanding something fundemental about the stencil test.