3

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?

Bart
  • 19,692
  • 7
  • 68
  • 77
neodelphi
  • 2,706
  • 1
  • 15
  • 22

1 Answers1

0

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.

neodelphi
  • 2,706
  • 1
  • 15
  • 22
  • 2
    The FBO status was probably Ok (complete) because you don't need a stencil buffer (and neither a depth buffer) for the FBO to be complete. In this case it will just not perform any stencil (depth) testing. – Christian Rau Dec 05 '11 at 23:36
  • You can flag your own solution/question to resolved, so when someone search for similar problem she can see that this question may contain an solution too. – tbalazs Dec 06 '11 at 07:49
  • I have to wait for two days, can't click for the moment. I'll mark it as solved as soon as possible. – neodelphi Dec 06 '11 at 19:54