PDA

View Full Version : Stencil when rendering to FBO



Darwin
09-12-2011, 04:34 PM
I'm trying to render the scene to a FBO with stencil buffers included. I've attached a depth stencil (d24s8) render buffer to the FBO and when I get the render buffers stencil size I do get 8.
But the stenciling just doesn't work.
It's supposed to clear the stencil buffer to 0x0 and then draw a triangle filled with 0x1. It works when I render normally but refuses to work when I render to the FBO. The FBO check returns that the FBO is complete.

I clear the stencil with
GL.ClearStencil(0x0); GL.Clear(ClearBufferMask.StencilBufferBit);

I don't know what else to try.

Is there some special way to write to the stencil buffer it I'm writing to a FBO?

Darwin
09-12-2011, 04:36 PM
Maybe I should mention that the image renders normally. Just, non of it is hidden like it should be.

Ilian Dinev
09-12-2011, 05:09 PM
Did you make sure to attach the depth-stencil like this:


glFramebufferTexture2D(GL_FRAMEBUFFER, GL_DEPTH_STENCIL_ATTACHMENT, GL_TEXTURE_2D, glTexHandle, 0);


Also btw, some state is FBO-specific, so do the glEnable(GL_STENCIL) and such after you bind the FBO for drawing.

Darwin
09-12-2011, 09:30 PM
Well I'm not using a texture for the stencil buffer. I'm using a render buffer. But I will try enabling stenciling after binding.

Darwin
09-12-2011, 11:26 PM
Enabling stenciling after binding fixed it. Thank you.