Frame Buffer Object

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:

  1. 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
  2. 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…

I am not quite sure what you are trying to achieve with your draw part.
You are most likely drawing to the FBO, but it will not appear on the screen by itself.

Are you setting up the viewport for that FBO?

Also, although I have not used FBOs much… Normally I render to the FBO, after setting up the viewport, and then to draw anything from the FBO you need to disable the FBO, enable it’s texture and draw that to some geometry (like a QUAD) on the main screen…