View Full Version : Depth problem on render to texture.

Alberto García
04-06-2015, 11:41 AM
Hi all, I am trying to render my scene in a texture, all works fine, but there is a problem whith the z value when I render in a texture, it produces differents colours in the scenes. In the texture render is like if the depth buffer not work fine. I have been testing my program and when I set "0" in the "near plane" argument on the glPerspective function, it produces the same effects than the texture render. Its seem that near plane change when I render on my texture. I have to say that I render equal the texture scene, and the main scene ( front buffer ). You can see the picture where in order to understand better the issue.


Thanks for your time.

Alfonse Reinheart
04-06-2015, 12:30 PM
It's much more likely that you simply forgot to attach a depth buffer (https://www.opengl.org/wiki/Depth_Buffer) to your FBO (https://www.opengl.org/wiki/Framebuffer_Object) when you rendered to your texture. The default framebuffer (https://www.opengl.org/wiki/Default_Framebuffer) (usually) comes with its own depth buffer. But if you're rendering to a texture, you must provide one yourself. Either as a depth-format (https://www.opengl.org/wiki/Image_Format#Depth_formats) texture or a depth-format renderbuffer (https://www.opengl.org/wiki/Renderbuffer_Object).

Otherwise, depth testing (https://www.opengl.org/wiki/Depth_Test) does not work.

Alberto García
04-06-2015, 01:06 PM
Lot of thanks Alfonse, I have attached a depth buffer a now all works fine.

Best regards!