View Full Version : Newbie - depth test not working - probably me
03-23-2005, 04:13 AM
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
'Hidden face removal
glClear GL_COLOR_BUFFER_BIT Or GL_DEPTH_BUFFER_BIT Or GL_STENCIL_BUFFER_BIT
'Now display a black wireframe
glPolygonMode faceFront, pgmLine
glRotatef angleY, 0.1, 0#, 0#
glRotatef angleX, 0#, 0.1, 0#
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.
03-23-2005, 04:40 AM
Thanks for the reply
An image can be seen @
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
03-23-2005, 04:58 AM
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:
glColor3f(0., 0., 0.);
// DRAW YOUR STUFF
glColor3f(1., 1., 1.);
// DRAW YOUR STUFF AGAINthis 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.
03-23-2005, 05:09 AM
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 :-)
03-23-2005, 06:20 AM
hm. can you update the screenshot?
03-24-2005, 02:05 AM
Thanks again guys
here is the rendered image
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 ???
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)
03-24-2005, 03:04 AM
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.
03-24-2005, 03:14 AM
I'm almost there
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?
03-24-2005, 03:20 AM
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 :-) )
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
Powered by vBulletin® Version 4.2.2 Copyright © 2014 vBulletin Solutions, Inc. All rights reserved.