What's the proper way to programmatically instantiate and add an OpenGL view to a window? I'm doing a simple GUI application but I'd like to create it programmatically so I can ask for Core 3.2 profile and fallback to 2.x if that's not available.
Looks like we're trying to figure out the same thing.
I've got a simple project where I just want a window with an NSOpenGLView covering the entire window contentView colored blue and a triangle displayed. The window displays, but I see no NSOpenGLView content.
I've got a simple project where I just want a window with an NSOpenGLView covering the entire window contentView colored blue and a triangle displayed. The window displays, but I see no NSOpenGLView content.
What's the proper way to programmatically instantiate and add an OpenGL view to a window? I'm doing a simple GUI application but I'd like to create it programmatically so I can ask for Core 3.2 profile and fallback to 2.x if that's not available.
Assuming you're setting up the 3.2 vs 2.x check via NSOpenGLPixelFormat, its initWithAttributes: will return nil if it can't initialize with the attributes given, so you could create a method to check for that and revert to 2.x settings if the 3.2 attributes fail.
An OpenGL view is an NSView, so it's added to a window just like any other view: create the window, create the OpenGL view, and set it as the window's content view, then show the window.
My problem isn't initializing OpenGL etc. - my problem is that I want to programmatically (in applicationDidFinishLaunching add an NSOpenGLView* to my window. I know how to alloc and init it with pixel format attributes, but now that I have this NSOpenGLView* and NSWindow*, how can I "insert" the view inside the window?