gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-03 18:00:04 24 4
gpt4 key购买 nike

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

我在 YouTube 上发布了一段显示该问题的视频 here (请务必阅读说明)

编辑:

//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

最佳答案

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

您是否使用 glEnable(GL_DEPTH_TEST); 激活深度测试?

您是否使用适当的 glDepthFunc 深度测试?

关于cocoa - OpenGL 渲染顺序导致前景中的三角形在后台绘制,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8115897/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com