Re: question on opengl
Re: question on opengl
- Subject: Re: question on opengl
- From: Eric Peyton <email@hidden>
- Date: Wed, 1 Aug 2001 16:16:34 -0500
I bet your attributes for the open gl view are incorrect.
When I am creating an opengl view I generally use the following
attributes ...
NSOpenGLPixelFormatAttribute attribs[] =
{ NSOpenGLPFAAccelerated,
NSOpenGLPFADepthSize, 16,
NSOpenGLPFAMinimumPolicy,
NSOpenGLPFAClosestPolicy,
0
};
NSOpenGLPixelFormat *format = [[[NSOpenGLPixelFormat alloc]
initWithAttributes:attribs] autorelease];
_view = [[[NSOpenGLView alloc] initWithFrame:NSZeroRect
pixelFormat:format] autorelease];
Since you are in a subclass, you should be able to set the pixel
format from inside your class using
- (void)setPixelFormat:(NSOpenGLPixelFormat*)pixelFormat;
Eric
On Wednesday, August 1, 2001, at 01:44 PM, Alex Golovinsky wrote:
Hi,
Here's a simple app that draws two squares, one in front of the
other, when a key is pressed. I've been knocking my head on this
for several days now: the depth test does NOT work. The red quad,
which is drawn first in order, does not get overdrawn by the black
quad despite the fact that the black quad is in the front and that
depth buffer testing is enabled. Can anyone see what's wrong with
this?
//controller is a subclass of NSOpenGLView
@implementation Controller
- (void)keyDown:(NSEvent *)event;
{
[self display];
}
- (void) applicationDidFinishLaunching: (NSNotification *) note;
{
width = [myGL frame].size.width;
height = [myGL frame].size.height;
[window setAcceptsMouseMovedEvents: YES];
[window makeFirstResponder: myGL];
glClearColor(1.0, 1.0, 1.0, 1.0);
glEnable(GL_DEPTH_TEST);
glViewport (0, 0, width, height);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(60, (float)width/height, 1.5, 20);
GL_INITIALIZED = YES;
}
- (void)drawRect:(NSRect)rect
{
if(GL_INITIALIZED){
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
gluLookAt(0, 0, 7, 0, 0, 0, 0, 1, 0);
glColor3f(0, 0, 0);
glBegin(GL_QUADS);
glVertex3f(-1, -1, 1);
glVertex3f(1, -1, 1);
glVertex3f(1, 1, 1);
glVertex3f(-1, 1, 1);
glEnd();
glColor3f(1, 0, 0);
glBegin(GL_QUADS);
glVertex3f(-1, -1, 0);
glVertex3f(1, -1, 0);
glVertex3f(1, 1, 0);
glVertex3f(-1, 1, 0);
glEnd();
glFlush();
}
}
@end
_______________________________________________
cocoa-dev mailing list
email@hidden
http://www.lists.apple.com/mailman/listinfo/cocoa-dev