Macos NSOpenGLView子类不随窗口调整大小
我一直在试图让NSOpenGLView在调整窗口大小时正确调整大小,但我一直有奇怪的行为,我无法解释。看起来是这样的: 原创(开头的样子): 调整大小后: 这是我的调整大小代码:Macos NSOpenGLView子类不随窗口调整大小,macos,cocoa,opengl,nsopenglview,Macos,Cocoa,Opengl,Nsopenglview,我一直在试图让NSOpenGLView在调整窗口大小时正确调整大小,但我一直有奇怪的行为,我无法解释。看起来是这样的: 原创(开头的样子): 调整大小后: 这是我的调整大小代码: - (void)reshape { [super reshape]; CGLLockContext([[self openGLContext] CGLContextObj]); NSRect viewRectPoints = [self bounds]; #if SUPPORT_RET
- (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;
}
每当我调用glDrawArrays()时,我都会使用:“glViewport(0,0,m_width,m_height);”
有人能帮忙吗?调整窗口大小时,还应设置投影矩阵以反映新尺寸。您没有发布设置/绘图代码,但通常看起来像:
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(...); // or glFrustum(), glOrtho(), gluOrtho2D(), ...
glMatrixMode(GL_MODELVIEW);
严重的是,在这些日子里,你可能要考虑离开<代码> NSopungLVIEW>代码>并直接移动。
对于这个愚蠢的类,我已经有太多的问题了,不必再为NSOpenGLView
和层备份视图操心了,尤其是在CAOpenGLLayer
IMHO中,它只会给你更多的灵活性和控制力。(并减少bug-尝试让
NSOpenGLView
在10.9或之前版本下的层备份视图层次结构中工作)
加上更多的开箱即用功能,或者至少在您的指尖下(如内置的CVDisplayLink
支持)
就我的2c。你也可以发布你的drawRect函数吗?