setting OpenGL version in objective-C

292 views Asked by At

I am writing in Objective-C for OS X. OpenGL defaults to version 2.1, I am trying to find out how to set it to 3.2 or higher.

I am not using GLFW, or QT, or SDL, or any other third-party framework, just what Apple and OpenGL provides. GLUT is OK though, but I'd prefer an Apple-ish native solution. My Mac is a brand new mini, which is theoretically capable of 4.1.

I am using a NSOpenGLView, and I just want my vertices in arrays, like modern OpenGL! I do not want to use SceneKit, but I am open to GLKitBaseEffect if it gives a solution, which I doubt.

One solution that comes up in searches is this:

NSOpenGLPixelFormatAttribute attrs[] =
{
  NSOpenGLPFADoubleBuffer,
  NSOpenGLPFADepthSize, 24,
  NSOpenGLPFAOpenGLProfile,
  NSOpenGLProfileVersion3_2Core,
  0
};

NSOpenGLPixelFormat* pf = [[NSOpenGLPixelFormat alloc] initWithAttributes:attrs];

NSOpenGLContext* oglc = [[NSOpenGLContext alloc] initWithFormat:pf shareContext:nil];
[self setOpenGLContext:oglc];
[oglc makeCurrentContext];

It does not work- it will not even create the view. I can only create the view with [NSOpenGLPixelFormat defaultPixelFormat], and I can find no way to start with the defaults and alter one of it's parameters before creating the view.

This "Works":

NSOpenGLPixelFormat* pf=[SculptView defaultPixelFormat];
 view=[[SculptView alloc] initWithFrame:(NSRect){0,0,768,1024} pixelFormat:pf];

but I'm stuck with OpenGL 2.1, with a bunch of glBegins and glEnds, and no arrays.

0

There are 0 answers