c++ - 使用 GLEW、GLFW 和 g++ 编译在 OS X 10.10 下启用 OpenGL 4.1

标签 c++ macos opengl g++ glfw

我有一个 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 INTEL-10.0.86 GLSL 版本:1.20 供应商:英特尔公司 渲染器:英特尔 Iris 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 \

...也许我缺少一个选项。非常感谢您的帮助!

最佳答案

阅读有关窗口创建提示的信息 at the glfw site ,你会发现:

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

Tom Dalling 的(工作)代码在提示版本之前调用 glfwInit,而您的代码则在之后调用。

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

关于c++ - 使用 GLEW、GLFW 和 g++ 编译在 OS X 10.10 下启用 OpenGL 4.1,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29858573/

相关文章:

c++ - 一个设备的多个 CUDA 上下文——有什么意义吗?

c++ - 在 C++ 中使用 rpcgen

c++ - Xcode4 : "bad codegen, pointer diff" linker error again

c - OpenGL - 在没有旋转的情况下绕着太阳旋转月亮?

c++ - 帧缓冲区在移动时切掉模型的一部分

c++ - 方法和自由函数之间有哪些细微的区别?

c++ - 数组折叠成单个元素

java - 在 OS X 10.6 中将 VTK 5.4.2 与 Java 结合使用

macos - 通过 Finder 和 Applescript : how to get "item exists - replace?" dialog in Finder? 复制项目

c++ - 3D 立方体绘图,只有一侧始终在最上面