【问题标题】:NSOpenGLView subclass not resizing with windowNSOpenGLView 子类不随窗口调整大小
【发布时间】:2015-08-29 02:29:21
【问题描述】:

我一直在尝试让 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();

谁能帮忙?

【问题讨论】:

  • 你也可以发布你的drawRect函数吗?

标签: macos cocoa opengl nsopenglview


【解决方案1】:

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

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

【讨论】:

    【解决方案2】:

    说真的,这些天你可能想考虑离开NSOpenGLView,直接转到CAOpenGLLayer

    我在这个愚蠢的课程上遇到了太多问题,我不想再打扰 NSOpenGLView 和在图层支持的视图中,特别是拥有 CAOpenGLLayer 恕我直言,这只会给你更多的灵活性 - 和控制。
    (以及更少的错误 - 尝试让 NSOpenGLView 在 10.9 或之前的层支持的视图层次结构中工作。)。

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

    只是我的 2c。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2020-07-12
      • 2023-03-24
      • 1970-01-01
      • 1970-01-01
      • 2012-05-13
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多