OpenGL 4.1(?) under Mavericks

2019-01-17 15:31发布

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?

6条回答
看我几分像从前
2楼-- · 2019-01-17 15:54

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."

查看更多
SAY GOODBYE
3楼-- · 2019-01-17 15:54

If you are using SDL as your high level API there are a number of things you need to do to get 4.1 support.

First of all make sure you have SDL2 2.0.1 (or later I guess). For instance using brew:

brew update brew upgrade sdl2

Secondly, you need to specifically tell SDL to request a core profile like so

SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_CORE );

Thirdly a quirk in how a core profile is requested on the mac actually requires you to request 3.2 to get 4.1 (!). I think this has been fixed in the SDL2 repository but not been released yet.

SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 3); SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 2);

查看更多
放我归山
4楼-- · 2019-01-17 15:58

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.

查看更多
别忘想泡老子
5楼-- · 2019-01-17 15:59

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.

查看更多
聊天终结者
6楼-- · 2019-01-17 16:09

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.

查看更多
做自己的国王
7楼-- · 2019-01-17 16:12

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);
查看更多
登录 后发表回答