Login  Register

Re: Seeking Help with OpenGL Depth Buffer Issue

Posted by xghost on Oct 16, 2014; 6:20am
URL: https://forum.jogamp.org/Seeking-Help-with-OpenGL-Depth-Buffer-Issue-tp4033219p4033373.html

jmaasing wrote
Just so you know, setting small values on the near clip plane is usually avoided due to precision issues, this is a good explanation: http://www.sjbaker.org/steve/omniv/love_your_z_buffer.html
Thanks for the link. It was a good read and I'll keep it around.

jmaasing wrote
OpenGL often do raise an error (depending on driver ofc) when you break the spec. Sometimes you must remember to ask OpenGL about the status of the previosu operation and the way I usually do it is to use JOGL-classes and constructs like these
drawable.setGL(new TraceGL4(new DebugGL4(gl.getGL4()), System.out));
I was already using them as shown in the project I had attached :)

The glGetError checks simply showed everything being "ok". From the OpenGL spec (e.g. gluPerspective doc, though I'm not using this function myself.) states that the value for zNear/zFar must be a positive number. The fact that it does not specify that receiving a non-positive number (e.g. zero or negative) should raise an error (e.g. GL_INVALID_VALUE) seems to suggest that it's undefined behavior at this point and the driver may behave in whatever way it sees fit (read: likely unpredictable).

While writing this, I think I realized why OpenGL never raised any errors of any kind. OpenGL might've raised an error for a non-positive zNear value (e.g. GL_INVALID_VALUE) if the function specifically taking those inputs had been used. But it was never used; the perspective matrix was built and then sent to the pipeline using a uniform, so I don't think it could've raised any errors anyway.

-x

PS: Hindsight 20/20