I have a problem with FBO and depth in openGL. I am passing projection, view and model matrices to a shader that writes to the g buffer. When I unbind the FBO and write to gl_FragColor the scene displays as it ought. But when I write to gl_FragData[0] then write the accompanying texture to a screen aligned quad, objects are drawn according to inverse order processed rather than depth... I can see through objects processed first to objects processed after. Has anyone had the same problem and do they know a fix? Or could someone provide syntax on reading depth values from the vertex shader, querying the current depth, then writing to the depth buffer depending on a comparison, ie, handling the operation manually in the fragment shader.
Asked
Active
Viewed 1,105 times
1 Answers
4
Your main frame-buffer most likely has the depth, while your manually created FBO might not have it. Therefore, when drawing to the screen you have depth-sorted geometry, while your FBO can not provide that and internally works with disabled depth testing having no storage associated with it.

kvark
- 5,291
- 2
- 24
- 33
-
You're right kvark. I didn't realize attaching a depth buffer to the fbo was a requirement for depth culling on fbo bound textures. Also found out that gl_FraDepth[i] is deprecated in favor of defining your own out variables. – ste3e Oct 15 '11 at 08:35
-
`gl_FragData`is deprecated, not `gl_FraDepth[]`. There is also a button in the stackoverflow interface designed for marking the right answer :) – kvark Oct 15 '11 at 13:59