Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Results 1 to 5 of 5

Thread: How to use the depth buffer?

  1. #1
    Guest

    How to use the depth buffer?

    Hello,

    I wrote a programm with a few triangles rotating around a point. I want hidden triangles(trinagles which are obscured by triangles in front of them) to be removed. I tried to use the depth buffer to do this, but when I enable
    GL_DEPTH_TEST, my triangles all start to flicker and the screen output looks rather strange. My code looks something like that(I am using glut):
    //Start of Pseudo-Code
    glutInitDisplayMode(GLUT_RGB|GLUT_DOUBLE|GLUT_DEPT H);
    //...
    glEnable(GL_DEPTH_TEST);
    //...
    glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
    Draw_the_triangles();
    glutSwapBuffers();
    //End of Pseudo-Code

    I hope anyone can help.

    Thanks,
    Martin

  2. #2
    Intern Contributor
    Join Date
    Jan 2001
    Location
    Irving TX USA
    Posts
    58

    Re: How to use the depth buffer?

    I encountered this problem when I had glEnable(GL_DEPTH_TEST) inside my Render() function once. When I moved it to an Initialize() function that was only called once it smoothed out my framerate considerably.

    There might be other things you only need to call once.

    Hope this helps

  3. #3
    Intern Contributor
    Join Date
    Mar 2004
    Posts
    62

    Re: How to use the depth buffer?

    Make sure VSync is enabled otherwise you will see a lot of tearing/flicker for just a couple of polygons.

    I always have vsync turned on except when I want to benchmark stuff.

  4. #4
    Guest

    Re: How to use the depth buffer?

    I am only calling glEnable(GL_DEPTH_TEST)once.
    I copied my display() code into my own engine code (not yet very sophisticated)and it works perfectly!? Altough it works now, it would be interesting to know why it had not worked with GLUT.

  5. #5
    Advanced Member Frequent Contributor
    Join Date
    Apr 2003
    Posts
    680

    Re: How to use the depth buffer?

    you need to:

    - enable depth test
    - specify a proper depth function
    - clear the depth buffer as well when clearing the framebuffer
    - and do so every frame before drawing.

    then it should work.

    Jan

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •