Results 1 to 4 of 4

Thread: Depth buffer test

  1. #1
    Junior Member Newbie
    Join Date
    Jul 2003
    Posts
    8

    Depth buffer test

    Hi,

    I am doing a project which involves displaying 3D objects. I have used the line primitive to draw the object. My problem is to remove the hidden lines of the object to get a understandable form of the object. I tried enabling the GL_DEPTH_TEST and using the depth function but it did not work. Is it possible to do depth test for objects which are drawn using GL_LINES or GL_LINE_LOOP. I haven't used shading is it necessary? how can we get a 3D view of the object?
    this is the code segment that i have used:

    if(m_bHide)
    {
    glEnable(GL_DEPTH_TEST);
    glClearDepth(1.0f);
    glDepthFunc(GL_LESS);
    DrawScene();
    }
    else
    {
    glDisable(GL_DEPTH_TEST);
    DrawScene();
    }
    My Z axis is away from the user
    Please help me out

    Nithya

  2. #2
    Senior Member Regular Contributor
    Join Date
    Sep 2002
    Location
    Nanjing,China
    Posts
    116

    Re: Depth buffer test

    place the glEnable(GL_DEPTH_TEST) after the glDepthFunc()

  3. #3
    Senior Member OpenGL Guru Relic's Avatar
    Join Date
    Apr 2000
    Posts
    2,450

    Re: Depth buffer test

    OpenGL is a state machine, there is not really a difference in the above code if glEnable is moved there.
    I would recommend to always set values and then enable things, this avoids some pitfalls.

    Of course wireframes alone are depth tested against each other but you can look through the interior of faces. To remove hidden lines in a 3D drawing with depth test you need to draw something into the faces occluding them.
    The standard method is (from top of my head, not compiled):

    Draw the model shaded into the depth buffer first fo get occluders:
    glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
    glPolygonOffset(1.0f, 1.0f); // Move shaded back (in screen space depth).
    glEnable(GL_POLYGON_OFFSET_FILL);
    glColorMask(GL_FALSE, GL_FALSE, GL_FALSE, GL_FALSE);
    glDepthFunc(GL_LESS); // default;
    glEnable(GL_DEPTH_TEST);
    DrawScene();
    Draw depth tested wireframes on top of that, only the frontmost remain.
    glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
    glDisable(GL_POLYGON_OFFSET_FILL);
    glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE);
    DrawScene();

    This is probably a little different than using lines. Polygon offset is only working with polygonal geometry (all OpenGL primitives except GL_POINTS, GL_LINES, GL_LINE_STRIP, GL_LINE_LOOP). To get correct results you should not use it mixing lines and polygons, but only with switching polygon mode.
    But the idea is the same. Experiment.


    [This message has been edited by Relic (edited 08-12-2003).]

  4. #4
    Junior Member Newbie
    Join Date
    Aug 2003
    Location
    Waterloo, Ontario, Canada
    Posts
    10

    Re: Depth buffer test

    glClearDepth(1.0) doesn't actually clear the depth buffer, but sets the clear value for the depth buffer. You must also call glClear(GL_COLOR_BUFFER | GL_DEPTH_BUFFER) to clear the depth buffer. From the code snippet you gave, it isn't clear whether you are doing this.
    Rob Targosz
    McAfee Canada, Inc.

Similar Threads

  1. Depth buffer / depth test question
    By openglbeginner123 in forum OpenGL: Basic Coding
    Replies: 1
    Last Post: 12-14-2014, 05:13 PM
  2. Framebuffer depth test with depth and stencil buffer
    By moldyviolinist in forum OpenGL: Basic Coding
    Replies: 10
    Last Post: 07-29-2013, 08:21 PM
  3. Depth buffer reading and depth buffer test
    By BurningLegion in forum OpenGL: Basic Coding
    Replies: 0
    Last Post: 03-15-2007, 04:09 AM
  4. 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
  5. Depth buffer and stencil buffer / Alpha test
    By greg2 in forum OpenGL: Basic Coding
    Replies: 5
    Last Post: 08-05-2004, 01:50 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