• 13
• 27
• 9
• 9
• 20

# Inconsistent off-screen rendering using FBO

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

## 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);glFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT, GL_RENDERBUFFER_EXT, colorBuffer);// 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);glFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT, GL_STENCIL_ATTACHMENT_EXT, GL_RENDERBUFFER_EXT, stencilBuffer);GLenum status = glCheckFramebufferStatusEXT(GL_FRAMEBUFFER_EXT);if(status == GL_FRAMEBUFFER_COMPLETE_EXT){	// Prepare drawing.	glClearColor(0.0f, 0.0f, 0.0f, 0.0f);	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);	glMatrixMode(GL_PROJECTION);	glLoadIdentity();	gluOrtho2D(0, fbWidth, fbHeight, 0); // Bottom-left corner pixel has coordinate (0, 0)	glViewport(0, 0, fbWidth, fbHeight);	glMatrixMode(GL_MODELVIEW);	glLoadIdentity();	glPushMatrix();	// Draw the textures with "clever" blending using alpha channel and stencil buffer. 	// Note that the very same function is called for ON-SCREEN rendering.	drawImagesWithBlending();}

Do you have any suggestions what went wrong here?

Thanks for any help on this topic.

##### 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 on other sites
Well, the code seems to be correct. I would test if a depth/stencil format works better.
// define packed depth/stencil formatglRenderbufferStorageEXT(GL_RENDERBUFFER_EXT, GL_DEPTH24_STENCIL8_EXT, fbWidth, fbHeight);// attach als stencil and depth bufferglFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT, GL_DEPTH_ATTACHMENT_EXT, GL_RENDERBUFFER_EXT, dstencilBuffer);glFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT, GL_STENCIL_ATTACHMENT_EXT, GL_RENDERBUFFER_EXT, stencilBuffer);

##### Share on other sites

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 ...