Search code examples
javaopengllwjglglfw

OpenGL 3.3 on Mac OSX El Capitan with LWJGL


I am currently trying to create an OpenGL 3.3 context in LWJGL 3 on my Macbook Pro mid 2014. My sourcecode to initialize the window looks like this:

if (!glfwInit()) {
    Logger.addError("GLFW", "init failed");
}

glfwDefaultWindowHints();

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

// glfwWindowHint(GLFW_SAMPLES, 2);

ID = glfwCreateWindow(width, height, title, 0, 0);
if (ID == 0) {
    Logger.addError("GLFW", "window creation failed");
}

Sadly GLFW fails to create the window for any version higher than 2.1, the version glGetString(GL_VERSION) returns when leaving out the window hints ...
I read through all of the "duplicate" questions, but as you can see I already request core profile and forward compatibility. Moreover I installed XCode and have the newest version of the operating system. Do you guys have any other suggestions or did I understand anything horribly wrong? Thanks in advance...

Note that there is no "GLFW_OPENGL_PROFILE" flag in LWJGL 3 afaik, so I can't copy the code from the official GLFW getting started page 1:1. Setting the "GLFW_OPENGL_CORE_PROFILE" flag to true worked on windows though thus this cant be the error making trouble...


Solution

  • The way you are setting the core profile window hint is incorrect. Instead use:

    glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
    

    From the GLFW documentation:

    GLFW_OPENGL_PROFILE specifies which OpenGL profile to create the context for. Possible values are one of GLFW_OPENGL_CORE_PROFILE or GLFW_OPENGL_COMPAT_PROFILE, or GLFW_OPENGL_ANY_PROFILE to not request a specific profile. If requesting an OpenGL version below 3.2, GLFW_OPENGL_ANY_PROFILE must be used. If OpenGL ES is requested, this hint is ignored.