Results 1 to 9 of 9

Thread: Depth Buffering

  1. #1
    Junior Member Newbie
    Join Date
    Apr 2000
    Posts
    5

    Depth Buffering

    Ok, here is the situation. I have a height map rendered as a quad strip. If I travel at ground level in the positive z-axis depth buffering works properly. However when I turn around and travel in the negative direction on the z-axis it doesn't work. I can see things that shouldn't be rendered. When I travel along the x-axis in either the positive or negative direction I have half of the screen with depth buffering working and the other half not working. Anyway I'm not that experienced coding in OpenGL, and I think I'm just doing something really stupid . I'll post my code if that will help, but it's really bad .

    [This message has been edited by SpaceCadet (edited 04-21-2000).]

  2. #2
    Senior Member Frequent Contributor
    Join Date
    Feb 2000
    Location
    London
    Posts
    503

    Re: Depth Buffering

    Weird. You aren't doing something silly like applying your viewpoint rotations to the projection matrix, are you? That might explain it.

  3. #3
    Member Contributor
    Join Date
    Feb 2000
    Location
    France
    Posts
    55

    Re: Depth Buffering

    Well, I think the problem seems to be that you just don't enable the depth test, so polygons that are drawn first are hided by last. Just type glEnable(GL_DEPTH_TEST); after the initialization of OpenGL.

  4. #4
    Junior Member Newbie
    Join Date
    Apr 2000
    Posts
    5

    Re: Depth Buffering

    I'm calling glEnable(GL_DEPTH_TEST). I may be messing with the projection matrix I'm not really sure. Each time I render the scene I call; glLoadIdentity(), glMatrixMode(GL_PROJECTION), and then use gluLookAt(...) to set up the veiwing.

  5. #5
    Senior Member Frequent Contributor
    Join Date
    Feb 2000
    Location
    London
    Posts
    503

    Re: Depth Buffering

    There should be a glMatrixMode(GL_MODELVIEW) somewhere before you call glLookAt. If there isn't, I'd say that's your problem.

  6. #6
    Junior Member Newbie
    Join Date
    Apr 2000
    Posts
    4

    Re: Depth Buffering

    Originally posted by SpaceCadet:
    I'm calling glEnable(GL_DEPTH_TEST). I may be messing with the projection matrix I'm not really sure. Each time I render the scene I call; glLoadIdentity(), glMatrixMode(GL_PROJECTION), and then use gluLookAt(...) to set up the veiwing.
    Maybe I'm wrong, but calling Load Identity() before setting your glMatrixMode isn't going to screw things really bad?

  7. #7
    Member Contributor
    Join Date
    Feb 2000
    Location
    France
    Posts
    55

    Re: Depth Buffering

    >I call; glLoadIdentity(), glMatrixMode(GL_PROJECTION), and then use gluLookAt(...)
    It's not the right way. Instead you must call glMatrixMode(GL_MODELVIEW); glLoadIdentity(); and gluLookAt(...)
    And at the beginning of the program after initialization, call glMatrixMode(GL_PROJECTION); glLoadIdentity(); gluPerspective(...). Look at tutorials.

  8. #8
    Junior Member Newbie
    Join Date
    Apr 2000
    Posts
    5

    Re: Depth Buffering

    it was my mistake I use glMatrixMode(GL_MODELVIEW)

  9. #9
    Senior Member Frequent Contributor
    Join Date
    Apr 2000
    Location
    Adelaide, South Australia, Australia
    Posts
    763

    Re: Depth Buffering

    Hmm, although you're right in that gluLookAt should apply to the modelview matrix, when you think about how the maths all works out, it shouldn't really mater. I mean, the projection eqn is:

    v'=Pv

    right? With a modelview matrix it's

    v'=PMv

    so it doesn't REALLY matter if it's

    v'=(PM)Iv

    or

    v'=P(IM)v

    where the first case is postmultiplying the projection matrix with the lookat, and in the second case, postmultiplying the identiy modelview matrix with the lookat.

    cheers
    John

Similar Threads

  1. Depth buffering problem
    By theDancer in forum Vulkan
    Replies: 0
    Last Post: 07-22-2017, 09:15 AM
  2. FBO and Depth Buffering
    By Zulfiqar Malik in forum OpenGL: Advanced Coding
    Replies: 5
    Last Post: 07-02-2005, 07:08 AM
  3. Depth buffering & transparency plz. help!
    By W. C. Picker in forum OpenGL: Basic Coding
    Replies: 2
    Last Post: 02-18-2003, 03:58 AM
  4. Depth Buffering Question!
    By Roach in forum OpenGL: Basic Coding
    Replies: 3
    Last Post: 01-06-2003, 02:01 PM
  5. Depth Buffering - HELP !!
    By stockton in forum OpenGL: Basic Coding
    Replies: 7
    Last Post: 01-22-2002, 07:05 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