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

Thread: Newbie - depth test not working - probably me

  1. #1
    Member Newbie
    Join Date
    Mar 2005
    Posts
    47

    Newbie - depth test not working - probably me

    Hi guys

    I am new to OGL and have hacked together some code to display a 3D poly model with scalar values at vertex points.

    Wow - OGL is great stuff.

    Anyway I cant get depth testing to work at the mo.

    The culling is working but I can "see" faces that should be hidden by depth testing.

    Am I missing something?

    Here is an incomplete code snippet (VB)

    Thanks for your time

    Julian

    ================================

    'Hidden face removal
    glEnable glcCullFace
    glEnable glcDepthTest


    Sub Render()

    glClear GL_COLOR_BUFFER_BIT Or GL_DEPTH_BUFFER_BIT Or GL_STENCIL_BUFFER_BIT

    'Now display a black wireframe
    glPolygonMode faceFront, pgmLine

    glPushMatrix
    glRotatef angleY, 0.1, 0#, 0#
    glRotatef angleX, 0#, 0.1, 0#
    glCallList triangl_list2
    glPopMatrix

    SwapBuffers pbOGL.hDC

    End Sub

  2. #2
    Senior Member Regular Contributor
    Join Date
    Aug 2003
    Posts
    369

    Re: Newbie - depth test not working - probably me

    I don't have much experience with Visual Basic, but the code looks right. Are you sure you're not seeing the faces you're not supposed to see, because some backface is culled (thus exposing what's behind it?) Can you post a screenshot?

    Hmm, now that I remember. When you create your window, are you requesting a depth buffer? Depending on the implementation, sometimes you get it without asking for it, but sometimes you don't, which could lead to this sort of problem.

  3. #3
    Member Newbie
    Join Date
    Mar 2005
    Posts
    47

    Re: Newbie - depth test not working - probably me

    Hi

    Thanks for the reply

    An image can be seen @

    www.cadfem.com/ogl.gif

    The colour pic is what it should look like.

    The wireframe is my first attempt.

    The culling seems to be working but if I comment out the depth line there is no difference.

    I may need to create a simple model and get my head round what is going on.

    Thanks for the input

    Julian

  4. #4
    Senior Member Frequent Contributor
    Join Date
    Aug 2004
    Location
    munich, germany
    Posts
    659

    Re: Newbie - depth test not working - probably me

    a-haaaaaa...so you want to display a hidden line view.

    if you set polygon mode to GL_LINE, you will always see lines that should actually not be seen. what you have to do is something like:

    Code :
    glEnable(GL_POLYGON_OFFSET_LINE);
    glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
    glPolygonOffset(0., -2000.);
    glColor3f(0., 0., 0.);
     
    // DRAW YOUR STUFF
     
    glDisable(GL_POLYGON_OFFSET_LINE);
    glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
    glColor3f(1., 1., 1.);
     
    // DRAW YOUR STUFF AGAIN
    this means you have to draw all elements twice. the first pass uses glPolygonOffset. if you don't use it, the edge lines will look broken or stippled.

  5. #5
    Member Newbie
    Join Date
    Mar 2005
    Posts
    47

    Re: Newbie - depth test not working - probably me

    Ah - right I see, thanks

    One thing though, if I set the polygons to fill - the image still seems odd.

    Anyway, you guys have given me stuff to look at and I thank you all for your time.

    Obviously I need to do a lot more reading

    Julian

  6. #6
    Senior Member Frequent Contributor
    Join Date
    Aug 2004
    Location
    munich, germany
    Posts
    659

    Re: Newbie - depth test not working - probably me

    hm. can you update the screenshot?

  7. #7
    Member Newbie
    Join Date
    Mar 2005
    Posts
    47

    Re: Newbie - depth test not working - probably me

    Hi

    Thanks again guys

    here is the rendered image

    www.cadfem.com\ogl2.gif

    This is the same view as before.

    You can see that the culling seems to be working but the depth stuff isn't

    Its encouraging that I am, basically, doing the right thing.

    I'm probably trying to run before I can walk soooooo, I will create a model of a cube and work on that.

    BTW you can see the stipple effect....

    I was going to offset the polygons by writing code to re-calculate the geometry.

    You are saying that you can do this automatically?

    This OGL API is brilliant stuff

    When I can get it working of course

    BTW2 I am assuming that I should be buying the "blue book" - yes ???

  8. #8
    Senior Member Regular Contributor
    Join Date
    Aug 2003
    Posts
    369

    Re: Newbie - depth test not working - probably me

    Actually the red book. The blue book contains only references for the functions (I haven't read it though, so don't take my word for it).
    The red book (which I have) contains code examples and numerous discussions on almost every aspect of OpenGL. This will help you more I think than the blue book.
    The reference for the functions you can either find it online by googling, MSDN or MESA (e.g. man glVertex)

  9. #9
    Senior Member Frequent Contributor
    Join Date
    Aug 2004
    Location
    munich, germany
    Posts
    659

    Re: Newbie - depth test not working - probably me

    i'd rather do without culling, for a start. i'm not convinced it is a depth test problem.

    yes, with glPolygonOffset ogl gives an offset to the lines automatically. not normal to an element plane, but in direction of the z-buffer. the first value is a variable offset depending on the element, the second value is a constant offset. maybe you have to play a bit to get what you want.

  10. #10
    Member Newbie
    Join Date
    Mar 2005
    Posts
    47

    Re: Newbie - depth test not working - probably me

    I'm almost there

    www.cadfem.com\ogl3.gif

    This image is an exact mirror of how it should look.

    The problem is something to do with the polygon ordering --- CW or CCW

    How do you guys cope with this sort of thing?

    Do you just ensure that your data is always ordered CCW prior to rendering or do you test for the ordering and set glFrontFace as appropriate?

    Interesting

Page 1 of 2 12 LastLast

Similar Threads

  1. FBO: depth is not stored, while the depth test is working
    By Goossen in forum OpenGL: Basic Coding
    Replies: 0
    Last Post: 12-29-2016, 08:55 AM
  2. Depth test for custom framebuffer not working
    By Blizzard_jedi in forum OpenGL: Basic Coding
    Replies: 6
    Last Post: 06-16-2014, 04:30 PM
  3. Depth test not working
    By esapir in forum OpenGL: Basic Coding
    Replies: 2
    Last Post: 02-28-2014, 12:52 PM
  4. Depth Test not working
    By AlbertoEAFerreira in forum OpenGL: Basic Coding
    Replies: 3
    Last Post: 12-19-2010, 02:12 PM
  5. Depth Test not Working
    By Colby Toland in forum OpenGL: Basic Coding
    Replies: 6
    Last Post: 08-05-2004, 01:59 PM

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