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

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.

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

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:

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.

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 :slight_smile:

Julian

hm. can you update the screenshot?

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 :slight_smile:

When I can get it working of course :slight_smile:

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

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)

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.

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

Thanks for the tips on the books…

I like the idea of a single reference with all the functions (Blue)

I found links to the functions in html but I like to have something I can flick through (whilst watching tv etc :slight_smile: )

Looks like its blue and red !

Most of my stuff to date has been from a book called “OpenGL SuperBible” bought for £5 from our local market — its turning out to be a bargain