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 3 of 3

Thread: Automatic hidden surface removal?

  1. #1
    Junior Member Newbie
    Join Date
    Apr 2008
    Posts
    2

    Automatic hidden surface removal?

    I have written a program that converts Bevier patches into 3-d GL_POLYGON objects (eg. 32 Bezier patches to draw a teapot which is comprised of a few thousand triangles).

    Unfortunately the patches that are drawn last appear in front of the rest. This makes some interior sections of my teapot appear when they're supposed to be hidden.

    Is there some automatic way to hide triangles which should not be shown? If not, what's the easiest way to do so that's not absurdly inefficient?

    Thanks for the help!

  2. #2
    Super Moderator OpenGL Guru
    Join Date
    Feb 2000
    Location
    Montreal, Canada
    Posts
    4,421

    Re: Automatic hidden surface removal?

    The z-buffer should take care of that.

    glEnable(GL_DEPTH_TEST);
    glDepthFunc(GL_LEQUAL);//less or equal

    I beleive it is disabled by default when you make a GL context.
    ------------------------------
    Sig: http://glhlib.sourceforge.net
    an open source GLU replacement library. Much more modern than GLU.
    float matrix[16], inverse_matrix[16];
    glhLoadIdentityf2(matrix);
    glhTranslatef2(matrix, 0.0, 0.0, 5.0);
    glhRotateAboutXf2(matrix, angleInRadians);
    glhScalef2(matrix, 1.0, 1.0, -1.0);
    glhQuickInvertMatrixf2(matrix, inverse_matrix);
    glUniformMatrix4fv(uniformLocation1, 1, FALSE, matrix);
    glUniformMatrix4fv(uniformLocation2, 1, FALSE, inverse_matrix);

  3. #3
    Junior Member Regular Contributor
    Join Date
    Oct 2002
    Location
    San Diego, CA, USA
    Posts
    211

    Re: Automatic hidden surface removal?

    Also, backfaced polygons should be removed. If the depth buffer isn't helping you, your polygons might be wound backwards, causing the far side of the teapot to show and not the near side.

Posting Permissions

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