I am experimenting with off-screen rendering. I understand there is two solutions to this:

  1. rendering to texture (you attach a texture to one of the FBO's attachment point which can be a color, depth, etc.)
  2. use a render buffer.

Question 1

I first experimented with using render-buffers. I have a FBO and 2 RBOs, one for color (attached to COLOR0) and one for depth (attached to DEPTH). When I want to visualise the content of what I rendered to the render buffer, I use the glBlitFramebuffer function to copy the content from the FBO to the Window frame buffer (index 0).

glBindFramebuffer(GL_READ_FRAMEBUFFER, fboId);
glBindFramebuffer(GL_DRAW_FRAMEBUFFER, 0);
glBlitFramebuffer(0, 0, width, height, 0, 0, width, height, GL_COLOR_BUFFER_BIT, GL_LINEAR);

First I would like to know if this the best way? (of passing the image from the a render buffer back to the window buffer).

Question 2

My second question. The method I described above works but I can only see the "color" buffer of the FBO, not the depth buffer (I would also like to visualise the depth buffer). So I was wondering how/if this was possible using this approach? I tried to use the index of the depth render buffer in place of the fboIdx in glBindFramebuffer but it didn't change anything. Can I make it work without using render-to-texture approach?

Question 3

My end goal is to render two images using an off-screen approach and blend them together. The result of the mix between the two rendered images is what I want to display to the screen. To keep things fast, I understand this can be done in hardware. What's the best way for doing this? Can it be done using the render-buffer approach or do I need to go the render-to-texture approach (aka render to two textures and then blend these textures using a fragment shader when I do my final pass in which I render a quad stretched over the surface of the screen?


1 Answer 1


Although I'm not an expert (I'm still trying to find my way through the blitting and all its problems) I'll try to help you out (since I can't comment).


Yes blitbuffer is a neat way of copying data back and forth between buffers, and it was specifically introduced to provide such functionality, without the need of messing around with copyPixels and drawPixels functions of the API.


I think the reason why it doesn't work for you is because you haven't included the GL_DEPTH_BUFFER_BIT flag in the clearmask option of the glBlitFramebuffer call. Especially if the draw and read buffers were created with exactly the same size, options and attributes this should work out of the box.


I think the answer to your problems is the glFramebufferTexture2D() function. In addition to your renderbuffers, you can also attach textures to specific attachments of the framebuffer (e.g ColorAttachment0, DepthAttachment) just like you would do in the render-to-texture case. This way, the fbo stores its information on only to the renderbuffers, but also to textures, which you can use whatever way you like afterwards.

Now concerning the mixing, because I'm not sure what exactly you want to do, I would suggest to just prepare the fbo textures (offsreen rendering) then bind the default framebuffer, render a quad and mix the 2 textures whichever way you like in the fragment shader.

If you want to make some serious post processing after the rendering stages i think you should stay with the render to texture approach, because this is what you need eventually. If you just want to copy data from one framebuffer to the other without any serious blending between them, I think blitbuffer should do the job for you.

  • \$\begingroup\$ (at)GregK Thank you. In fact it seems like it's possible to use the blit mechanism to copy the depth off-screen buffer to the depth pass of the default frame buffer,but you can't seem to visualise it!!! (Z -> RGB), unless you go along with using read/write pixels, etc. As for (3) thanks a lot. I get this working and it seems like it's the best way. Plus I read many posts saying the blit approach was actually slower than the quad solution. \$\endgroup\$
    – user18490
    Commented Jan 31, 2017 at 16:36
  • \$\begingroup\$ Oh yeah totally, I didn't notice that you wanted to visualize it. Blitbuffer just copies it directly to the depth buffer of the default fbo. If you want to visualize it you want it as a texture, so yeah, attach your textures to the fbo and do your thing in a shader :) \$\endgroup\$
    – Greg
    Commented Jan 31, 2017 at 22:19

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .