opengl配置问题-取消强制软件渲染

上一级页面:index-wsl

前言

安装openGL见ubuntu安装opengl

OpenGL3.3版本

see:Environment Variables — The Mesa 3D Graphics Library latest documentation

在运行阶段出现 OpenGL 版本问题

1
Failed to open GLFW window. If you have an Intel GPU, they are not 3.3 compatible. Try the 2.1 version of the tutorials.

WSL默认使用的是OpenGL1.4版本,可以使用一下命令看到当前使用的是什么版本的OpenGL:

1
glxinfo | grep "OpenGL version"
1
## OpenGL version string: 1.4 (4.4.0 - Build 20.19.15.4549)

这是因为较旧版本的WSL默认设置的是Indirect Rendering,最高只能支持OpenGL1.4,和我们项目中使用的版本不一致。为了能支持更高的版本,我们需要设置:

  • MESA_GL_VERSION_OVERRIDE
  • LIBGL_ALWAYS_INDIRECT

必须设置以下环境变量才能消除错误:

1
export MESA_GL_VERSION_OVERRIDE=3.3

注意这里的是3.3,WSLG的D3D12支持现在并不支持opengl4,

取消间接渲染

因为我们要使用linux的opengl做开发,还有必须覆盖的一项环境变量LIBGL_ALWAYS_INDIRECT,将其unset

1
2
3
# if set to`true`(1) , forces an indirect rendering context/connection
# 如果设置为true,强制indirect rendering 上下文/连接
unset LIBGL_ALWAYS_INDIRECT

unset LIBGL_ALWAYS_INDIRECT后,Windows下的VcXsrv也必须取消Native opengl这一选项,如图所示操作

Pasted image 20220607151033

  • 注:如果设置export LIBGL_ALWAYS_INDIRECT=1,会强制indirect rendering ,这样之前之前的设置都无用了,还是不能使用最新的opengl
1
2
3
# if set to`true`(1) , forces an indirect rendering context/connection
# 如果设置为true,强制indirect rendering 上下文/连接
export LIBGL_ALWAYS_INDIRECT=1

不要设置强制软件渲染

如果要强制软件渲染(不调用GPU),这便于opengl的开发调试工作,但请不要永久设置应当在启动opengl开发套件前,临时的设置环境变量

1
2
# 如果设置为`true`(1) ,则始终使用软件渲染(强制软件渲染),不要永久设置这项!!!!!!!!
# export LIBGL_ALWAYS_SOFTWARE=1

参考、引用、致谢