PDA

View Full Version : How to avoid influence of drawing order?



Theo Vosse
05-19-2005, 12:03 AM
Hi,

After a few years not using OpenGL, I've started again and encountered a probably very simple problem that has me completely stupified. I've reduced my scene to four non-overlapping cubes. Camera movement and object rotation seem to work well, but when rotating the scene 90 degrees clock-wise, the cubes that should be invisible can still be seen as if they were in front. When rotating it counter-clockwise, everything works fine.

All seems to depend on the drawing order (when changing that, the effect is fine under clockwise rotation, but not under counter-clockwise rotation).

For further testing, I made the program draw the edges of the cubes, and they are all visible as if the cube is transparent (which it isn't), but not when the cube gets obscured by another cube after rotation.

The depth buffer is enabled, and it gets cleared. I've even tried setting the normal vectors, but that didn't make any change (except for obscuring the whole thing when they were set wrong). What can I be doing wrong?

Thanks in advance,

Theo

RigidBody
05-19-2005, 12:30 AM
you may enable depth buffer, but are you sure you have one? in windows you have to set PFD_DOUBLEBUFFER in the pixelformatdescriptor, in linux GLX_DOUBLEBUFFER in the attribute list for glXChooseVisual.

Theo Vosse
05-19-2005, 12:54 AM
My God, you were right!

I'm working in XCode on a mac, and my OpenGL view had the depth buffer explicitly disabled (a feature of the interface builder).

Thanks!

RigidBody
05-19-2005, 01:09 AM
thank you for getting the right idea out of my post although i made a mistake :p

of course you need to set pfd.cDepthBits or GLX_DEPTH_SIZE instead of PFD_DOUBLEBUFFER/GLX_DOUBLEBUFFER