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: Depth test problem

Hybrid View

  1. #1
    Junior Member Newbie
    Join Date
    Oct 2011
    Posts
    21

    Depth test problem

    Im trying to draw a few things then switch to OrthoMode and draw a background. The problem is that the background hides the objects that I drew in normal mode.

    I found someone having the same problem but that answer didnt help me.

    -----------
    http://www.opengl.org/discussion_boa...p;Number=27634

    "I think the values for z near and z far are in terms of the projection/camera's (which specifically is one of the things i'm not sure of) z axis.

    Also, with a 3D projection (this might apply to ortho too, I can see no reason why it wouldn't in fact, but again, i'm not sure), you look down the negative Z axis, by default.

    So, if the projection/camera's z axis has a negative Z component, and you're looking down the negative z axis, then a positive value of zfar is going to produce a negative vaule in world space coordinates, which, if your vertices are also in world space coordinates, will result in negative vertex z values being visible (all else being equal)."
    -----------

    I have depth test enabled in both modes. I dont use glRotate.
    I do use glTranslate( 0, 0, -5) so the stuff i draw with 0.0 z coordinates will be visible, ...but the background has -100 z value so it shouldnt make any difference.

    I switch to ortho with:
    glOrtho(0.0, 1.0, 0.0, 1.0 / mouse->getAspectRatio(), 1.0, 500.0);

    The "normal mode" was set up with:
    gluPerspective(perspective_angle_vert, aspect_ratio, 0.1f, 200.0f);

  2. #2
    Junior Member Regular Contributor Kopelrativ's Avatar
    Join Date
    Apr 2011
    Posts
    212

    Re: Depth test problem

    I am doing as follows for my skybox (drawn last):
    Code :
    		glDepthRange(1, 1); // This will move the sky box to the far plane, exactly
    		glDepthFunc(GL_LEQUAL); // Seems to be needed, or depth value 1.0 will not be shown.

    Maybe it can help you.

  3. #3
    Junior Member Newbie
    Join Date
    Oct 2011
    Posts
    21

    Re: Depth test problem

    Thanks! It worked(glDepthRange(1, 1)) except that Im doing parralax scrolling with more layers and now it draws them according to the drawing sequence.

    ("Seems to be needed" ...I like theese kind of comments

Posting Permissions

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