c - Arch Linux 上的 OpenGL 3.3

标签 c linux opengl glfw mesa

我需要帮助使用核心配置文件进行一些 OpenGL 3.3 编程。我在安装了 xf86-video-intelmesa-libgl 软件包的 Arch Linux 操作系统上运行。我的 CPU 内置了 Intel HD 4400

当我输入glxinfo | grep OpenGL 进入终端,显示我可以支持 OpenGL 3.3

OpenGL vendor string: Intel Open Source Technology Center
OpenGL renderer string: Mesa DRI Intel(R) Haswell Mobile 
OpenGL core profile version string: 3.3 (Core Profile) Mesa 12.0.3
OpenGL core profile shading language version string: 3.30
OpenGL core profile context flags: (none)
OpenGL core profile profile mask: core profile
OpenGL core profile extensions:
OpenGL version string: 3.0 Mesa 12.0.3
OpenGL shading language version string: 1.30
OpenGL context flags: (none)
OpenGL extensions:
OpenGL ES profile version string: OpenGL ES 3.0 Mesa 12.0.3
OpenGL ES profile shading language version string: OpenGL ES GLSL ES 3.00
OpenGL ES profile extensions:

我使用 GLFW3 和 GLEW 来设置 OpenGL

if(!glfwInit()) {
    return -1;
}
GLFWwindow* window = glfwCreateWindow(800, 600, "Hello Guys", NULL, NULL);
if(!window) {
    glfwTerminate();
    return -1;
}

glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3);
glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
glfwWindowHint(GLFW_RESIZABLE, GL_FALSE);

glfwMakeContextCurrent(window);

if(glewInit() != GLEW_OK) {
    printf("GLEW did not initialize\n");
    glfwTerminate();
    return -1;
}

但是,当我尝试编译着色器时,收到错误不支持 GLSL 3.30。支持的版本有:1.10、1.20、1.30、1.00 ES 和 3.00 ES

看来 Mesa 或 GLFW3 正在让我的电脑使用前向兼容配置文件而不是核心配置文件。我该如何解决这个问题?

最佳答案

来自the docs (强调我的):

void glfwWindowHint( int hint, int value )        

This function sets hints for the next call to glfwCreateWindow. ...

所以:除非你想要 the defaults确保在创建窗口之前设置提示::

glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3);
glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
glfwWindowHint(GLFW_RESIZABLE, GL_FALSE);

GLFWwindow* window = glfwCreateWindow(800, 600, "Hello Guys", NULL, NULL);
if(!window) {
    glfwTerminate();
    return -1;
}

关于c - Arch Linux 上的 OpenGL 3.3,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40089639/

相关文章:

c++ - 在 OpenGL 中计算相机的法线?

c++ - 从带有 opengl 代码的 C++ 转换为带有 GUI 的 QT 应用程序?

c - unsigned long 到 char 数组

c - 打印数组列表大小崩溃

c、创建 child 和wait()

python - python是否有 Hook 到EXT3

c++ - 为什么 GLSL const bool 不起作用?

使用 Xcode 控制到达非 void 函数 C 编程的末尾

linux - 如何在 Linux 命令行中将多个输入指定为单个输入?

c++ - 在堆中共享一个对象