Stencil when rendering to FBO

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?

Maybe I should mention that the image renders normally. Just, non of it is hidden like it should be.

Did you make sure to attach the depth-stencil like this:


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

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.

Enabling stenciling after binding fixed it. Thank you.