Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

OpenGL depth buffer on Android

I'm currently learning OpenGL ES programming on Android (2.1). I started with the obligatory rotating cube. It's rotating fine but I can't get the depth buffer to work. The polygons are always displayed in the order the GL commands render them. I do this during initialization of GL:

gl.glClearColor(.5f, .5f, .5f, 1);
gl.glShadeModel(GL10.GL_SMOOTH);
gl.glClearDepthf(1f);
gl.glEnable(GL10.GL_DEPTH_TEST);
gl.glDepthFunc(GL10.GL_LEQUAL);
gl.glHint(GL10.GL_PERSPECTIVE_CORRECTION_HINT, GL10.GL_NICEST);

On surface-change I do this:

gl.glViewport(0, 0, width, height);
gl.glMatrixMode(GL10.GL_PROJECTION);
gl.glLoadIdentity();
GLU.gluPerspective(gl, 45.0f, (float) width / (float) height, 0.1f, 100f);

When I enable backface culling then everything looks correct. But backface culling is only a speed-optimization so it should also work with only the depth buffer or not? So what is missing here?

like image 710
kayahr Avatar asked Dec 23 '22 03:12

kayahr


1 Answers

Found it myself. It wasn't GL code, it was android code:

view.setEGLConfigChooser(false);

The "false" in this line explicitly says that no Z-Buffer should be allocated. After switching it to "true" it worked perfectly.

like image 106
kayahr Avatar answered Dec 24 '22 18:12

kayahr