iDevGames Forums
bad depth sorting in Cocoa OpenGL - Printable Version

+- iDevGames Forums (http://www.idevgames.com/forums)
+-- Forum: Development Zone (/forum-3.html)
+--- Forum: Graphics & Audio Programming (/forum-9.html)
+--- Thread: bad depth sorting in Cocoa OpenGL (/thread-2118.html)



bad depth sorting in Cocoa OpenGL - aldermoore - Nov 22, 2008 01:53 PM

I am trying to convert the GLUTBasics example from MacDev to something more like the CocoaGL example which uses the NSOpenGL API. The object in the CocoaGL example is just a rotating cube. The object from GLUTBasics is a trefoil made up of thousands of triangles. I just copied over the code (and adjusted the camera attributes), and it displayed, but there seems to be a depth sorting problem. I've listed my pixel format below. When I don't include the NSOpenGLPFADepthSize attribute, the object totally self intersects as it rotates, almost like there's no depth sorting going on at all. When the attribute is included (and I've tried different values), it doesn't seem fluid any more, but parts of it still self-intersect as it rotates. I've tried enabling all kinds of stuff, but nothing helps. Any ideas about how to fix this?

NSOpenGLPixelFormatAttribute attributes [] = {
NSOpenGLPFAWindow,
NSOpenGLPFADoubleBuffer,
NSOpenGLPFASampleBuffers, 1,
NSOpenGLPFASamples, 4,
NSOpenGLPFANoRecovery,
NSOpenGLPFADepthSize, 24,
(NSOpenGLPixelFormatAttribute)nil
};


bad depth sorting in Cocoa OpenGL - donny - Dec 30, 2008 02:53 PM

What do you mean by "it doesn't seem fluid any more?"

Are you enabling depth testing?


bad depth sorting in Cocoa OpenGL - ThemsAllTook - Dec 30, 2008 03:07 PM

aldermoore Wrote:I just copied over the code (and adjusted the camera attributes)

What did you set your near and far clipping planes to? The lower the ratio of near:far, the less precision you get in your depth buffer. If you have it set to something extreme (like 0.00001:100000), you might be losing enough precision to make the depth buffer ineffective.