Question

I apologies in advance if this question will be trivial or a nonsense...this is one of the first app that I'm developing. (Unfortunatley) I'm not a developer.

I have a NSWindow which contains a custom View which is a subclass of NSOpenGLView.

Since the NSWindow and the NSOpenGLView are created through Interface Builder, I don't need to init neither NSOpenGLContext nor NSOpenGLPixelFormat.

I've recently switched to OS X Lion and I now want to leverage new OpenGL 3.2.

From Apple documentation I found out that to enable OpenGL 3.2 I simply need to write something like:

NSOpenGLPixelFormatAttribute pixelFormatAttributes[] =
    {
        NSOpenGLPFAOpenGLProfile, NSOpenGLProfileVersion3_2Core,
        0
    };

    NSOpenGLPixelFormat *pixelFormat = [[[NSOpenGLPixelFormat alloc] initWithAttributes:pixelFormatAttributes] autorelease];
    NSOpenGLContext* openGLContext = [[[NSOpenGLContext alloc] initWithFormat:pixelFormat shareContext:nil] autorelease];

before initializing the NSOpenGLContext.

This is quite easy (even for me), but how can I implement this in my app since I never init NSOpenGLContext?

Since the NSOpenGLView is created from Interface Builder, the method -initWithFormat:shareContext: doesn't get called.

Therefore I tried to override the -initWithCoder: method with something like this:

-(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];
}

and OpenGL 3.2 is correctly loaded as reported by glGetString(GL_VERSION) but the created Context is no longer interacting with the app...nothing is drawn in the view..

I tried everything I know of...but I'm not able to solve this.

How should I do instead?

Was it helpful?

Solution

Sounds your code is OpenGL 2.1 based. The OpenGL 3.2 in Lion only support the core profile (without compatibility profile), which means all fixed-function pipeline stuff (e.g. glBegin/End, glVertex, glPushMatrix, glMultMatrix) all have gone.

You have to update your code very much. The work will be less if you already use VBO.

OTHER TIPS

NSOpenGLView has a setOpenGLContext method. Pass your 3.2 context to the view that way, and call setView on the NSOpenGLContext afterwards.

I haven't tested this, but it should work, although I just made my own OpenGL View.

Using [setPixelFormat …] in my subclass's awakeFromNib is working for me, though it makes me uncomfortable because nothing in the docs promises it should.

This override's any settings from Interface Builder. I can't see a non-deprecated way to inspect a pixel format to add the ones I need to the ones selected in Interface Builder.

Hopefully the IB folks will add it there, or better yet the NSOpenGLView class will sprout a mechanism for subclasses to f

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top