WSL – Troubleshoot OpenGL on Ubuntu Under Windows 10

openglUbuntuwindows 10windows-subsystem-for-linux

I have installed Ubuntu on Windows 10 using Windows Subsystem for Linux (WSL). I'm attempting to get OpenGL graphics to work. My ultimate objective is to be able to run the Gazebo simulator for Robot OS (ROS), which requires OpenGL. As a first step, I'm trying to ensure that OpenGL graphics are working like they're supposed to.

According to this tutorial and many others, to run ROS and Gazebo I should install VcXsrv and run the X server with the "Native OpenGL" option disabled, so I'm doing that.

My immediate problem is that OpenGL doesn't appear to be working quite right. I have installed the Mesa utils and when I run glxgears I do see the graphics window, but the animation is extremely slow. I'd estimate that the gears are turning at about 1 revolution per minute. I can reorient the gears using the arrow keys, but again the update is extremely slow. (Every now and then there is a visible "jump", if that matters.)

For a comparison, I tried running glxgears on Ubuntu running in a VirtualBox machine. To my surprise, it animates much faster; the gears make a full rotation about once every 4 seconds, compared to once every (maybe 60 seconds but I lost patience) when running under Windows with WSL. This is a big surprise since I'd expect the VirtualBox to be much slower.

On Windows with WSL, glxgears claims that it is running very fast — between 800 and 1700 FPS. In VirtualBox glxgears reports about 900-1000FPS.

Version info on glxgears and OpenGL:

xxxx@DESKTOP-8U2MCOG:~$ glxgears -info
GL_RENDERER   = Software Rasterizer
GL_VERSION    = 1.4 (2.1 Mesa 19.2.0-devel (git-cdf42f5eaa))
GL_VENDOR     = Mesa Project
GL_EXTENSIONS = GL_ARB_depth_texture GL_ARB_fragment_program GL_ARB_fragment_program_shadow GL_ARB_occlusion_query GL_ARB_texture_env_dot3 GL_ARB_transpose_matrix GL_EXT_draw_range_elements GL_EXT_multi_draw_arrays GL_NV_depth_clamp GL_NV_fog_distance GL_NV_point_sprite GL_SUN_multi_draw_arrays
VisualID 183, 0xb7
20311 frames in 5.0 seconds = 4062.197 FPS

Why is glxgears running so slow in WSL? If it should rightly be able to run faster, then how do I make that happen?

UPDATE

Based on the answer from @allquixotic below I made another attempt to run with the wgl option, which I did by leaving that second checkbox "Native opengl" checked. I had tried this before, but it turns out I needed to do this after a reboot for it to take effect. When I run glxgears with this setup, I get a slightly different readout on the console:

xxxx@DESKTOP-8U2MCOG:~$ glxgears
Running synchronized to the vertical refresh.  The framerate should be
approximately the same as the monitor refresh rate.
23633 frames in 7.5 seconds = 3147.913 FPS
10395 frames in 6.8 seconds = 1529.523 FPS
10395 frames in 6.9 seconds = 1512.829 FPS

Now I'm pretty sure my monitor doesn't run at a vertical scan rate of 1500Hz! So I think this might be an indicator of what's really going on; some weirdness with the indirect rendering system. Also I notice that when I CTRL+C to end the program, the GL Window keeps running and animating for a good 10-11 seconds after I've terminated the program — and that's if I've only run the program for 3-4 seconds. So I'd have to guess that there are a ton of messages getting queued up, or something like that…?

Best Answer

While I hate to be "that guy" who posts an answer to his own question, I went through more than a little pain to get things working, and I'd like to save the next guy the same amount of trouble. So, here is

What actually ended up working

For reasons I do not understand, my system worked when I ran contrary to the (quite sensible) recommendation from @allquixotic.

1) Disable LIBGL_ALWAYS_INDIRECT

This wound up being really difficult, simply because I had to find where it was set.

  • In the folder \etc\profile.d was a file wsl-integration.sh.
  • The above file was actually a symlink; the actual file was /usr/share/wslu/wsl-integration.sh
  • In that file the variable LIBGL_ALWAYS_INDIRECT was set, so I commented out that line.

2) Do not use the -wgl command line argument (or its GUI equivalent) for VcXsrv

Since I was launching VcXsrv from a GUI client, this meant leaving the second option box, titles "Native opengl", unchecked.

Only once I had both those changes made (and did a fresh reboot to make sure no old settings for VcXsrv had persisted) then the gears in glxgears were turning at a normal rate, and I could reorient them using the arrow keys, just like they're supposed to work.

Related Question