Results 1 to 2 of 2

Thread: Depth Buffer

  1. #1
    Junior Member Newbie
    Join Date
    May 2009
    Location
    IL, USA
    Posts
    1

    Depth Buffer

    Hi all -
    I am trying to use the Depth Buffer feature of OpenGL to determine when one pixel should or should not be drawn on top of another. I enable the Depth Buffer and have confirmed that it is active and working.

    The documentation I read indicates that the z-axis value determines whether or not a pixel will overwrite the value of a previous pixel. If the z-axis value is numerically higher, the new pixel will overwrite the old one, else it will not. I have actually confirmed that this is working by changing the z-axis value in the drawing functions used, which is simply glVertex3f. If I change the last parameter, which is the z-axis value, it affects which points overwrite others, as stated by the documentation.

    My problem is that when I change the z-axis value, the value of the point shifts on the graph. It's as if the z-axis value was being interpreted as an actual z value in a 3D coordinate system. It was my understanding that if you have the Depth Buffer enabled, the z-axis value is used for the Depth test only, and not as part of the point coordinate. My understanding is very limited, I just started working with OpenGL a few days ago.

    Since our plot is really a 2D plot, I don't need to specify a z-axis value, and want to use this value solely to control the Depth Buffer and not have it interpreted as the z-axis value of a 3D coordinate. Is this possible?

    Thanks in advance for any help you can give me.
    Bud

  2. #2
    Senior Member OpenGL Guru
    Join Date
    Dec 2000
    Location
    Reutlingen, Germany
    Posts
    2,042

    Re: Depth Buffer

    Yes, it is possible, but your understanding of the pipeline is indeed very limited.

    With glVertex3f you specify points in 3D space. That means the z-value in 3D space has nothing to do with the "Z-value" used in the depth test. The depth test operates in a different space (screen-space) that is always relative to what you are looking at. For example, if you look down the X-axis, the depth-test will still sort your geometry correctly, because it sorts everything by the depth from it's camera center, no matter which axis that actually is. It only names that depth as "Z", but it is not the same as the z-axis given with glVertex.

    If you really only want to render 2D geometry, you should look at the function glOrtho. It sets up an orthographic projection, that is one where you don't use any perspective foreshortening depending on the depth, but the depth is mostly ignored (except for the depth-test, which can still use it for sorting). Right now you most certainly use gluPerspective or glFrustum to set up your camera matrix. That piece of code needs to be replaced with glOrtho.

    Hope that helps,
    Jan.
    GLIM - Immediate Mode Emulation for GL3

Similar Threads

  1. OpenGL: Draw a depth texture to depth buffer
    By Balrog in forum OpenGL: Advanced Coding
    Replies: 1
    Last Post: 04-25-2012, 04:53 AM
  2. Depth buffer reading and depth buffer test
    By BurningLegion in forum OpenGL: Basic Coding
    Replies: 0
    Last Post: 03-15-2007, 04:09 AM
  3. Does Depth Buffer Allow Writing Into When Disabling Depth Test
    By wilburn in forum OpenGL: Basic Coding
    Replies: 16
    Last Post: 12-23-2006, 01:23 AM
  4. depth buffer -> depth texture -> depth buffer
    By Codemonkey in forum OpenGL: Advanced Coding
    Replies: 9
    Last Post: 12-23-2005, 06:27 AM
  5. why depth buffer save to image file can not display depth information
    By victorswan in forum OpenGL: Basic Coding
    Replies: 1
    Last Post: 05-27-2001, 09:19 PM

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