Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Page 1 of 2 12 LastLast
Results 1 to 10 of 16

Thread: Depth Testing Issue?

  1. #1
    Junior Member Newbie
    Join Date
    Oct 2014
    Posts
    10

    Depth Testing Issue?

    Hi Everyone,

    This is my first post on the forums. I'm having what I believe to be some depth-test related issues? For example, in the first image you can see through the nearest wall to the furthest one behind it. This can also be seen in the second image? I know a common mistake can be forgetting "GL_DEPTH_BUFFER_BIT" when calling glClear but I've double checked and the flag is indeed set.

    Any help with this would be much appreciated.

    Image 1:
    Click image for larger version. 

Name:	RenderingBug0-0.jpg 
Views:	137 
Size:	14.3 KB 
ID:	1470

    Image 2:
    Click image for larger version. 

Name:	RenderingBug0-1.jpg 
Views:	141 
Size:	8.8 KB 
ID:	1471

  2. #2
    Junior Member Newbie
    Join Date
    Jan 2013
    Posts
    11
    Hum, this looks like the bug I have been stuck with for the last 3 days: A whitish overlay coming from nowhere. In my case, it looks like an uninitialized 2nd texture superimposed. I am also getting the bands like on your 1st shot in the back. The catch is I am only using one texture stage. And you?
    If the checkerboard we sort of see on the floor and ceiling is part of your intended texture with the right spacing, then I'd say you also have something superimposed. Is it consistent? In my case the ghost texture will vary from plain white to snow, to a random image based on what I have run before. I describe it in the previous thread with the shader and a few routines I use.

  3. #3
    Junior Member Newbie
    Join Date
    Oct 2014
    Posts
    10
    Hey, thanks for the reply. I don't think my issue is with texturing, I believe it's more a depth issue since the farthest wall is visible instead of the nearest wall. Similarly, in the second picture, faces/polygons which shouldn't be visible are visible. Have added a third image, this one is more of a close-up of the second.

    Click image for larger version. 

Name:	RenderingBug0-2.jpg 
Views:	134 
Size:	10.8 KB 
ID:	1472

  4. #4
    Junior Member Newbie
    Join Date
    Jan 2013
    Posts
    11
    Oh I see the bands are where the wall should be. Then you are probably having a winding problem with your triangles not defined in the correct order ( clockwise vs counter clockwise).

    You can check if you are with
    glFrontFace( GL_CCW ); or glFrontFace( GL_CW);
    And do your triangles have the corresponding winding.

  5. #5
    Junior Member Newbie
    Join Date
    Oct 2014
    Posts
    10
    It's currently set to counter-clockwise, changing it to CW didn't do anything for it, I also tried disabling culling and the issue persists. You can see in the image below, where the dress is being drawn in favor of the hand (which is closer to the camera and no the camera is sufficiently far away so it's not just clipping through).

    Click image for larger version. 

Name:	RenderingBug0-3.jpg 
Views:	115 
Size:	6.5 KB 
ID:	1473

  6. #6
    Advanced Member Frequent Contributor
    Join Date
    Apr 2010
    Posts
    894
    Some things you may want to check:
    - do you request a depth buffer when creating your OpenGL context?
    - are near/far set to sensible values given the extents of your scene?
    - missing glEnable(GL_DEPTH_TEST)?
    - do you disable depth writes (glDepthMask(GL_FALSE))?
    - is your depth function glDepthFunc(GL_LESS) or glDepthFunc(GL_LEQUAL)?
    - is your projection matrix perhaps inverting the sign on the z axis?

  7. #7
    Junior Member Newbie
    Join Date
    Jan 2013
    Posts
    11
    Ok, it gets more precise.
    You are sure you have z writes enabled with : glDepthMask( GL_TRUE );
    and z tests also : glEnable( GL_DEPTH_TEST );

  8. #8
    Junior Member Regular Contributor
    Join Date
    Sep 2013
    Posts
    183
    You could test if your depth testing is initialized correctly by just drawing 2 lonely triangles over each other and see whether the correct one gets displayed.

  9. #9
    Junior Member Newbie
    Join Date
    Oct 2014
    Posts
    10
    Thanks for the replies guys, will start working through them and get back to you.

  10. #10
    Junior Member Newbie
    Join Date
    Oct 2014
    Posts
    10
    - do you request a depth buffer when creating your OpenGL context? -> Am using SFML which does allow you to specify the bits used for depth, I've set this to 24 at context creation.

    - are near/far set to sensible values given the extents of your scene? -> I didn't have these set before, have added: glDepthRange(0.f, 1.f);

    - missing glEnable(GL_DEPTH_TEST)? -> Nope, this was always present

    - do you disable depth writes (glDepthMask(GL_FALSE))? -> I didn't have a call to this either for true or false, have added glDepthMask(GL_TRUE) after the call to glEnable(GL_DEPTH_TEST)

    - is your depth function glDepthFunc(GL_LESS) or glDepthFunc(GL_LEQUAL)? -> Again, was not explicitly set, have tried both and neither really help

    - is your projection matrix perhaps inverting the sign on the z axis? -> I am inverting the vertex positions z component, I did this when loading obj files with DX11

    This image is with newly added depth settings:

    glEnable( GL_DEPTH_TEST );
    glDepthMask( GL_TRUE );
    glDepthFunc( GL_LEQUAL );
    glDepthRange(0.f, 1.f);

    Click image for larger version. 

Name:	RenderingBug0-4.jpg 
Views:	132 
Size:	7.3 KB 
ID:	1474

Posting Permissions

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