Enabling OpenGL 4.1 on OS X 10.10 with GLEW, GLFW and g ++ compilation

I have a 2014 RMBP updated to the latest version of OS X which should guarantee compatibility with OpenGL 4.1. I put together a minimal working example:

#include <iostream>

#include "GL/glew.h"
#include <GLFW/glfw3.h>

using namespace std;

int main(){
    int windowWidth = 800;
    int windowHeight = 800;
    string windowTitle = "title";

    glfwDefaultWindowHints();
    glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE);
    glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
    glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 4);
    glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 1);

    if( !glfwInit() )
    {
        cerr << "Failed to initialize GLFW.\n";
        return 1;
    } else {
        clog << "Initialized GLFW." << endl;
    }

    GLFWwindow* pWindow = glfwCreateWindow(windowWidth, windowHeight, windowTitle.c_str(), 0, NULL);

    glfwSetWindowPos(pWindow, 700, 200);
    glfwMakeContextCurrent(pWindow);
    if( pWindow == NULL )
    {
        cerr << "Failed to open GLFW window.\n";
        glfwTerminate();
        return 1;
    }

    std::cout << "GL Version: " << glGetString(GL_VERSION) << "\n";
    std::cout << "GLSL Version: " << glGetString(GL_SHADING_LANGUAGE_VERSION) << "\n";
    std::cout << "Vendor: " << glGetString(GL_VENDOR) << std::endl;
    std::cout << "Renderer: " << glGetString(GL_RENDERER) << std::endl;

    while (!glfwWindowShouldClose(pWindow))
    {
        glfwPollEvents();
    }
    glfwDestroyWindow(pWindow);
    return 0;
}

      

This opens a window, which works fine, but displays the following: GL Version: 2.1 INTEL-10.0.86 GLSL version: 1.20 Provider: Intel Inc. Renderer: Intel Iris OpenGL Engine

what's wrong! I have to get 4.1 compatibility. I have uploaded examples at https://github.com/tomdalling/opengl-series and up to 4.1 in xCode so I know my computer is capable of it.

This is valid for a larger project; I tried to import my project in xcode, merging it with Tom Dalling project, it just doesn't work, I always get GL 2.1.

I am compiling the above code with

g++ main.cpp -o GLTEST -lglfw -framework Cocoa -framework OpenGL -framework IOKit -framework CoreVideo \

      

... maybe I'm missing an option. Thank you so much for your help!

+3


source to share


1 answer


After reading glfw's tips for creating a window , you will find:

These hints are set to default values ​​each time the library is initialized with glfwInit



and Tom Dalling (working) code calls glfwInit

before hinting at the version while yours does it later.

So I suspect it might be related to this.

+3


source







All Articles