RTT using FBO shows scene as if light was enabled

I’m rendering a scene to a texture using FBOs and then rendering a textured cube to the default framebuffer using the created texture.

I’m not using light at all, but the scene seems to be lighted. The farther I get from the cube the darker it gets.

If I use a normal texture everything is ok.
I’m also blitting the texture directly to the screen (glBlitFramebuffer), and the texture looks ok (no light)

Using OpenGL version 3.2.0 NVIDIA 195.36.15 on Ubuntu karmic

Any ideas why could this be happening?

Download code from here

Perhaps you have fog enabled?

Nope, no fog, no light.

I think you are mistaken.

I might be but as far as I can tell there is no light or fog enabled, please check the code if you have the time, its there in my original post…

OK, I’ve looked at the code, and I see another possibility.

You call glGenerateMipmap() after the texture is defined (with a NULL data pointer), and before the texture image has been drawn with the FBO. Therefore, the mipmaps will be generated based on whatever data happens be be in the reserved texture memory. Based on the appearance, I would say that’s black (at least in that test run). Your rendering redefines the top layer, but not the lower level mips.

As the cube recedes into the distance the texture sampling starts to blend in the black mip layers.

If my guess is right, then the solution is to call glGenerateMipmap() after any time that you update the base texture.

You could also test this by choosing a texture minification mode that does not involve mipmap sampling.

Kelvin, you are right indeed, recreating the mipmaps solved the problem.

Thank you very much!

Whoo hoo!

That was a good one. :slight_smile:

Impressive guess Kelvin, I really had no clue about this !

wow, that was smart!