Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

Chirone

macrumors 6502
Original poster
Mar 2, 2009
279
0
NZ
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.
 
Hye,

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 :
 
no.

when i added this code:
Code:
    if (USE_DEPTH_BUFFER) {
        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
 
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
etc...

read the redbook and find an example and go line by line
 
so if nothing is showing up only when glEnable(GL_Depth_Test) is on what does that tell you?
 
i seem to get something if i go like this:
Code:
glEnable(GL_DEPTH_TEST);
glDepthFunc(GL_ALWAYS);
// drawing code
glDisable(GL_DEPTH_TEST);
i just tried different depth functions

edit: oh wait, things just show up as if depth_test wasnt enabled
 
Chirone as for the matrix wrongness you were wright.

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

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

It solve a problem for me.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.