zync
zync

Reputation: 461

Can't create an OpenGL 3.2 context using GLFW3 on mac

I've been working on an OpenGL project using GLFW 2 in Xcode and everything was working perfectly fine. I was able to create a 3.2 OpenGL context, and render everything.

However, yesterday I installed the GLFW3 lib and made the corrections suggested. Now I simply can't create a 3.2 context and it always returns a 3.0.3 context. What can I be doing wrong?

I include the glew headers before the glfw ones

Here's my initialisation code:

if(!glfwInit()){
        std::cout << "ERROR IN glfwInit()" << std::endl;
        return;
    }

    mWindow = glfwCreateWindow(mWidth, mHeight, "GLFW Renderer", NULL, NULL);;

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

    if(!mWindow){
        std::cout << "ERROR IN glfwOpenWindow" << std::endl;
        glfwTerminate();
        return;
    }

    /* Make the window's context current */
    glfwMakeContextCurrent(mWindow);

    int major, minor, rev;
    glfwGetVersion(&major, &minor, &rev);
    std::cout << "OpenGL " << major << "." << minor << "." << rev << std::endl;

    glewExperimental = GL_TRUE;
    if(glewInit() != GLEW_OK){
        std::cout << "ERROR INITIALIZING GLEW" << std::endl;
        return;
    }

    glViewport(0, 0, mWidth, mHeight);

Edit: changed GLFW_CONTEXT_VERSION_MINOR to 2

Upvotes: 0

Views: 2026

Answers (2)

Shago
Shago

Reputation: 101

when i put

 glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3);

my window can't be created, i put the windowHints before declaring the window and creating it.

I only have :

glfwWindowHint(GLFW_SAMPLES, 4); // 4x antialiasing
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3); // We want OpenGL 3.3                                                   
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3);

Upvotes: 0

zync
zync

Reputation: 461

As suggested by Brett Hale, I solved it by specifying the glfwWindowHints before creating the window, which makes perfect sense.

Upvotes: 5

Related Questions