|
|
GL Depth Testing
|
|
|
|
Admin Emeritus
Join Date: Oct 2000
Location: Boston, MA
Status:
Offline
|
|
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)
|
|
|
|
|
|
|
|
Junior Member
Join Date: Mar 2001
Status:
Offline
|
|
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
|
|
|
|
|
|
|
|
|
Mac Enthusiast
Join Date: Jan 2001
Status:
Offline
|
|
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
|
|
|
|
|
|
|
|
|
Admin Emeritus
Join Date: Oct 2000
Location: Boston, MA
Status:
Offline
|
|
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)
|
|
|
|
|
|
|
|
Fresh-Faced Recruit
Join Date: Feb 2001
Location: OR
Status:
Offline
|
|
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).]
|
|
|
|
|
|
|
|
|
Fresh-Faced Recruit
Join Date: Feb 2001
Location: OR
Status:
Offline
|
|
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
|
|
|
|
|
|
|
|
|
Admin Emeritus
Join Date: Oct 2000
Location: Boston, MA
Status:
Offline
|
|
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)
|
|
|
|
|
|
|
|
Dedicated MacNNer
Join Date: Jun 2000
Location: Dundas, Ontario, Canada
Status:
Offline
|
|
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.
|
|
|
|
|
|
|
|
|
Dedicated MacNNer
Join Date: Aug 2001
Location: Seattle, WA
Status:
Offline
|
|
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 ]
|
|
|
|
|
|
|
|
|
Dedicated MacNNer
Join Date: Aug 2001
Location: Seattle, WA
Status:
Offline
|
|
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.
|
|
|
|
|
|
|
|
|
Dedicated MacNNer
Join Date: Jun 2000
Location: Dundas, Ontario, Canada
Status:
Offline
|
|
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.
|
|
|
|
|
|
|
|
|
Dedicated MacNNer
Join Date: Jun 2000
Location: Dundas, Ontario, Canada
Status:
Offline
|
|
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.
|
|
|
|
|
|
|
|
|
Admin Emeritus
Join Date: Oct 2000
Location: Boston, MA
Status:
Offline
|
|
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 Rules
|
|
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
|
HTML code is Off
|
|
|
|
|
|
|
|
|
|
|
|