3

I have problems utilizing the stencil buffer, and it's seems to boil down to not work at all. Given the following code:

  glEnable(GL_STENCIL_TEST);
  glClearStencil(0);
  glClear(GL_STENCIL_BUFFER_BIT | GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
  glColor4f(1, 1, 1, 1);
  glStencilFuncSeparate(GL_FRONT_AND_BACK, GL_NEVER, 0, 0);
  glStencilOpSeparate(GL_FRONT_AND_BACK, GL_INCR, GL_INCR, GL_INCR);
  glBegin(GL_TRIANGLES);
  { draw something }
  glEnd();

The triangles are still drawn!? Am I missing something trivial here?

Note: I'm not rendering to a frame buffer, I'm using glStencil...Separate just to make sure it's not related to front\back, I've kept bits of code that to me doesn't seem related.

Viktor Sehr
  • 12,825
  • 5
  • 58
  • 90

1 Answers1

3

You don't have a stencil buffer. And by the specification (from 4.3 core, folio page 432):

If there is no stencil buffer, no stencil modification can occur, and it is as if the stencil tests always pass, regardless of any calls to StencilFunc.

Nicol Bolas
  • 449,505
  • 63
  • 781
  • 982
  • You mean I have to render to a frame buffer object with a stencil buffer attached? – Viktor Sehr Nov 20 '12 at 19:19
  • @ViktorSehr: No; you have to ensure that whatever framebuffer you use has a stencil buffer. If you're rendering to an FBO, then that means you need to use a packed depth/stencil buffer. If you're rendering to the default framebuffer, then you need to use a pixel format that provides a stencil buffer. That's platform-specific, so unless you mention how you're creating your context, I can't really help. Also note that "framebuffer" is *one word*, not two. – Nicol Bolas Nov 20 '12 at 19:40
  • Seems I didn't provide a stencil buffer to the default-\screen frame(no space)buffer. Thanks! – Viktor Sehr Nov 21 '12 at 15:20