question on opengl
question on opengl
- Subject: question on opengl
- From: Alex Golovinsky <email@hidden>
- Date: Wed, 1 Aug 2001 14:44:43 -0400
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