gpt4 book ai didi

macos - NSOpenGLView 子类不随窗口调整大小

转载 作者:行者123 更新时间:2023-12-03 16:21:15 27 4
gpt4 key购买 nike

我一直在尝试让 NSOpenGLView 在调整窗口大小时正确调整大小,但我不断收到无法解释的奇怪行为。看起来像这样:

原始(一开始的样子):

调整大小后:

这是我的调整大小代码:

- (void)reshape
{
[super reshape];

CGLLockContext([[self openGLContext] CGLContextObj]);

NSRect viewRectPoints = [self bounds];

#if SUPPORT_RETINA_RESOLUTION

NSRect viewRectPixels = [self convertRectToBacking:viewRectPoints];

#else //if !SUPPORT_RETINA_RESOLUTION

NSRect viewRectPixels = viewRectPoints;

#endif // !SUPPORT_RETINA_RESOLUTION

[self resizeWithWidth:viewRectPixels.size.width
AndHeight:viewRectPixels.size.height];

CGLUnlockContext([[self openGLContext] CGLContextObj]);
}

- (void) resizeWithWidth:(GLuint)width AndHeight:(GLuint)height
{
glViewport(0, 0, width, height);

m_width = width;
m_height = height;
}

我正在使用:“glViewport(0, 0, m_width, m_height);”每当我调用 glDrawArrays();

有人可以帮忙吗?

最佳答案

调整窗口大小时,您还应该设置投影矩阵以反射(reflect)新尺寸。您没有发布设置/绘图代码,但通常看起来像这样:

glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(...); // or glFrustum(), glOrtho(), gluOrtho2D(), ...
glMatrixMode(GL_MODELVIEW);

关于macos - NSOpenGLView 子类不随窗口调整大小,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29292256/

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