2

I'm trying to learn OpenGL on OSX Mavericks which supports upto OpenGL 4.1 as of today.

I'm keeping it basic and compiling using gcc (g++), but when loading the open GL context through Freeglut OSX loads the legacy OpenGL profile.

I've tried this: OpenGL 3.3 on OSX with FreeGLUT but with no luck, a glGetString call returns these values:

NVIDIA GeForce GT 750M OpenGL Engine
2.1 NVIDIA-8.24.9 310.40.25f01

Anyone have any ideas?

i'm calling FreeGlut with the following context calls:

glutInitContextVersion(3,2);
glutInitContextProfile(GLUT_CORE_PROFILE);

Edit: Just tried the same application in Windows rather than OSX and got this error:

2.1 context requested but wglCreateContextAttribsARB is not available. Falling back to legacy context creation

Here is my application entry point

    int main (int argc, char * argv[])
{
try{
    glutInit(&argc, argv);


    glutInitDisplayMode(GLUT_RGBA);

    glutInitWindowSize(512,512);

    glutInitContextVersion(4,2);

    glutInitContextFlags(GLUT_FORWARD_COMPATIBLE);
    glutInitContextProfile(GLUT_CORE_PROFILE);

    cout << "Called GLUT with 'GLUT_FORWARD_COMPATIBLE' \n";
    //cout << VAO_IDs::NumVAOs;

    glutCreateWindow("Triangles!");

    cout << "Calling GLEW. " << endl;
    glewExperimental = GL_TRUE;
    if(glewInit())
    {
        cerr << "unable to initialise GLEW.. Exiting " << endl;
    }
    cout << "calling init " << endl;
    init();
    cout << "Setting display function " << endl;
    glutDisplayFunc(display);
    cout << "Entering loop " << endl;
    glutMainLoop();
    }
    catch (exception)
    {
        cerr << "ERROR! " <<endl;
    }

    }

OK So...

Recompiled on a Windows PC, worked no issue, maybe an issue with FreeGLUT on OSX or OSX itself or a combination.

At least now I have code I can test OSX with...

Community
  • 1
  • 1
  • You have to create a forwad compatible context on OSX – derhass Apr 07 '14 at 20:43
  • And how do I do that? – VariableDeclared Apr 08 '14 at 08:07
  • `glutInitContextFlags(GLUT_FORWARD_COMPATIBLE);` might do the trick – derhass Apr 08 '14 at 10:48
  • Just put that one in, didn't work unfortunately. Do you know where I can get a list of options for glutInitContextProfile? that'd be useful. – VariableDeclared Apr 08 '14 at 14:52
  • OS X does not even have a method in its underlying CGL/NSOpenGL APIs to select forward-compatibility. It is pretty much implicit that what you are given when you create a 3.2+ context on OS X it will behave as forward-compatible. If anything, this would be a hint for some frameworks so that ***the framework itself*** understands which features are available... but context creation will not fail if you neglect to specify this flag. *Can you include some more code that puts these two calls into context? If you call them after you create your context, for instance, then they do nothing.* – Andon M. Coleman Apr 08 '14 at 19:12
  • OK will include code, thanks for the feedback. – VariableDeclared Apr 08 '14 at 19:44

1 Answers1

5

OSX Mavericks has no support of OpenGL 4.2. Hence, it is impossible to create a 4.2 context. The last supported version is 4.1 + some extensions which are made into Core in 4.2.

If you want to ship today the only option is using OpenGL 4.1 with extensions.

Here is the code for GLFW3:

glfwWindowHint( GLFW_CONTEXT_VERSION_MAJOR, 4 );
glfwWindowHint( GLFW_CONTEXT_VERSION_MINOR, 1 );
glfwWindowHint( GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE );
glfwWindowHint( GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE );
Sergey K.
  • 24,894
  • 13
  • 106
  • 174