3
votes

I try to use the stencil buffer of a FBO in OpenGL, but I can't get it to work. I bound a depth24_stencil8 texture to the FBO both for the depth and stencil targets. As a simple test, I tried:

/* Enable FBO */

glEnable(GL_STENCIL_TEST);
glStencilFunc(GL_NEVER, 1, 0xff);
glStencilOp(GL_KEEP, GL_KEEP, GL_KEEP);

glBegin(GL_TRIANGLE);
/* Draw some triangles */
glEnd();

glDisable(GL_STENCIL_TEST);

/* Disable FBO and render it on screen as a texture. */

As I use GL_NEVER, nothing should be rendered at all, but I can see the triangles. This is like if there were no stencil at all, but I cannot understand why. Trying this code without FBOs works, so I think I use the stencil functions correctly. I don't have any idea how to solve this problem. Did anyone already use a stencil with FBOs?

1
Maybe you should show your code of how you are creating your FBO? - zerm
Thanks for having a look to my post, problem is now solved. - neodelphi
Can I ask you what formats you used for your stencil buffer, as I cant get stencil buffer rendering in frame buffer to work properly. - Viktor Sehr

1 Answers

0
votes

My bad, I was not attaching correctly the stencil buffer to my FBO. Strange thing is that my fbo status was not indicating any error or bad attachement, so I was persuaded it was OK... this problem has driven me crazy but now it seems to work.