NSOpenGLView类具有一个读/写属性openGLContext,在我阅读文档时,getter不应该返回零:
如果接收方没有关联的上下文对象,则创建一个新的
NSOpenGLContext对象。使用接收器的像素格式信息初始化新对象。
在macOS 10.13上,这似乎是正确的,但在macOS 10.9上,在我将视图添加到窗口后返回零。也就是说,如果我这样做:
NSOpenGLView* glView = [[NSOpenGLView alloc]
initWithFrame: NSMakeRect( 0.0, 0.0, 100.0, 100.0 )
pixelFormat: [NSOpenGLView defaultPixelFormat]];
NSLog(@"Pixel format %@, context %@", glView.pixelFormat, glView.openGLContext );
[self.host addSubview: glView];
NSLog(@"Pixel format %@, context %@", glView.pixelFormat, glView.openGLContext );然后在第二个日志中,上下文为零。有什么解决办法吗?创建我自己的NSOpenGLContext并分配它是没有帮助的。我已经验证了主机视图是窗口的一部分,并且windowNumber是正数。
发布于 2019-02-27 01:24:06
显然,在小牛中,必须设置上下文的视图以及视图的上下文。像这样的东西起作用了:
NSOpenGLPixelFormat* pf = [NSOpenGLView defaultPixelFormat];
NSOpenGLView* glView = [[[NSOpenGLView alloc]
initWithFrame: NSMakeRect( 0.0, 0.0, 100.0, 100.0 )
pixelFormat: pf] autorelease];
NSOpenGLContext* glc = [[[NSOpenGLContext alloc]
initWithFormat: glView.pixelFormat shareContext: nil] autorelease];
[self.host addSubview: glView];
glc.view = glView; // the key step I was missing
glView.openGLContext = glc;
NSLog(@"Pixel format %@, context %@", glView.pixelFormat, glView.openGLContext );https://stackoverflow.com/questions/54891914
复制相似问题