c++ - GLFW 无法创建窗口 : "GLX: Failed to create context: GLXBadFBConfig"

标签 c++ linux opengl glfw

我正在尝试在我的 Debian Stretch 系统中创建一个 glfw 窗口。

初始化glfw的代码:

// Initialize GLFW  
void initGLFW()
{
    if (!glfwInit())
    {
        exit(EXIT_FAILURE);
    }

    glfwSetErrorCallback(errorCallback);
    glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 4);
    glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 0);
    glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_FALSE);
    glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
    glfwWindowHint(GLFW_RESIZABLE, GL_FALSE);
    glfwWindowHint(GLFW_OPENGL_DEBUG_CONTEXT, GL_TRUE);

    window = glfwCreateWindow(WINDOW_WIDTH, WINDOW_HEIGHT, "GLSL4.3 + GLM + VBO + VAO", NULL, NULL);
    if (!window)
    {
        fprintf(stderr, "Failed to open GLFW window.\n");
        glfwTerminate();
        //system("pause");
        exit(EXIT_FAILURE);
    }
}

当我运行可执行文件时,我收到了上面的消息。为什么?

GLX: Failed to create context: GLXBadFBConfig
Failed to open GLFW window.

运行 LIBGL_DEBUG=verbose 我明白了

libGL: Can't open configuration file /home/rafael/.drirc: No such file or directory.
libGL: pci id for fd 5: 8086:0a16, driver i965
libGL: OpenDriver: trying /usr/lib/x86_64-linux-gnu/dri/tls/i965_dri.so
libGL: OpenDriver: trying /usr/lib/x86_64-linux-gnu/dri/i965_dri.so
libGL: Can't open configuration file /home/rafael/.drirc: No such file or directory.
libGL: Using DRI3 for screen 0

一些有用的信息:

$ lspci | grep VGA
00:02.0 VGA compatible controller: Intel Corporation Haswell-ULT Integrated Graphics Controller (rev 0b)

$ glxinfo | grep version
server glx version string: 1.4
client glx version string: 1.4
GLX version: 1.4
    Max core profile version: 3.3
    Max compat profile version: 3.0
    Max GLES1 profile version: 1.1
    Max GLES[23] profile version: 3.0
OpenGL core profile version string: 3.3 (Core Profile) Mesa 11.2.2
OpenGL core profile shading language version string: 3.30
OpenGL version string: 3.0 Mesa 11.2.2
OpenGL shading language version string: 1.30
OpenGL ES profile version string: OpenGL ES 3.0 Mesa 11.2.2
OpenGL ES profile shading language version string: OpenGL ES GLSL ES 3.00

initGLFW 函数是从 main 调用的第一个函数。

最佳答案

您正在尝试创建 OpenGL 4.0 核心配置文件上下文:

glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 4);
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 0);
glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);

您的驱动程序/OpenGL 实现最多只支持 3.3:

OpenGL core profile version string: 3.3 (Core Profile) Mesa 11.2.2
Max core profile version: 3.3

台面 11.2.2 could support OpenGL 4.1 但仅适用于某些驱动程序(来自 11.0.0 的发行说明):

OpenGL 4.1 on radeonsi, nvc0

台面 12.0.0 seems to support i965 上的 OpenGL 4.3:

OpenGL 4.3 on nvc0, radeonsi, i965 (Gen8+)

修复方法是更新您的显卡、Mesa3D 或改为创建 3.3 上下文:

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

关于c++ - GLFW 无法创建窗口 : "GLX: Failed to create context: GLXBadFBConfig",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39213757/

相关文章:

c++ - 什么是跨平台字符串类的 "Best Practices"以实现良好的模型可移植性?

c++ - Profinet/Profibus linux

linux - 构建和使用 Qt Embedded 的经验

math - 使用 Eigen 计算 2D 相机的模型 View 矩阵

opengl - freeglut 和 glut 的主要区别是什么

c++ - 类似于 PHP 的类语法

c++ - map 初始化 map

c++ - 目标文件是什么样的

android - 如何从 Linux 内核中找到处理核心的频率和利用率?

c++ - 损坏的纹理编号 OpenGL,在 glGenTextures/glBindTexture 之后