OpenGL 渲染顺序导致前景中的三角形在后台绘制

发布于 2024-12-15 04:52:40 字数 1141 浏览 0 评论 0原文

我正在一个世界中绘制三角形,三角形在背景中,但是当我走到它后面时,三角形并不在前景中(就像它应该的那样)。

我在 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

南巷近海 2024-12-22 04:52:40

您是否使用深度缓冲区创建了上下文?

您是否使用 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?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文