OpenGL 渲染顺序导致前景中的三角形在后台绘制
我正在一个世界中绘制三角形,三角形在背景中,但是当我走到它后面时,三角形并不在前景中(就像它应该的那样)。
我在 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
I am drawing my triangles in a world the triangles in the background but when I go behind it the triangle isn't in the foreground (like it should be).
I put a video on YouTube showing the problem here (make sure you read the description)
EDIT:
//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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您是否使用深度缓冲区创建了上下文?
您是否使用
glEnable(GL_DEPTH_TEST);
激活深度测试?您是否使用适当的
glDepthFunc
深度测试?Did you create your context with a depth buffer?
Did you activate depth testing with
glEnable(GL_DEPTH_TEST);
?Are you using an appropriate
glDepthFunc
depth test?