glClear( GL_DEPTH_BUFFER_BIT ) not working

I’m trying to use a frame buffer object in a project I’m working on, and encountered an odd problem.

I’ve cut’n’paste code from an online OGL tutorial to create a straightforward frame buffer object with a colour buffer and a depth buffer attached. Everything works fine - I can render to the FBO, and use the resulting texture elsewhere - apart from one problem: I can’t clear the FBO’s depth buffer. When I call:


only the colour buffer is cleared.

Now, I could understand it if the depth buffer wasn’t working at all, but it is. The geometry clearly is being rendered into the depth buffer; the effect is hard to describe but I’m sure you can imagine it: in each frame only the geometry that pokes in front of everything rendered in previous frames actually appears.

That’s it, really. Clearing the depth buffer on the primary frame buffer works fine; it just doesn’t work on the FBO. I’ve searched around and nobody else seems to be having this problem, and it’s such a basic operation that I can’t really think of anything else to try.

Anyone else experienced this?

Maybe a glDepthMask (true) before the glClear call might do the trick.


That fixed it :slight_smile:

I’m a bit surprised an explicit call like glClear pays any attention to that setting. Anyway, thanks very much!

Same for all the other masks. Especially glColorMask is sometimes used to clear only certain channels and leave others intact.