使用带有Mesa 10和GLFW3的OpenGL核心配置文件

时间:2013-12-23 05:50:04

标签: opengl glfw mesa

我在装有Intel HD 3000 GPU的惠普笔记本电脑上运行带有Mesa 10的Arch Linux。 (还有一张ATI卡,但我在启动时将其关闭。)我正在尝试使用核心配置文件运行OpenGL代码。应根据glxinfo支持OpenGL 3.1和GLSL 1.4:

-> % glxinfo | grep version
OpenGL core profile version string: 3.1 (Core Profile) Mesa 10.0.1
OpenGL core profile shading language version string: 1.40
OpenGL version string: 3.0 Mesa 10.0.1
OpenGL shading language version string: 1.3

但是,当我编译GLFW程序时,尝试强制核心配置文件,并要求OpenGL版本如下:

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

int main(void)
{
    // Use OpenGL 3.1 core profile
    glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
    glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE);
    glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
    glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 1);
    glfwWindowHint(GLFW_CONTEXT_REVISION, 0);

    // Create opengl context
    int window_width = 1024;
    int window_height = 768;
    GLFWwindow* window = initialize_glfw(window_width, window_height);
    if (!window)
    {
        glfwTerminate();
        std::exit(EXIT_FAILURE);
    }

    // Display OpenGL version
    int major, minor, rev, client, forward, profile;
    glfwGetVersion(&major, &minor, &rev);
    std::cout << "OpenGL - " << major << "." << minor << "." << rev << std::endl;
}

以及使用GLSL #version 140编译着色器,这是打印输出:

-> % ./main
OpenGL - 3.0.3
Shader compilation failed with this message:
0:1(10): error: GLSL 1.40 is not supported. Supported versions are: 1.10, 1.20, 1.30, 1.00 ES, and 3.00 ES

因此,似乎应该支持OpenGL 3.1和GLSL 1.4,但它们并没有在我的GLFW程序中使用。谁能告诉我可能出现的问题?

2 个答案:

答案 0 :(得分:0)

在调用其他函数之前,您需要initialize GLFW。在调用函数之前,还需要使OpenGL上下文保持最新状态。

答案 1 :(得分:0)

重新阅读文档后,似乎有两个问题。正如elmindreda指出的那样,在制作窗口提示后调用init会将窗口提示设置回默认值,因此必须首先调用init。

其次,我正在使用OpenGL 3.1和GLFW文档say&#34;如果请求的OpenGL版本低于3.2,则必须使用GLFW_OPENGL_ANY_PROFILE。&#34;我试图使用GLFW_OPENGL_CORE_PROFILE。