Jump to content
  • Advertisement
Sign in to follow this  

Inconsistent off-screen rendering using FBO

This topic is 3075 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Dear gamedevs,

I got a problem with framebuffer objects with which I was struggling the whole weekend. As I don't want to mess-up this new week with the problem of "the old days", I hope to get some help from you guys... :)

My work lies in the context of image stitching. See here the output of my ON-SCREEN rendering, showing two images being correctly stitched. Note that I'm blending gradually from one image to the other to avoid seams at the image borders. To do so in a clever manner (only blend image with image, never blend image with background), I'm using stencil tests. Now, if I want to render the same 2d-scene OFF-SCREEN by means of the same OpengGL drawing instructions, I'm getting this output, which is not what I want.

Here is the code I'm using.

// Create and bind fbo.
GLuint fbo;
glGenFramebuffersEXT(1, &fbo);
glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, fbo);

// Create and bind/attach color buffer.
GLuint colorBuffer;
glGenRenderbuffersEXT(1, &colorBuffer);
glBindRenderbufferEXT(GL_RENDERBUFFER_EXT, colorBuffer);
glRenderbufferStorageEXT(GL_RENDERBUFFER_EXT, GL_RGBA, fbWidth, fbHeight);

// Create and bind/attach stencil buffer.
GLuint stencilBuffer;
glGenRenderbuffersEXT(1, &stencilBuffer);
glBindRenderbufferEXT(GL_RENDERBUFFER_EXT, stencilBuffer);
glRenderbufferStorageEXT(GL_RENDERBUFFER_EXT, GL_STENCIL_INDEX, fbWidth, fbHeight);

GLenum status = glCheckFramebufferStatusEXT(GL_FRAMEBUFFER_EXT);
// Prepare drawing.
glClearColor(0.0f, 0.0f, 0.0f, 0.0f);

gluOrtho2D(0, fbWidth, fbHeight, 0); // Bottom-left corner pixel has coordinate (0, 0)
glViewport(0, 0, fbWidth, fbHeight);

// Draw the textures with "clever" blending using alpha channel and stencil buffer.
// Note that the very same function is called for ON-SCREEN rendering.

Do you have any suggestions what went wrong here?

Thanks for any help on this topic.

Share this post

Link to post
Share on other sites
Just bumped the thread. I'm really stuck with this problem, I can't figure it out. Please intervene if the problem formulation is not clear enough (or if I should pose the question in the beginner's corner...). Thanks alot!

Share this post

Link to post
Share on other sites
Well, the code seems to be correct. I would test if a depth/stencil format works better.

// define packed depth/stencil format
glRenderbufferStorageEXT(GL_RENDERBUFFER_EXT, GL_DEPTH24_STENCIL8_EXT, fbWidth, fbHeight);

// attach als stencil and depth buffer

Share this post

Link to post
Share on other sites
Thanks for your reply.

Your suggestions leads to the very same problem. It seems as if the stencil test fails for some reason. (Read in this thread why I need a stencil buffer.)

After having played around a while, I found out that if I adjust the following line of code I receive proper blending at the frame borders.

// glRenderbufferStorageEXT(GL_RENDERBUFFER_EXT, GL_RGBA, fbWidth, fbHeight);
glRenderbufferStorageEXT(GL_RENDERBUFFER_EXT, GL_RGB, fbWidth, fbHeight);

So - with black background both the ON-SCREEN and OFF-SCREEN rendering give the same result.

BUT - this is still not what I want! I set the background to the transparent color vec4(0.f, 0.f, 0.f, 1.f) - however, if the color format GL_RGB is applied I lose the transparency (which is what I want outside of the texture scene). I don't get why the alpha-blending of overlapping frames works properly if I exclude the alpha channel from the drawing loop. Can someone explain this to me? And: is there a way to preserve the transparency of the background?

... Sorry for being so picky ...

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!