Results 1 to 10 of 10

Thread: Quads with no depth sorting?

  1. #1
    Member Contributor
    Join Date
    Feb 2001
    Location
    Hungary
    Posts
    60

    Quads with no depth sorting?

    I've got 4 cubes made of quads rotating around 0,0,0. The problem is, that the quads appear in the correct order when I render them, but it looks like the cubes are rendered one after the other in a way, that the newly drawn cubes are drawn in front of the old ones.
    It's like no depth sorting was used - but only when rendering the cubes (and not the quads of a cube).

    I'll post a piece of my code (as short as possible), maybe someone will find something I haven't.


    In "MAIN":

    glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    glMatrixMode(GL_MODELVIEW);glLoadIdentity();glPush Matrix();
    glMatrixMode( GL_PROJECTION );glPushMatrix();glLoadIdentity();
    gluPerspective( 80, 1.3, 0,1000.0 );
    gluLookAt(0, 0, 5, 0,0,0, 0,1,0);

    glEnable(GL_DEPTH_TEST);
    glEnable(GL_TEXTURE_2D);

    glTranslated(0,0,0);
    glRotated(rot,1,0,0);
    draw_cubes();

    glMatrixMode(GL_PROJECTION);glPopMatrix();
    glMatrixMode(GL_MODELVIEW);glPopMatrix();
    SwapBuffers(DCvalue);


    In the init() I also wrote:
    glEnable(GL_NORMALIZE);
    glDepthFunc(GL_LEQUAL);
    glShadeModel(GL_SMOOTH);

    I 'stole' the normals and the vertices' data from the NeHe 'Missile mapping' lesson, so, they should be correct:
    Quad 1:
    normal1=0;normal2=0;normal3=1;
    texcoord11=0;texcoord12=0;
    texcoord21=1;texcoord22=0;
    texcoord31=1;texcoord32=1;
    texcoord41=0;texcoord42=1;
    x1= 0+x; y1= 0+y; z1=5;
    x2= 5+x; y2= 0+y; z2=5;
    x3= 5+x; y3= 5+y; z3=5;
    x4= 0+x; y4= 5+y; z4=5;

    Quad 2:
    normal1=0;normal2=0;normal3=-1;
    texcoord11=1;texcoord12=0;
    texcoord21=1;texcoord22=1;
    texcoord31=0;texcoord32=1;
    texcoord41=0;texcoord42=0;
    x1= 0+x; y1= 0+y; z1= 0;
    x2= 0+x; y2= 5+y; z2= 0;
    x3= 5+x; y3= 5+y; z3= 0;
    x4= 5+x; y4= 0+y; z4= 0;

    And so on...

    I know, that drawing 2 cubes is a basic thing to do and I've done harder tricks already, but now, I'm really stuck... I think I missed someting.

    Please, someone help me

  2. #2
    Guest

    Re: Quads with no depth sorting?

    0 is not valid for zNear in gluPerspective...

  3. #3
    Guest

    Re: Quads with no depth sorting?

    Do you realize that you are building the composite MVP on the projection matrix stack?

  4. #4
    Member Contributor
    Join Date
    Feb 2001
    Location
    Hungary
    Posts
    60

    Re: Quads with no depth sorting?

    You mean, I should change the lines like:

    glMatrixMode( GL_PROJECTION );
    glPushMatrix();
    glLoadIdentity();
    glMatrixMode(GL_MODELVIEW);
    glLoadIdentity();
    glPushMatrix();
    gluPerspective( 80, 1.3, 0,1000.0 );
    gluLookAt(0, 0, 20,
    0,0,0,
    0,1,0);

    What does MVP mean?

  5. #5
    Guest

    Re: Quads with no depth sorting?

    Try this

    glMatrixMode( GL_PROJECTION );
    glLoadIdentity();
    gluPerspective( 80, 1.3, 1, 1000.0 );

    glMatrixMode(GL_MODELVIEW);
    glLoadIdentity();
    gluLookAt( 0,0,20, 0,0,0, 0,1,0 );

    The transforms are applied to the currently active matrix stack.

    You don't need to push/pop the initial matrices, unless you just want to...

    MVP = (M)odel(V)iew + (P)rojection

  6. #6
    Guest

    Re: Quads with no depth sorting?

    I mean MVP is the product of the modelview and projection matrices (in case someone mistakes string concatenation with a matrix operation).

  7. #7
    Member Contributor
    Join Date
    Feb 2001
    Location
    Hungary
    Posts
    60

    Re: Quads with no depth sorting?

    Thanks. I tried it. Now it looks like:

    glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

    glMatrixMode( GL_PROJECTION );
    glLoadIdentity();
    gluPerspective( 80, 1.3, 0,1000.0 );

    glMatrixMode(GL_MODELVIEW);
    glLoadIdentity();
    gluLookAt(0, 0, 20,
    1,1,1,
    0,1,0);

    glDisable(GL_LIGHTING);
    glEnable(GL_DEPTH_TEST);
    glEnable(GL_TEXTURE_2D);

    glTranslated(0,0,0);
    glRotated(rot,1,0,0);
    draw_cubes();

    glEnable(GL_LIGHTING);

    SwapBuffers(DCvalue);

    But nothing changed. It is the same bad result...

  8. #8
    Guest

    Re: Quads with no depth sorting?

    You still have a 0 for zNear!


  9. #9
    Member Contributor
    Join Date
    Feb 2001
    Location
    Hungary
    Posts
    60

    Re: Quads with no depth sorting?

    Oops. Missed your gluperspective line change. Now it's ok. It works.
    I rewrote the code in its original state just to see how it should have worked. The problem was really this line...

    I knew, that I just missed something. You have better eyes than I do. Thanks again.

  10. #10
    Guest

    Re: Quads with no depth sorting?

    Yeah, projection matrix abuse like that works, but you are hosed when it comes to fixed-function lighting and texgen since opengl relies on the contents of the modelview matrix for various things. Just something to keep in mind...

Similar Threads

  1. Depth sorting.
    By MrShoe in forum OpenGL: Advanced Coding
    Replies: 15
    Last Post: 08-25-2004, 03:17 AM
  2. Do I need Depth Sorting?
    By B_old in forum OpenGL: Basic Coding
    Replies: 15
    Last Post: 12-09-2002, 12:04 PM
  3. Depth sorting problem
    By Syslock in forum OpenGL: Basic Coding
    Replies: 4
    Last Post: 10-22-2001, 01:25 PM
  4. Depth Sorting
    By imported_Theo in forum OpenGL: Basic Coding
    Replies: 1
    Last Post: 01-13-2001, 01:09 PM
  5. How can i do depth sorting
    By mczhao in forum OpenGL: Advanced Coding
    Replies: 1
    Last Post: 11-09-2000, 05:20 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Proudly hosted by Digital Ocean