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.
You’re not having a depth buffer attached to your FBO, are you? Alternatively you’ve not set up your depth testing settings correctly (enabling depth testing, clear depth, actually clearing the depth buffer, depth function, etc).
Also, you can’t read and write to the same texture (depth texture in this case), so you can’t do a manual depth test in the fragment shader.