在OS X 10.10下启用OpenGL 4.1,并具有GLEW,GLFW和g++编译



我有一个2014 RMBP,更新到最新版本的OS X,这应该保证我兼容OpenGL 4.1。我整理了一个最小的工作示例:

#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;
}

这将打开一个工作正常的窗口,但它输出以下内容:GL 版本: 2.1 英特尔-10.0.86GLSL 版本:1.20供应商:英特尔公司渲染器:英特尔锐炬 OpenGL 引擎

这是错误的!我应该获得 4.1 兼容性。我在 https://github.com/tomdalling/opengl-series 和 xCode 下下载了示例,它确实上升到 4.1,所以我知道我的计算机能够做到这一点。

这实际上适用于一个更大的项目;我确实尝试将我的项目导入 xcode,将其与 Tom Dalling 的项目合并,它只是不起作用,我总是得到 GL 2.1。

我正在编译上面的代码

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

。也许我错过了一个选择。非常感谢您的帮助!

阅读有关 glfw 站点上的窗口创建提示,您会发现:

每次使用 glfwInit 初始化库时,这些提示都会设置为其默认值

Tom Dalling 的(工作)代码在暗示版本之前调用glfwInit,而你的代码则在之后执行。

所以我怀疑这可能与此有关。

最新更新