OpenGL 4.1(?) under Mavericks

17,787

Solution 1

When you request your pixel format using one of the lower-level APIs on OS X, you need to add the following to your attribute list in order to use a core profile:

CGL:

  kCGLPFAOpenGLProfile,     kCGLOGLPVersion_3_2_Core

NSOpenGL:

  NSOpenGLPFAOpenGLProfile, NSOpenGLProfileVersion3_2Core

Now, while the particular constant is named ...3_2Core, what it actually means is request a context that removes all deprecated features and supports at least OpenGL 3.2 (a core profile, in other words). You can get a 4.1 or 3.3 context using this same constant; in all honesty, including an actual version number in the constant was probably a poor choice.

If you do not specify this when you request your pixel format, OS X will give you kCGLOGLPVersion_Legacy or NSOpenGLProfileVersionLegacy respectively. And this will limit you to OpenGL 2.1 functionality.

If you are using a higher-level framework, then you will need to consult your API reference. However, be aware that on OS X you must have a core profile context to access anything newer than OpenGL 2.1.

Solution 2

Use the OpenGL library GLFW the latest version is 3.0.4... right after you initialize glfw init

if (!glfwInit())
{
    printf("glfwInit() fail to initualize. \n");
    glfwTerminate();
    exit(-1);
}

after you initialize glfwInit() include these 4 lines of code. these four line of code will enable you to use the highest version supported by you OS. on mac its opengl 4.1

glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE);
glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 2);

then create your window.

_Window = glfwCreateWindow(width, height, title, 0, 0);

check to make sure it was created.

if (!_Window) {
    printf("Display window fail to create. \n");
    glfwTerminate();
    exit(-1);
}

then make it you current window using the following.

glfwMakeContextCurrent(_Window);

after you make it your cureent window all thats left to be done is to create you main loop.

while (!glfwWindowShouldClose(_Window))
{
    ........
    glfwSwapBuffers(_Window);
    glfwPollEvents();
}

make sure you includ glfwPollEvents(); in the loop this makes it possible to use the close botton to quit the window. if you having trouble compiling the library in xcode just message me on here and i will send you a copy of the library.

Solution 3

I struggled a long time on this, and finally succeeded on using any glsl version supported by the graphics card.

There are several main points:

  1. Use CORE PROFILE
  2. Set the MAJOR.MINOR to version of GL you want to use
  3. If not the newest version of GL used, you have to enable FORWARD COMPATIBILITY.

for example, as pointed out by @kanthonye, if you are using glfw, and use gl version 3.2, these lines are needed:

glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE);
glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 2);

Solution 4

http://support.apple.com/kb/HT5942

the site title is "Mac computers: OpenCL and OpenGL support in OS X Mavericks - Learn about the OpenGL and OpenCL versions that are supported by your computer in OS X Mavericks."

Solution 5

If you're using LWJGL (as of version 2.90), there's a mild gotcha in the javadoc header of ContextAttribs:

... This extension is not supported on MacOS X. However, in order to enable the GL 3.2 context on MacOS X 10.7 or newer, an instance of this class must be passed to LWJGL. The only valid configuration is ContextAttribs(3, 2, CONTEXT_CORE_PROFILE_BIT_ARB), anything else will be ignored.

Share:
17,787

Related videos on Youtube

bobl
Author by

bobl

Updated on July 04, 2022

Comments

  • bobl
    bobl almost 2 years

    I've just upgraded my MacBook Pro to Mavericks (MacOS 10.9), including Xcode. According to Apple's "OpenGL Capabilities Table", this version has support for OpenGL 4.1, but a call to glGetString(GL_VERSION) returns "1.2" and my GLSL 3.30 shader, which begins with "#version 330" refuses to load, saying that version is not supported.

    Do I need to do something to Mavericks to enable 4.1 support?

    • genpfault
      genpfault over 10 years
      Are you requesting a Core context?
    • Andon M. Coleman
      Andon M. Coleman over 10 years
      1.2?! Are you sure you don't mean 2.1?
    • wenbo qiu
      wenbo qiu about 10 years
      I meet the same problem when running the sample code of OpenGL SuperBible Fifth Edition written by Richard Wright, it use glut to create context, after searching on web, people say glut is not in active development, is the problem caused by GLUT?
    • Andon M. Coleman
      Andon M. Coleman almost 10 years
      @wenboqiu: There is FreeGLUT, which is maintained... the problem with using it on OS X is that it goes through X11. X11 is provided on OS X through a compatibility X server called XQuartz, you cannot get a 3.2+ OpenGL context using the XQuartz server because it does not implement the necessary GLX extension to request a core profile. So that means any framework that uses 3.2 on OS X has to go through native APIs like CGL (Fullscreen and C) or NSOpenGL (Fullscreen/Windowed and Objective C). GLFW3 and many other frameworks do this, FreeGLUT still does not.
    • wenbo qiu
      wenbo qiu over 9 years
      @AndonM.Coleman: thanks for your answer.
  • bobl
    bobl over 10 years
    "Attribute list"? "core profile context"? Something to do with XCode, no doubt. Sadly, I've been avoiding XCode since my application is cross-platform. For the same reason, I've been using GLUT for a framework, but I'm suspecting that if I want to use anything more recent than OpenGL 2.1, I'm going to have to bite the bullet and get more involved with MacOS-specific development. Sigh. In any case, thanks.
  • Andon M. Coleman
    Andon M. Coleman over 10 years
    @user2507282: When I think of Xcode I think of the monstrosity of a GUI Apple wants you to use to write software for OS X / iOS.. this really has nothing to do with that, CGL and NSOpenGL are two interfaces in OS X to creating and managing render contexts. At any rate, do not use GLUT if you want modern OpenGL while still hiding the low-level OS specific stuff; I would suggest you use something like glfw3, you must have a core profile context to use GL 3.2+ on OS X, and an ancient framework like GLUT just is not going to cut it.
  • Andy
    Andy over 8 years
    glGetString(GL_VERSION) returns 4.1 ATI-1.38.3 for me yet it still refuses to compile #version 130 shaders. It seems to accept #version 330 shaders, though I don't yet know how to update my shader code to 330...I'm guessing I'm having a completely separate issue?
  • Andy
    Andy over 8 years
    disclaimer: I'm using JOGL, but that is the output of its glGetString wrapper.
  • Andon M. Coleman
    Andon M. Coleman over 8 years
    OS X does not implement GLSL 1.30. They implement 1.20 in the legacy driver and 3.20 in the core. You can get various extensions that touch on 1.40 and 1.50 in the legacy driver though.
  • Bjorn
    Bjorn about 8 years
    This also worked for me, but only after I removed glew. glew and glfw are supposed to be compatible, but on OS X glew caused nothing but problems. OP didn't mention glew, but this was like 2 days of me trying to figure it out. I also had to import <OpenGL/OpenGL.h> and <OpenGL/gl3.h> and then it worked.