【问题标题】:OpenGL compiling with incorrect versionOpenGL 编译时版本不正确
【发布时间】:2017-11-01 19:30:47
【问题描述】:

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

这里是glxinfo的返回| 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;
}

【问题讨论】:

  • 请显示产生此输出的完整源代码。
  • 我给出的实际上是所有相关的代码。但是我编辑了我的帖子以包含在应用程序启动期间运行此部分的代码块。
  • 如果您查看 derhass 的答案,那么您就会知道为什么提供一个完整的示例如此重要。

标签: c++ opengl glfw


【解决方案1】:

您不能在glfwInit() 之前调用任何 GLFW 函数。在您的情况下,glfwInit() 将完全重置窗口提示。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2020-06-28
    • 1970-01-01
    • 1970-01-01
    • 2018-07-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多