Welcome to the MacNN Forums.

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

You are here: MacNN Forums > Software - Troubleshooting and Discussion > Developer Center > GL Depth Testing

GL Depth Testing
Thread Tools
parallax
Admin Emeritus
Join Date: Oct 2000
Location: Boston, MA
Status: Offline
Reply With Quote
Feb 23, 2001, 11:57 AM
 
I can't get depth testing to work in OpenGL. The stuff that's drawn later is the stuff that appears in front. I used glEnable(whatever the depth testing is) and glDepthFunc(GL_LESS). It still doesn't work.
"Against stupidity, the gods themselves contend in vain" (Schiller)
     
Wixar
Junior Member
Join Date: Mar 2001
Status: Offline
Reply With Quote
Mar 5, 2001, 04:49 PM
 
How are you setting up your NSOpenGLView? (Or are you using something other than NSOpenGLView, like GLUT, or some Core Graphics stuff?)

Does glGetError() return anything?

-Peter
     
00101001
Mac Enthusiast
Join Date: Jan 2001
Status: Offline
Reply With Quote
Mar 6, 2001, 12:20 AM
 
check out http://nehe.gamedev.net/opengl.asp
download some of the OSX ported examples, all his code uses depth testing and works great, maybe you can figure it out from there
     
parallax  (op)
Admin Emeritus
Join Date: Oct 2000
Location: Boston, MA
Status: Offline
Reply With Quote
Mar 6, 2001, 11:08 AM
 
I got most of the code from nehe anyways, but I'll try to check that out.
"Against stupidity, the gods themselves contend in vain" (Schiller)
     
Ryan Bates
Fresh-Faced Recruit
Join Date: Feb 2001
Location: OR
Status: Offline
Reply With Quote
Mar 6, 2001, 05:45 PM
 
That's very strange, half of my message got cut off. Here's the first half again:

I encountered the same problem with the depth buffer, I'm guessing you are programming in Cocoa. The problem actually is with the setup of the NSOpenGLView. In Interface Builder you can set the depth buffer of an NSOpenGLView in the attributes section, however I found this doesn't work very well. Here's what I would suggest doing:

In IB, create a "CustomView" then create a subclass of NSOpenGLView. Set the custom view to that subclass in the attributes. In the code of the new view, include this in the initialize method.

Code:
- (id)initWithFrame:(NSRect)frameRect { NSOpenGLPixelFormatAttribute attribs[] = { NSOpenGLPFAAllRenderers, NSOpenGLPFADoubleBuffer, NSOpenGLPFADepthSize, 16, 0 }; NSOpenGLPixelFormat *format = [[NSOpenGLPixelFormat alloc] initWithAttributes:attribs]; self = [super initWithFrame:frameRect pixelFormat:format]; return self; }
To give credit where it's due, I got these pixel attribute settings from the epicware screen savers: http://www.epicware.com/macosxsavers.html

Well I hope that works for you; let me know via email if you would like an example app of this. Good luck.

Ryan

[This message has been edited by Ryan Bates (edited 03-06-2001).]
     
Ryan Bates
Fresh-Faced Recruit
Join Date: Feb 2001
Location: OR
Status: Offline
Reply With Quote
Mar 7, 2001, 01:20 AM
 
One more thing, make sure you are calling glEnable(GL_DEPTH_TEST) on every frame of the animation, not just at the start. For some reason it doesn't stay if you just call it once. Let me know if you get it to work.

Ryan
     
parallax  (op)
Admin Emeritus
Join Date: Oct 2000
Location: Boston, MA
Status: Offline
Reply With Quote
Mar 7, 2001, 08:28 AM
 
Hmmm... It still doesn't seem to be working.

I'm sick of GL for a while, so that works well :-)
"Against stupidity, the gods themselves contend in vain" (Schiller)
     
Apocalypse
Dedicated MacNNer
Join Date: Jun 2000
Location: Dundas, Ontario, Canada
Status: Offline
Reply With Quote
Aug 31, 2001, 03:16 AM
 
Parallax, did you ever end up resolving this problem? I am having the same problem right now and I am stumped.

If anyone has resolved the issue can you drop me a line here?

Thanks,
Jeff.
Spectral Class
"Shedding Light on Innovation"
     
Tim2 at Omni
Dedicated MacNNer
Join Date: Aug 2001
Location: Seattle, WA
Status: Offline
Reply With Quote
Aug 31, 2001, 04:48 AM
 
If all else fails, check to see that you're doing your perspective and modelview transformations correctly. If you have object A obscuring object B from one angle, object B will obscure object A from the opposite angle. So maybe the "camera" just isn't where you think it is :-)

[ 08-31-2001: Message edited by: Tim2 at Omni ]
Tim Omernick
Engineer, The Omni Group
     
Tim2 at Omni
Dedicated MacNNer
Join Date: Aug 2001
Location: Seattle, WA
Status: Offline
Reply With Quote
Aug 31, 2001, 04:50 AM
 
Also, I've found NSOpenGLView to be a bit flaky. You might want to just use an NSView and bind an NSOpenGLContext to it, using pixel format attributes like those described in a previous post.
Tim Omernick
Engineer, The Omni Group
     
Apocalypse
Dedicated MacNNer
Join Date: Jun 2000
Location: Dundas, Ontario, Canada
Status: Offline
Reply With Quote
Aug 31, 2001, 10:55 AM
 
I did try doing what they do above and to initialize the pixel attributes. I always do my views this way since I don't know how to work with them without sub-classing. The other mention of point of view probably wouldn't do it either. The problem I am having is with an "orbiting" effect over the game board. Everything looks fine for exactly 50% of the frames. For the rest, the back pieces float "through" the foremost ones.
I though that something like this might be the problem but the depth function explanations I have found claim that the function is used on the existing pixel's z value vs. the new pixel's z value. After all is said and done (that being all projection and modelview matrix stacks have been calculated) that should imply that everything looks fine.
I am actually thinking that the depth buffer is not being enabled since the changing of the depth function from GL_NEVER to GL_ALWAYS should have some effect on the scene even if it isn't the one that I want. However, no matter what I set the function to I get exactly the same results.

Any other ideas?
Jeff.
Spectral Class
"Shedding Light on Innovation"
     
Apocalypse
Dedicated MacNNer
Join Date: Jun 2000
Location: Dundas, Ontario, Canada
Status: Offline
Reply With Quote
Aug 31, 2001, 10:59 AM
 
Never mind. I fixed the problem by using the options defined in IB. Apparently the "Maximum" setting for depth buffer on NSOpenGLViews works really well.

Thanks for your help, though.
Jeff.
Spectral Class
"Shedding Light on Innovation"
     
parallax  (op)
Admin Emeritus
Join Date: Oct 2000
Location: Boston, MA
Status: Offline
Reply With Quote
Aug 31, 2001, 11:59 AM
 
Hah! That's exactly what happened to me. A while back, I went into IB to screw around with some things, and I realized there was a depth buffer setting.
"Against stupidity, the gods themselves contend in vain" (Schiller)
     
   
 
Forum Links
Forum Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Top
Privacy Policy
All times are GMT -4. The time now is 09:50 AM.
All contents of these forums © 1995-2017 MacNN. All rights reserved.
Branding + Design: www.gesamtbild.com
vBulletin v.3.8.8 © 2000-2017, Jelsoft Enterprises Ltd.,