Skip to main content
GameDev.net gamedev.net
🔒 Locked

Android, OpenGL, and a Depth Problem.

Started by Mike Oct 3, 2010 at 10:24 AM 2 replies 3.1k views
Original Post
Mike
Mike
I'm working on getting started on Anroid development; however, I'm having a problem with the depth buffer I cannot figure out.

picture:


code:
public void onSurfaceCreated( GL10 gl, EGLConfig eglConfig ) {
gl.glEnable(GL10.GL_DEPTH_TEST);
gl.glDepthFunc( GL10.GL_LEQUAL );

gl.glMatrixMode(GL10.GL_PROJECTION);
float size = .01f * (float) Math.tan(Math.toRadians(45.0) / 2);
float ratio = _width / _height;
// perspective:
gl.glFrustumf(-size, size, -size / ratio, size / ratio, 0.01f, 100.0f);
// orthographic:
//gl.glOrthof(-1, 1, -1 / ratio, 1 / ratio, 0.00f, 200.0f);
gl.glViewport(0, 0, (int) _width, (int) _height);
gl.glMatrixMode(GL10.GL_MODELVIEW);

gl.glClearColor(0f, 0f, 0f, 1.0f);
gl.glEnable(GL10.GL_CULL_FACE);
gl.glFrontFace(GL10.GL_CCW);
gl.glCullFace(GL10.GL_BACK);

gl.glEnableClientState(GL10.GL_VERTEX_ARRAY);
gl.glEnableClientState(GL10.GL_COLOR_ARRAY);

initTriangle();
}

public void onDrawFrame(GL10 gl) {
gl.glClear(GL10.GL_COLOR_BUFFER_BIT | GL10.GL_DEPTH_BUFFER_BIT);

gl.glVertexPointer(3, GL10.GL_FLOAT, 0, _vertexBuffer);
gl.glColorPointer(4, GL10.GL_FLOAT, 0, _colorBuffer);

for (int i = 1; i <= 3; i++) {
gl.glLoadIdentity();
gl.glTranslatef(0.0f, -1.0f, -1.0f + (-1.5f*i));
// set rotation
gl.glRotatef(_xAngle, 1f, 0f, 0f);
gl.glRotatef(_yAngle, 0f, 1f, 0f);
gl.glDrawElements(GL10.GL_TRIANGLES, _nrOfVertices, GL10.GL_UNSIGNED_SHORT, _indexBuffer);
}

int[] depth = new int[10];
gl.glGetIntegerv(GL10.GL_DEPTH_BITS, depth, 0);
}
Rene Z
Rene Z
I don't know how the context is created on android, but are you sure you created a depth buffer?
Mike
Mike
The following code (at the end of the onDrawFrame method) returns 16:

int[] depth = new int[10];
gl.glGetIntegerv(GL10.GL_DEPTH_BITS, depth, 0);

So I'm assuming that the depth buffer exists. At the beginning of the onSurfaceCreated method the following line is used to enable depth testing:

gl.glEnable(GL10.GL_DEPTH_TEST);

From what I've found on the Internet, that is all that is needed to enable the depth buffer when using OpengGL ES; however, I'm clearly missing something. I just can't figure out what.
Mike
Mike
I resolved my problem. It turns out I was calling setEGLConfigChooser(false) elsewhere in my code which tells the view to choose a configuration that is as close to 16 bit RGB as possible with or without a depth buffer. That "false" was causing the view to use a configuration that had no depth buffer.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.