Create window crash on mac

imyt wrote on Sunday, February 23, 2014:

Hi everyone,

I’m new to mac os so I decided to use GLFW. However I cannot even create a window, I called glfwInit first and then glfwCreateWindow, but glfwCreateWindow failed with the following error message “Error: Failed to retrieve context version string
”. Did anyone encountered the same problem before?

I’m using Mac OSX 10.9 and GLFW is built with Cocoa, NSGL and OpenGL.

xdread wrote on Friday, March 07, 2014:

I have been having a look at the source of GLFW, and located the error messages in the file context.c. GLFW gives you that error message when a call to an Open GL function named glGetString() returns 0, and you should theoretically get the real error message by calling glGetError(). I am not sure why GLFW doesn’t do that, but I assume from the error codes returned by Open GL that the error message is irrelevant anyway.

The codes are:
GL_INVALID_ENUM - Which would never happen, since GLFW are using the correct enums.
GL_INVALID_OPERATION - Which would never happen in your case, since you are using OS X Maverich core profile, forward compatible. (glBegin and glEnd is deprecated)

If you can post your code here? Or compare with my minimal working code below?

Anyway, here is my minimalistic code to make GLFW work:

 #include <OpenGL/gl3.h> //(My code compiles without this line)
 #include "GLFW/glfw3.h"


    if (!glfwInit()) {

    glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
    glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 2);

    GLFWwindow* window = glfwCreateWindow(640, 480, "GLFW", NULL, NULL);

    if (!window)

//Setup shaders and things here
//Maybe glfwSwapInterval(1) here?

    glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
    while (!glfwWindowShouldClose(window))
        glfwPollEvents();  //Needed, or you will get a spinning beach ball

void error_callback(int error, const char* description)
    fputs(description, stderr);
    std::cout << std::endl;

EDIT: I would insist on you learning “modern” Open GL with shaders, even if it seems very hard, but if you insist on using the soon to be obsolete old style Open GL, just set the version to be 2.1 and remove the window hints for core and forward compatibility. You don’t have backwards compatibility for any version higher than that on Mac.

Also note that even though Open GL is a certain version, the shader language may NOT be the same version:

And last, a good source to learn more:

elmindreda wrote on Friday, March 07, 2014:

#include <OpenGL/gl3.h> //(My code compiles without this line)

These two lines have the same result. You only need one of them.