Hi !
For a project, I need to render some part of my scene in 2 opengl frame buffer, and to merge them by depth buffer comparison.
So I tried to split this problem in 2 tasks:
- First:
a. Render a part of the scene into a framebuffer
b. Switch this framebuffer with the backbuffer
c. Switch the back buffer with the framefuffer - Second:
a. Merge the 2 framebuffer
I implemented the first part:
************FBO SETUP PART ********
// Create 2 render buffer
int[] MyRenderBuffer = new int[2];
glGenRenderbuffersEXT(2, MyRenderBuffer);
// Bind the first render buffer
glBindRenderbufferEXT(GL_RENDERBUFFER_EXT, MyRenderBuffer[0]);
// Allocate memory for its: colorimetry buffer
glRenderbufferStorageEXT(GL_RENDERBUFFER_EXT,GL_RGBA, CV.width, CV.height);
// Bind the first render buffer
glBindRenderbufferEXT(GL_RENDERBUFFER_EXT, MyRenderBuffer[1]);
// Allocate memory for its: depth buffer
glRenderbufferStorageEXT(GL_RENDERBUFFER_EXT, GL_DEPTH_COMPONENT, CV.width, CV.height);
// Create a Frame Buffer Object & bind it
int[] MyFBO = new int[1];
glGenFramebuffersEXT(1, MyFBO);
glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, MyFBO[0]);
// Attach the fist render buffer with the FBO “COLOR_ATTACHMENT0”
glFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT,GL_RENDERBUFFER_EXT, MyRenderBuffer[0]);
// Attach the fist render buffer with the FBO “DEPTH _ATTACHMENT0”
glFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT,GL_DEPTH_ATTACHMENT_EXT,GL_RENDERBUFFER_EXT, MyRenderBuffer[1]);
// Bind the OpenGL Standard framebuffer
glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0);
// Check FBO Status
int status_fbo =glCheckFramebufferStatusEXT(GL_FRAMEBUFFER_EXT);
int normal_status =GL_FRAMEBUFFER_COMPLETE_EXT;
************DRAW ********
// Bind the FBO
glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, fbo);
// Draw my scene
Draw();
// Re bind the OpenGL Standard framebuffer
glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0);
// Then SDL swaps buffers…
Results:
• My status_fbo is equal to “GL_FRAMEBUFFER_COMPLETE_EXT” ! (good)
• If I disable the line “glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, fbo);” in the “Draw part”, my scene is correctly shown on the screen. (good)
• If I enable line “glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, fbo);” in the “Draw part”, nothing is shown (no good)
Question:
Please, is anyone could help me to identify the mistake? I think I don’t really switch the back buffer with my FBO, but I don’t know why…