1
votes

Here's the situation: I have a texture containing some depth values. I want to render some geometry using that texture as the depth buffer, but I want the color to be written to the normal framebuffer (i.e., the window's framebuffer).

How do I do this? I tried creating an FBO and only binding a depth texture to it (GL_DEPTH_COMPONENT) but that didn't work; none of the colors showed up.

1

1 Answers

2
votes

No you can't. The FBO you are rendering to may be either a main framebuffer or an off-screen one. You can't mix them in any way.

Instead, I would suggest you to render to a color renderbuffer and then do a simple blitting operation into the main framebuffer.

Edit-1.

Alternatively, if you already have depth in the main FB, you can first blit your depth and then render to a main FB, thus saving video memory on the additional color renderbuffer.

P.S. Blitting is done via glBlitFramebuffer. In order to make it work you should setup GL_READ_FRAMEBUFFER, GL_DRAW_FRAMEBUFFER and glDrawBuffer() for each of them.