Android depth buffer issue: Advice for anyone experiencing problem
- by Andrew Smith
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, but 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.