使用错误版本编译的 OpenGL

OpenGL compiling with incorrect version

我正在尝试使用 OpenGL 3.3 编译我的应用程序。我在网上搜索了我的显卡,最高支持4.4。

这里是glxinfo的return | grep OpenGL

OpenGL vendor string: Intel Open Source Technology Center
OpenGL renderer string: Mesa DRI Intel(R) HD Graphics 520 (Skylake GT2) 
OpenGL core profile version string: 4.5 (Core Profile) Mesa 17.2.3
OpenGL core profile shading language version string: 4.50
OpenGL core profile context flags: (none)
OpenGL core profile profile mask: core profile
OpenGL core profile extensions:
OpenGL version string: 3.0 Mesa 17.2.3
OpenGL shading language version string: 1.30
OpenGL context flags: (none)
OpenGL extensions:
OpenGL ES profile version string: OpenGL ES 3.2 Mesa 17.2.3
OpenGL ES profile shading language version string: OpenGL ES GLSL ES 3.20
OpenGL ES profile extensions:

我告诉 GLFW 使用主要版本 3 次要版本 3

glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3);

并使用核心配置文件:

glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);

我很高兴指向版本 3.3 和核心配置文件:

python -m glad --api "gl=3.3" --generator c --out-path ./output --profile core --spec gl

但是当我打电话时

glGetString(GL_VERSION)

我回来了

3.0 Mesa 17.2.3

我这辈子都弄不明白我错过了什么。

第运行段这段代码

{
    glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
    glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3);
    glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE);
    glfwWindowHint(GLFW_FLOATING, GL_TRUE);
    glfwWindowHint(GLFW_RESIZABLE, GL_FALSE);

    glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);

    if (!glfwInit()) {
        std::cout << "glfw not inited" << std::endl;
    }

    glfwSetErrorCallback(error_callback);
    m_game_window = glfwCreateWindow(800, 600, "window", NULL, NULL);

    if (!m_game_window) {
        std::cout << "window creation failed" << std::endl;
        glfwTerminate();
        //crash
    }

    glfwMakeContextCurrent(m_game_window);
    gladLoadGLLoader((GLADloadproc) glfwGetProcAddress);

    glViewport(0, 0, 800, 600);

    char *version = (char*)glGetString(GL_VERSION);
    std::cout << version;
}

您不得在 glfwInit() 之前调用任何 GLFW 函数。在您的情况下,window 提示将被 glfwInit().

完全重置