View Full Version : OpenGLES 2.0 and a 3D scene

Jun 13, 2010, 05:31 PM
I'm trying to make a 3D scene with opengles 2.0 by rendering multiple models

the problem i'm having is that the models appear on top of each other like it's 2D

so.. if in the code a cube is drawn after a cone then the cube is drawn on top of the cone even though the cube's coordinates have it behind the cone

how do i render a 3D scene in opengles 2.0? i've enabled Depth_Test like i would if it were opengles 1 but that didn't help.

Jun 13, 2010, 06:07 PM

Did you find any solutions ? I have exactly the same problem.
As for me , I just can't draw a simple square.

Here is the result :
http://img706.imageshack.us/img706/5872/cubeone.th.png (http://img706.imageshack.us/i/cubeone.png/)

Jun 13, 2010, 06:44 PM

when i added this code:
glGenRenderbuffers(1, &depthRenderbuffer);
glBindRenderbuffer(GL_RENDERBUFFER, depthRenderbuffer);
glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH_COMPONENT16, backingWidth, backingHeight);
glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, depthRenderbuffer);
which is meant to enable the depth buffer nothing happened... i just got a black screen, yet it worked for other people :confused:
is there something in the apple template that's missing to make this work?

edit: whoops, i accidentally killed two lines in the draw method that binds the frame buffer and color buffer

things show up if Depth_Test isn't enabled, but otherwise nothing shows up....

gandrakar: is that meant to be a cube? looks like you've something funny going on inside your shader or whatever stores the coordinates of the verts of the cube, or you've funny matrix math

Jun 13, 2010, 07:14 PM
As an experienced 3D guy, there are too many possibilities:
incorrect depth function
bad z values in vertices
incorrect clearing of depth values
depth buffer not created attached correctly

read the redbook and find an example and go line by line

Jun 13, 2010, 07:38 PM
so if nothing is showing up only when glEnable(GL_Depth_Test) is on what does that tell you?

Jun 13, 2010, 08:12 PM
i seem to get something if i go like this:
// drawing code

i just tried different depth functions

edit: oh wait, things just show up as if depth_test wasnt enabled

Jun 14, 2010, 02:53 AM
Chirone as for the matrix wrongness you were wright.

I have few mistakes in matrix multiplication. However I always have the depth buffer problem.

Jun 14, 2010, 06:05 AM

Chirone did you think about the glEnable(GL_CULL_FACE); option.

It solve a problem for me.