is it possible to copy the default framebuffer to another framebuffer object in OpenGL?
I am trying to copy the default framebuffer after rendering on to the screen to another custom framebuffer in OpenGL. Below is my code. Do you see anything wrong? BLit call is successful but I don't see anything rendering.
void drawDisplayList() {
setNormalDraw();
clear();
drawDisplayLists();
drawDisplayLists();
glBindFramebuffer(GL_READ_FRAMEBUFFER, 0);
glReadBuffer(GL_FRONT);
glBindFramebuffer(GL_FRAMEBUFFER, geomFBO);
glBindFramebuffer(GL_DRAW_FRAMEBUFFER, geomFBO);
glDrawBuffer(GL_COLOR_ATTACHMENT0);
glBlitFramebuffer(0, 0, _scrWidth, _scrHeight, 0, 0, _scrWidth, _scrHeight, GL_COLOR_BUFFER_BIT, GL_NEAREST);
GLenum errorCode1;
errorCode1 = glGetError();
if (errorCode1 != GL_NO_ERROR) {
printf("glBlitFramebuffer Success!");
}
glBindFramebuffer(GL_READ_FRAMEBUFFER, 0);
glBindFramebuffer(GL_DRAW_FRAMEBUFFER, 0);
}
My FBO Intialization
void createFboBuffers()
{
glGenFramebuffers(1, &geomFBO);
glBindFramebuffer(GL_FRAMEBUFFER, geomFBO);
glGenRenderbuffers(1, &color_rbo);
glBindRenderbuffer(GL_RENDERBUFFER, color_rbo);
glRenderbufferStorage(GL_RENDERBUFFER, GL_RGB, this->size().width(), this->size().height());
glBindRenderbuffer(GL_RENDERBUFFER, 0);
glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_RENDERBUFFER, color_rbo);
glGenRenderbuffers(1, &depth_rbo);
glBindRenderbuffer(GL_RENDERBUFFER, depth_rbo);
glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH_COMPONENT24, _scrWidth, _scrHeight);
glBindRenderbuffer(GL_RENDERBUFFER, 0);
glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, depth_rbo);
}
Any pointers please. Looks like Nothing is copied to another FrameBuffer.
The instruction glBindFramebuffer(GL_FRAMEBUFFER, geomFBO)
binds the framebuffer object to both the read and draw framebuffer targets (see glBindFramebuffer
). This breaks the binding of the default framebuffer to the read framebuffer target. Just remove:
glBindFramebuffer(GL_READ_FRAMEBUFFER, 0);
glReadBuffer(GL_FRONT);
// glBindFramebuffer(GL_FRAMEBUFFER, geomFBO); <-- DELETE
glBindFramebuffer(GL_DRAW_FRAMEBUFFER, geomFBO);