3

如果这个问题很微不足道或者是无稽之谈,我很抱歉...这是我正在开发的第一个应用程序之一。 (Unfortunatley)我不是开发者。NSOpenGLView与OpenGL 3.2核心

我有一个NSWindow,其中包含一个自定义视图,它是NSOpenGLView的子类。

由于NSWindowNSOpenGLView通过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]; 

这是很容易的(甚至对我来说),但我怎么能实现这个在我的应用程序,因为我从来没有initNSOpenGLContext

由于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是否正确装入......没有什么是在视图中绘制..

我试过我所知道的一切......但我无法解决这个问题。

我应该怎么做呢?

回答

1

听起来你的代码是基于OpenGL 2.1的。 Lion中的OpenGL 3.2只支持核心配置文件(没有兼容性配置文件),这意味着所有固定功能管道的东西(例如glBegin/End,glVertex,glPushMatrix,glMultMatrix)都已经没有了。

你必须非常更新你的代码。如果您已经使用VBO,工作将会减少。

4

NSOpenGLView有一个setOpenGLContext方法。然后将你的3.2上下文传递给视图,然后在NSOpenGLContext上调用setView。

我还没有测试过这个,但它应该工作,虽然我只是做了我自己的OpenGL视图。

0

在我的子类的awakeFromNib中使用[setPixelFormat ...]正在为我工​​作,虽然它让我感到不舒服,因为文档中没有任何东西承诺它应该。

此重写的界面生成器的任何设置。我看不到一种不被弃用的方式来检查像素格式,以便将我需要的像素格式添加到Interface Builder中选定的像素格式中。

希望IB的人会在那里添加它,或者更好的是NSOpenGLView类将为子类创建一个机制,以便于f