views:

260

answers:

2

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?

+1  A: 

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.

kayahr
A: 

I am new to OpenGl.Please Help me. How can I draw or put images into transparent 3d cube. I use the same CubeRender.java, Cube.java files from Api Demos.In my CubeActivity class I add mCubeView.getHolder().setFormat(PixelFormat.TRANSPARENT) to have transparent cube.

David