我尝试在 WSL2 上运行 OpenGL 代码,但在尝试运行可执行文件时出现以下错误:
GLFW error 65543: GLX: Failed to create context: GLXBadFBConfig
Unable to create GLFW window
这是我用来创建窗口的代码:
....
GLFWwindow* initialize() {
int glfwInitRes = glfwInit();
if (!glfwInitRes) {
fprintf(stderr, "Unable to initialize GLFW\n");
return nullptr;
}
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 2);
glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE);
GLFWwindow* window = glfwCreateWindow(1280, 720, "InitGL", nullptr, nullptr);
if (!window) {
fprintf(stderr, "Unable to create GLFW window\n");
glfwTerminate();
return nullptr;
}
glfwMakeContextCurrent(window);
....
return window;
}
....
GLFWwindow* window = initialize();
我使用 VcxSrv 作为我的 X 服务器。
以下是输出glxinfo
direct rendering: No (LIBGL_ALWAYS_INDIRECT set)
server glx vendor string: SGI
server glx version string: 1.4
client glx vendor string: Mesa Project and SGI
client glx version string: 1.4
GLX version: 1.4
OpenGL vendor string: NVIDIA Corporation
OpenGL renderer string: GeForce 940MX/PCIe/SSE2
OpenGL version string: 1.4 (4.6.0 NVIDIA 457.30)
以下修复对我有用。
As @dratenik https://stackoverflow.com/users/14215102/dratenik如上所述,问题仍然存在,因为direct rendering: No
。要解决此问题,请执行以下操作:
在 bashrc/zshrc 文件中添加以下内容:
export LIBGL_ALWAYS_INDIRECT=0
或者你可以删除export LIBGL_ALWAYS_INDIRECT=1
bashrc/zshrc 文件中的行(如果您已添加)。
Then, start a new instance of VcxSrv with and unselect the Native opengl box on the Extra Settings page, and select the Disable access control box.
完成此操作后,应该打开直接渲染,并且您应该在运行时得到以下结果glxinfo
:
direct rendering: Yes
server glx vendor string: SGI
server glx version string: 1.4
...
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)