View Full Version : failed to use Stencil

02-02-2011, 07:58 AM

I'm trying to port a DirectX10 piece of code but I failed to use stencil correctly.

Here is my test :
I have a FBO with a depth stencil render buffer attached and stencil test enabled. I clear it to '1' value.
Then I attach color buffers to the FBO and try to draw a simple fullscreen quad just for test, with stencil test func set to GL_GREATER and ref value to '1'. So I expect to have nothing drawn....but all pixels are drawn on the screen...

Could you please help me finding where I'm wrong ?

the code lokks like this :


(...) //create the renderBufferObject, attach to the FBO

glStencilMaskSeparate(GL_FRONT_AND_BACK, 0xffffffff);
glClear(GL_STENCIL_BUFFER_BIT | GL_COLOR_BUFFER_BIT); //want to keep depth

glStencilFuncSeparate(GL_FRONT, GL_GREATER, 1, 0xffffffff);
glStencilMaskSeparate(GL_FRONT, 0);
glStencilOpSeparate(GL_FRONT, GL_KEEP, GL_KEPP, GL_KEEP);

(...) //draw

Alfonse Reinheart
02-02-2011, 10:42 AM
You only set the values for GL_FRONT facing polygons. Are you sure you're drawing the front of your triangles? OpenGL defaults to no face culling, so if you're drawing the back, you'd never notice.

02-03-2011, 02:40 AM
Ok, I've found the problem.

You're right there was a very hidden little bug in the engine I'm using that caused wrong culling & CW on my quad as a side effect. So the stencil seperate affected was effectively the GL_BACK instead of the GL_FRONT.

I have to fix all that stuff now ;)