3

在调整窗口大小时,我一直试图让 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();

任何人都可以帮忙吗?

4

2 回答 2

1

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

glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(...); // or glFrustum(), glOrtho(), gluOrtho2D(), ...
glMatrixMode(GL_MODELVIEW);
于 2015-04-04T16:39:15.647 回答
0

说真的,在这些日子里,你可能想考虑离开NSOpenGLView并直接搬到那里CAOpenGLLayer

我在这个愚蠢的课程上遇到了太多问题,无法再打扰NSOpenGLView图层支持的视图,尤其是CAOpenGLLayer恕我直言,它只会为您提供更大的灵活性和控制力。
(和更少的错误 - 尝试NSOpenGLView在 10.9 或之前的层支持的视图层次结构中工作。)。

加上更多开箱即用的功能 - 或者至少在您的指尖下(如内置CVDisplayLink支持)。

只是我的2c。

于 2015-08-28T18:29:21.330 回答