Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

OpenGL 4.1(?) under Mavericks

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?

like image 390
bobl Avatar asked Nov 08 '13 17:11

bobl


People also ask

What version of OpenGL does Mac support?

According to Apple, OpenGL is no longer supported. However, it appears v4. 1 of OpenGL was supported on many devices as of July 28, 2020.

Can I do OpenGL in Mac?

OpenGL is available to all Macintosh applications. OpenGL for OS X is implemented as a set of frameworks that contain the OpenGL runtime engine and its drawing software. These frameworks use platform-neutral virtual resources to free your programming as much as possible from the underlying graphics hardware.

Does MacBook Pro have OpenGL?

The most recent machines to support both OpenCL and OpenGL are the 2018 MacBook Pro 13 and 15 inch. Both machines support OpenGL 4.1 and OpenCL 1.2.


2 Answers

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.

like image 168
Andon M. Coleman Avatar answered Oct 22 '22 20:10

Andon M. Coleman


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.

like image 13
kanthonye Avatar answered Oct 22 '22 21:10

kanthonye