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…
glEnable(GL_DEPTH_TEST);
glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
glClearDepthf(1.0);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glDepthMask( GL_TRUE );
glDepthFunc(GL_EQUAL);
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);
glFramebufferRenderbufferOES(GL_FRAMEBUFFER_OES, GL_DEPTH_ATTACHMENT_OES, 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
glFramebufferRenderbufferOES(GL_FRAMEBUFFER_OES, GL_DEPTH_ATTACHMENT_OES, GL_RENDERBUFFER_OES, depthRenderbuffer);
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…