Results 1 to 7 of 7

Thread: Depth Test Problem

  1. #1
    Guest

    Depth Test Problem

    Hi,

    I'm rendering some object, which I rotate. However, when I enable the depth test and rotate, there's a lot of flickering and objects that should be behind the others aren't. I'm not sure if I'm doing something wrong or depth test is haphazard. Any suggestions are more than welcome.

    Thanks!

  2. #2
    Senior Member Regular Contributor
    Join Date
    Oct 2001
    Location
    Princeton, NJ
    Posts
    380

    Re: Depth Test Problem

    what are your near and far clipping planes, sounds like it might be a z-fighting issue

  3. #3
    Guest

    Re: Depth Test Problem

    I'm using gluPerspective with a Z near of 0.0 and a Z far of 100.0.

  4. #4
    Guest

    Re: Depth Test Problem

    Ok, I just changed my near to -1.0 and it worked! Thanks so much for the suggestion!

  5. #5
    Senior Member OpenGL Pro
    Join Date
    Jun 2000
    Location
    Shreveport, LA, USA
    Posts
    1,502

    Re: Depth Test Problem

    zNear really should be greater than 0.

  6. #6
    Guest

    Re: Depth Test Problem

    Yeah, I that's what I thought too, but it didn't work when I put a positive number...I wasn't able to see anything in the window. I tried adjusting glLookAt, but that didnt' seem to work. Do you have any suggestions? Thanks!

  7. #7
    Junior Member Newbie
    Join Date
    Mar 2002
    Location
    UK
    Posts
    27

    Re: Depth Test Problem

    If you use a negative zNear your going to cause yourself problems, it should be set >0. In your case try a value of 1. The negative value of your near clipping plane may have caused you to see things that are actually behind you or other strange artifacts. Make sure that you draw objects at some distance into the screen ie. at a negative z coordinate, or you won't see anything.

    [geek]
    Assuming the near and far clipping planes correspond to 0 and 1 in the depth buffer then the relation from eye to screen is:
    Code :
              1 f+n    1   2fn     1
    Zval =  -.--- + -.------ + -
              2 f-n    2 z(f-n)    2
    where Zval is the value in the z-buffer and z is the real-world depth.
    Taking your value of 100 for the far clipping plane and solving for both 1 and -1 near clipping planes you get:

    znear = 1, Zval = 1 + 1/z
    znear = -1, Zval = 1 - 1/z

    Thus for real-world z values which are positive that is behind you, Zval is [0,1] for the znear of -1 and [-1,0] for znear 1. But Zval MUST be in the range [0,1]. So here the objects behind you get drawn, but things maybe distorted because the depth buffer is not linear and the negative clipping plane will do funny things to the z buffer equations. Hence silly flickering and other artifacts.
    [/geek]

    EDIT: Equation got messed up - sorted


    [This message has been edited by thelamberto (edited 08-14-2002).]
    ----------------------------
    Anthony Clare
    School of Engineering
    Cranfield University

Similar Threads

  1. Depth test problem.
    By Dregel in forum OpenGL: Basic Coding
    Replies: 5
    Last Post: 08-09-2017, 12:05 AM
  2. Depth test problem
    By Aliii in forum OpenGL: Basic Coding
    Replies: 2
    Last Post: 02-19-2012, 07:37 AM
  3. Depth Test Problem
    By glfreak in forum OpenGL: Advanced Coding
    Replies: 9
    Last Post: 02-24-2008, 06:29 PM
  4. Problem with Depth test
    By suponlyzx in forum OpenGL: Basic Coding
    Replies: 2
    Last Post: 10-20-2005, 01:24 AM
  5. Depth Test Problem
    By Chris Brown in forum OpenGL: Basic Coding
    Replies: 1
    Last Post: 04-30-2001, 10:28 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