如果这个问题很微不足道或者是无稽之谈,我很抱歉...这是我正在开发的第一个应用程序之一。 (Unfortunatley)我不是开发者。NSOpenGLView与OpenGL 3.2核心
我有一个NSWindow,其中包含一个自定义视图,它是NSOpenGLView
的子类。
由于NSWindow
和NSOpenGLView
通过Interface Builder中创建的,我不需要init
既不NSOpenGLContext
也不NSOpenGLPixelFormat
。
我最近切换到OS X Lion,现在我想要利用新的OpenGL 3.2。
从苹果的文档,我发现,要启用OpenGL 3.2我只需写类似:初始化NSOpenGLContext
前
NSOpenGLPixelFormatAttribute pixelFormatAttributes[] =
{
NSOpenGLPFAOpenGLProfile, NSOpenGLProfileVersion3_2Core,
0
};
NSOpenGLPixelFormat *pixelFormat = [[[NSOpenGLPixelFormat alloc] initWithAttributes:pixelFormatAttributes] autorelease];
NSOpenGLContext* openGLContext = [[[NSOpenGLContext alloc] initWithFormat:pixelFormat shareContext:nil] autorelease];
。
这是很容易的(甚至对我来说),但我怎么能实现这个在我的应用程序,因为我从来没有init
NSOpenGLContext
?
由于NSOpenGLView
是从Interface Builder创建的,所以方法-initWithFormat:shareContext:
不会被调用。
所以我试着像这样的东西覆盖-initWithCoder:
方法:
-(id)initWithCoder:(NSCoder *)aDecoder
{
NSOpenGLPixelFormatAttribute pixelFormatAttributes[] =
{
NSOpenGLPFAOpenGLProfile, NSOpenGLProfileVersion3_2Core,
0
};
NSOpenGLPixelFormat *pixelFormat = [[[NSOpenGLPixelFormat alloc] initWithAttributes:pixelFormatAttributes] autorelease];
NSOpenGLContext* openGLContext = [[[NSOpenGLContext alloc] initWithFormat:pixelFormat shareContext:nil] autorelease];
[super initWithCoder:aDecoder];
[self setOpenGLContext:openGLContext];
[openGLContext makeCurrentContext];
}
,并通过glGetString(GL_VERSION)
的报道,但在创建上下文不再与应用程序交互的OpenGL 3.2是否正确装入......没有什么是在视图中绘制..
我试过我所知道的一切......但我无法解决这个问题。
我应该怎么做呢?