OpenGLES 2.0 and a 3D scene

Discussion in 'iPhone/iPad Programming' started by Chirone, Jun 13, 2010.

  1. macrumors 6502

    Joined:
    Mar 2, 2009
    Location:
    NZ
    #1
    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.
     
  2. macrumors newbie

    Joined:
    Jun 13, 2010
    #2
    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 :
    [​IMG]
     
  3. thread starter macrumors 6502

    Joined:
    Mar 2, 2009
    Location:
    NZ
    #3
    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
     
  4. macrumors regular

    Joined:
    Jun 5, 2010
    #4
    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
     
  5. thread starter macrumors 6502

    Joined:
    Mar 2, 2009
    Location:
    NZ
    #5
    so if nothing is showing up only when glEnable(GL_Depth_Test) is on what does that tell you?
     
  6. thread starter macrumors 6502

    Joined:
    Mar 2, 2009
    Location:
    NZ
    #6
    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
     
  7. macrumors newbie

    Joined:
    Jun 13, 2010
    #7
    Chirone as for the matrix wrongness you were wright.

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

    Joined:
    Jun 13, 2010
    #8
    Hye,

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

    It solve a problem for me.
     

Share This Page