PDA

View Full Version : glClear( GL_DEPTH_BUFFER_BIT ) not working



Peeling
05-07-2009, 02:09 PM
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:

glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );

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?

Jan
05-07-2009, 03:05 PM
Maybe a glDepthMask (true) before the glClear call might do the trick.

Jan.

Peeling
05-08-2009, 01:18 AM
That fixed it :)

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

Jan
05-08-2009, 02:42 AM
Same for all the other masks. Especially glColorMask is sometimes used to clear only certain channels and leave others intact.

Jan.