Android depth buffer issue: Advice for anyone experiencing problem
I've wasted around 30 hours this week writing and re-writing code, believing that I had misunderstood how the OpenGL depth buffer works. Everything I tried, failed. I have now resolved my problem by finding what may be an error in the Android implementation of OpenGL.
See this API entry:
http://www.opengl.org/sdk/docs/man/xhtml/glClearDepth.xml
void glClearDepth(GLclampd depth);
Specifies the depth value used when the depth buffer is cleared. The initial value is 1.
Android's implementation has two versions of this command:
glClearDepthx which takes an integer value, clamped 0-1
glClearDepthf which takes a floating point value, clamped 0-1
If you use glClearDepthf(1) then you get the results you would expect. If you use glClearDepthx(1), as I was doing then you get different results. (Note that 1 is the default value, b开发者_如何学Cut calling the command with the argument 1 produces different results than not calling it at all.) Quite what is happening I do not know, but the depth buffer was being cleared to a value different from what I had specified.
Try passing 65536
to glClearDepthx()
.
GLfixed
is S15.16 fixed-point, so 1.0
is represented by 2^16
or 65536
.
Also, you linked to the regular OpenGL documentation, not the OpenGL ES 1.1 docs.
精彩评论