Ok, so I just started out with OpenGL and (suprisingly) got it pretty much working right off the bat with the help of a few tutorials and such.
Anyway, what I’ve done so far is load in an OBJ file exported from 3DSMax with a few meshes inside, loaded the meshes, and rendered them, and rotated the scene around a bit. This worked fine, no probs… except that everything was one color and I couldn’t see anything but silhouettes…
Now I’ve added in some light to better see everything, and I’m noticing that I can VERY clearly see objects being drawn that are behind other objects. For example, seeing the innards of that teapot… seeing a sphere behind a cube… stuff like that…
What am I doing wrong as far as the ZBuffer goes? I’m writing this in GLUT and the only few mentions I have about the Depth buffer are the following:
The problem is most likly with your gluPerspective or glOrtho or whatever call that you use to set up the view frustrum.
The Z buffer is not linear but rather exponential when it’s determining percission at certain depths. So up close it’s super percise and far away it’s bad.
The way to fix this is to put you’re near view plane as far away from you as possible and you’re far plane as near to you as possible.
I#ve got a similar problem some time ago. I used something like “0.5f” as the near clipping plane (i.e. using GluPerspective). Try greater values like “1.5f” or so.
Hmm … I tried my code in another simple OpenGL prog I made, and it seems the z buffer works fine…
See, I made two versions (I need OpenGL in a window)… one in a Win32 window, and one using GLUT.
The Win32 one works fine when loading the models and all … just need to play with the light a bit to see the differences
But on the GLUT one I can see the polygons bleeding through each other, and I’m not sure how to fix this …
My best guess is that during the initialization I set the Z buffer to 16 bit in the pixel format descriptor …
In GLUT I have no idea what it is nor how to change it.
Apart from the window creation, the initialization (glPerspective, etc) looks identical …
My glPerspective is as such:
gluPerspective(60.0f,(GLfloat)width/(GLfloat)height,20.0f,500.0f);
Now this is in the GLUT version, in the Win32 one the last parameter is 1000.0f and I have no problem with that one (no triangle bleeding or anything)…
Also … a.f.a. the cull settings are concerned… cough … I have no idea?