PDA

View Full Version : FBO problem



apapaxionga
12-13-2011, 05:39 AM
i render a scene including a teapot and ambient light .Without using fbo the whole scene seems ok!When i using fbo to render the scene into a texture,the light become dim. Why?


glGenFramebuffersEXT(1, &fb);
glGenTextures(1, &tex);
glGenRenderbuffersEXT(1, &depth_rb);

glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, fb);


glBindTexture(texTarget, tex);

glTexImage2D(texTarget,0,GL_RGBA,texWidth,texHeigh t,0,GL_RGBA,GL_FLOAT,0);

glTexParameterf(texTarget, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameterf(texTarget, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameterf(texTarget, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameterf(texTarget, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);



glBindRenderbufferEXT(GL_RENDERBUFFER_EXT, depth_rb);
glRenderbufferStorageEXT(GL_RENDERBUFFER_EXT, GL_DEPTH_COMPONENT, texWidth, texHeight);

glBindRenderbufferEXT(GL_RENDERBUFFER_EXT, 0);

glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT, GL_TEXTURE_2D, tex, 0);//new
glFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT, GL_DEPTH_ATTACHMENT_EXT, GL_RENDERBUFFER_EXT, depth_rb);//new


glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0);

_arts_
12-13-2011, 08:51 AM
With dim, I think you mean more dark ?


glTexImage2D(texTarget,0,GL_RGBA,texWidth,texHeigh t,0,GL_RGBA,GL_FLOAT,0);

You ask for an RGBA texture (so 4 channels of 1 byte each and and you use float, which is 4 bytes for each channel).
Try to use GL_UNSIGNED_BYTE instead of GL_FLOAT.

V-man
12-13-2011, 12:19 PM
With dim, I think you mean more dark ?


glTexImage2D(texTarget,0,GL_RGBA,texWidth,texHeigh t,0,GL_RGBA,GL_FLOAT,0);

You ask for an RGBA texture (so 4 channels of 1 byte each and and you use float, which is 4 bytes for each channel).
Try to use GL_UNSIGNED_BYTE instead of GL_FLOAT.

When the last parameter is 0, then whether you use GL_FLOAT or GL_UNSIGNED_BYTE doesn't matter.

0 means you don't intend to upload any texels. It means leave the memory location in whatever state it is in already.

The data storage is controlled by the 3rd parameter
http://www.opengl.org/wiki/Common_Mistakes#Image_precision

and also
http://www.opengl.org/wiki/Textures
where it says "The format, type, and data parameters are used for performing...etc"

Alfonse Reinheart
12-13-2011, 01:03 PM
When the last parameter is 0, then whether you use GL_FLOAT or GL_UNSIGNED_BYTE doesn't matter.

Actually, that's not true. The call can still fail if the pixel transfer formats don't match the internal format for the basic pixel type. For example, if you're creating a GL_DEPTH_COMPONENT24 internal format, you *must* use GL_DEPTH_COMPONENT for the pixel transfer format.

Yet another reason why texture_storage was long overdue...

apapaxionga
12-13-2011, 06:26 PM
So why how can i make the scene brighter ? what changes should i make?

apapaxionga
12-14-2011, 05:21 AM
GL_FLOAT is still the same.

mobeen
12-14-2011, 05:39 AM
I am not sure if this helps but I suspect maybe you have left the lighting on after rendering the scene to the fbo? Could u post the display function just to see whether there is anything else that might be causing this.

_arts_
12-14-2011, 06:17 AM
Yes, give us pertinent code (where you draw). You might don't render the light in the same way (before or after the modelview transform for example).

Even if it is the same with GL_FLOAT (as posters said, this has no influence under this situation: no data given and not depth texture wanted), putting coherent arguments make the code more clean, more readable and more coherent: more pertinent and less prone to potential bugs.