2

Is there a way to render to both, a renderbuffer and to the display without have to call multiple times the draw function? I wanted someting like this:

glBindFramebuffer(GL_FRAMEBUFFER, fbo);
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE2D, tbo, 0);
glClear(GL_DEPTH_BUFFER_BIT | GL_COLOR_BUFFER_BIT);
GLenum* attachments[2] = {GL_COLOR_ATTACHMENT0, ...} //with the second I want to render to screen which would have the same value like the first
glDrawBuffer(2, attachments);

glDrawElements(GL_TRIANGLES, 12*3, GL_UNSIGNED_INT, 0);

So I can use what I drawed in the same time as a texture for another rendercall. I could just write

glBindFramebuffer(GL_FRAMEBUFFER, 0);
glDrawElements(GL_TRIANGLES, 12*3, GL_UNSIGNED_INT, 0);

but this would require to draw the scene again, which would be slow. Another solution would be just to draw the framebuffer, but I thought there would be a smarter solution.

1
  • Short answer: No. But, use glBlitFramebuffer to copy from one framebuffer to another. Of course the data have to be copied, but there is no need to render the scene again. Commented Oct 15, 2019 at 9:17

1 Answer 1

3

You can copy a frame buffer to another one using glBlitFramebuffer().

Something like:

glBindFramebuffer(GL_READ_FRAMEBUFFER, fbo);
glBindFramebuffer(GL_DRAW_FRAMEBUFFER, 0);
glBlitFramebuffer(
    0, 0, fboWidth, fboHeight,
    0, 0, screenWidth, screenHeight,
    GL_COLOR_BUFFER_BIT, GL_NEAREST);

should do the trick.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.