Results 1 to 5 of 5

Thread: GL_DEPTH_TEST -> What am I doing wrong?

  1. #1
    Junior Member Newbie
    Join Date
    May 2008
    Posts
    6

    GL_DEPTH_TEST -> What am I doing wrong?

    Just learning OpenGL, so I'm playing with simple programs to get the hang of things. I'm experimenting with 3d and I swear the following code should result with the red square under the blue square, but when I run it, the red's always above (because it is drawn later) even though it should be hidden by the depth testing. What's the problem?
    Relevant code (in its entirety, no camera tricks or anything)
    glClearColor(0.0, 0.0, 0.0, 1.0);
    glOrtho(-3.0, 3.0, -3.0, 3.0, -20.0, 20.0);

    glEnable(GL_DEPTH_TEST);

    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

    glBegin(GL_QUADS);
    /* FRONT , blue */
    glColor3f(0.0, 0.0, 1.0);
    glVertex3f(1.0, -1.0, -1.0);
    glVertex3f(1.0, 1.0, -1.0);
    glVertex3f(-1.0, 1.0, -1.0);
    glVertex3f(-1.0, -1.0, -1.0);
    /* BACK , red */
    glColor3f(1.0, 0.0, 0.0);
    glVertex3f(1.25, -1.25, -1.25);
    glVertex3f(1.25, 0.75, -1.25);
    glVertex3f(-0.75, 0.75, -1.25);
    glVertex3f(-0.75, -1.25, -1.25);
    glEnd();
    glFlush();

  2. #2
    Senior Member OpenGL Pro dletozeun's Avatar
    Join Date
    Jan 2006
    Location
    FRANCE
    Posts
    1,367

    Re: GL_DEPTH_TEST -> What am I doing wrong?

    Quote Originally Posted by Aaron McConnell
    glOrtho(-3.0, 3.0, -3.0, 3.0, -20.0, 20.0);
    why do you put the near plane behind the eye? Try something like:

    glOrtho(-3.0, 3.0, -3.0, 3.0, 1.0, 20.0);

  3. #3
    Junior Member Newbie
    Join Date
    May 2008
    Posts
    6

    Re: GL_DEPTH_TEST -> What am I doing wrong?

    Even if I bring the planes in very tight

    glOrtho(-3.0, 3.0, -3.0, 3.0, 0.9, 1.26);

    red is still on top.

  4. #4
    Senior Member OpenGL Guru
    Join Date
    Feb 2000
    Location
    Sweden
    Posts
    2,978

    Re: GL_DEPTH_TEST -> What am I doing wrong?

    Check the pixel format if you have a depth buffer at all.

  5. #5
    Junior Member Newbie
    Join Date
    May 2008
    Posts
    6

    Re: GL_DEPTH_TEST -> What am I doing wrong?

    You were right on target. The fault, Bob, lay not in my GL, but in my GDK. When I made the window, I didn't bother to ask for a depth buffer.

    There are times when I've felt like a bigger idiot, but not many...

Similar Threads

  1. Strange Problem GL_DEPTH_TEST
    By ketenev in forum OpenGL: Basic Coding
    Replies: 2
    Last Post: 04-01-2013, 01:41 AM
  2. GL_DEPTH_TEST not working?
    By someoney in forum OpenGL: Basic Coding
    Replies: 2
    Last Post: 10-24-2010, 03:40 PM
  3. glEnable(GL_ALPHA_TEST | GL_DEPTH_TEST)
    By knackered in forum OpenGL: Advanced Coding
    Replies: 1
    Last Post: 07-07-2010, 06:05 AM
  4. Looks like GL_DEPTH_TEST is failing ?
    By Andrew Jameson in forum OpenGL: Basic Coding
    Replies: 3
    Last Post: 06-08-2002, 11:35 PM
  5. GL_DEPTH_TEST question
    By Alessandro_dup1 in forum OpenGL: Advanced Coding
    Replies: 5
    Last Post: 04-12-2001, 05:45 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