Yet another update: I changed the texture type to GL_TEXTURE_RECTANGLE. This way I can directly use gl_FragCoord.xy when passing data to the textures. I'm using the defaults, so I assume gl_FragCoord.xy will have values like 0.5, 1.5, 2.5, etc.
I store all my display data on display lists. I draw my display list once and save the color and depth buffer by create a frame buffer with GL_TEXTURE_RECTANGLE textures for both - one color, and one depth. The filters on both textures are set to GL_NEAREST.
I query the depth texture using
float depth = texture (depthtex,gl_FragCoord.xy).r;
My expectation is that this call should always find the exact same texel in my texture; so it writes the color and depth on one pass and reads with the exact same coordinates on the next path.
But, unfortunately, this is not the case. I "solved" my problem by using a tolerance such as
if(depth >= gl_FragCoord.z - 0.00001) discard;
on the second time I draw. The image looks perfect - pointing to the fact that this was indeed my problem. But
1) Why do I not get the exact same values on the second pass as the first pass, or... why does my comparison fails at times?\
2) Can I get better results by using different texture parameters?