depth testing in iphone opengl

Hi all,

   I am trying to learn 3d rendering in iphone opengl. I am using xcode 3.1.4 and opengl ES 1.1. 

   I try to draw two cube , one is near to eye and other one is behind the first one in the negative  z plane... I render the front cube first and then the back cube. But Always my back cube is showing in the front because it is rendering second. Ofcourse trying to render in reverse order should cure the problem. But since we have depth testing in iphone opengl I tried to enable it. But there I am having some trouble. 

These are the settings I have done.

In my draw (render()) function…

glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
glDepthMask( GL_TRUE ); 

In my resizeFromLayer function in ES1Renderer.m

glBindRenderbufferOES(GL_RENDERBUFFER_OES, depthRenderbuffer);
glRenderbufferStorageOES(GL_RENDERBUFFER_OES, GL_DEPTH_COMPONENT16_OES, backingWidth, backingHeight);

In init function in ES1Renderer.m

glGenRenderbuffersOES(1, &depthRenderbuffer);
glBindRenderbufferOES(GL_RENDERBUFFER_OES, depthRenderbuffer);

I tried to render after this but this time nothing is drawing and the scene is blank. Then I comment this line from init


Now Two cubes are rendering but just the same way as it is rendered before enabling depth testing… The cube which should be behind is shown in front obstructing the other cube. What am i missing…Please anybody help me…

I have done one more thing to see whether depth buffer value…

int depth;  
glGetIntegerv(GL_DEPTH_BITS, &depth);  
NSLog(@"%i bits depth", depth);  

And the NSLog output is :

0 bits depth

So depth buffer value is zero … I doesnt look good.

Why not grab one of the widely available EAGLView classes from Apple, or an engine like Oolong.

Pretty much all you need to know is in those files.