我在背景中繪製三角形的世界中的三角形,但是當我走到它後面時,三角形不在前景中(就像它應該是) 。OpenGL渲染順序導致前景中的三角形被繪製在背景中
我把顯示問題here(請務必閱讀說明)在YouTube上的視頻
編輯:
//create instance of camera class
mainCamera = [[Camera alloc]init];
//Tell window to log mouse events
[[self window] setAcceptsMouseMovedEvents:YES];
//Timer for updating frames
NSTimer *timer = [NSTimer scheduledTimerWithTimeInterval:1/30 target:self selector:@selector(redraw) userInfo:nil repeats:YES];
//keep timer running during event tracking
[[NSRunLoop currentRunLoop] addTimer:timer forMode:NSEventTrackingRunLoopMode];
[[NSRunLoop currentRunLoop] addTimer:timer forMode:NSModalPanelRunLoopMode];
glEnable(GL_DEPTH_TEST);
glClearDepth(1.0f);
glShadeModel(GL_SMOOTH);
glEnable(GL_LINE_SMOOTH);
glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
//self in this case is my view. The code below is getting the size of the view.
gluPerspective(45.0f, [self frame].size.width/[self frame].size.height, 1.0f, 1000.0f);
glMatrixMode(GL_MODELVIEW);
//creating triangle objects
我認爲這個紫色三角形在前景中,但是如果你改變了它,可能會更容易辨別。 –
@JamesBlack:不,我發現其他三角形正在繪製在它上面。深度測試 –