Posted by
xghost on
Sep 29, 2014; 7:26am
URL: https://forum.jogamp.org/Seeking-Help-with-OpenGL-Depth-Buffer-Issue-tp4033219p4033234.html
If it's truly obvious, then it must've bitten my face off a thousand times and I've not yet found what it could be :(
I've already tried setting the color to the
gl_FragCoord.z value in the fragment shader, which according to documentation, has the depth value of the current fragment being processed (not the depth value currently in the depth buffer).
If I change the frag shader color output line to any of these alternatives:
color = vec4(gl_FragCoord.x, gl_FragCoord.y, gl_FragCoord.z, 1.0);
// or
color = vec4(gl_FragCoord.z, gl_FragCoord.z, gl_FragCoord.z, 1.0);
...then everything shows up white. I guess this specific result was kind of expected since changing the glDepthFunc to GL_LESS seems to prevent anything from getting written into the frame buffer and nothing gets rendered, but "works" with GL_EQUAL and GL_LEQUAL.
I've been chasing this issue on-n-off (work full time, so don't necessarily get the chance every night) for some time now (2.5+ weeks), and I usually spend my time before I try asking for help on the forum. I've done additional reading on depth buffer/testing, but the one that seems to go into a bit more detail is this one[1], yet nothing has been useful so far. (My other reading resources have been offline --i.e. books.) Even the 8th Ed of the OpenGL "Red Book" barely skims through it and doesn't seem to share anything that I don't already seem to understand. I guess that's what has made this issue problematic to root-cause: it seems to be so simple and straightforward that not even the reference books spend too much time on that topic.
I'd at least be interested to see if others see the same result I am. (I'd like to confirm that the issue is actually on my code and not something else...) I've attached the code here[2]. In the current implementation, the object's are set to be at known locations, so that they're stationary and we can know what the end result should look like.
If anyone could take a few minutes to try this, I'd appreciate it. For the project, I actually decided to use a graphics library posted at the CSUS web site[3], which handles the Point, Vector, and Matrix-related classes. (This is needed to run the project.) Those have been tested and are very unlikely to be related.
Thanks again in advance for anyone willing/able to help out.
[1]
http://www.arcsynthesis.org/gltut/Positioning/Tut05%20Overlap%20and%20Depth%20Buffering.html[2]
test-proj.gz[3]
http://athena.ecs.csus.edu/~gordonvs/155/graphicslib3D.zip