These steps have been tested on Windows 10 with WSL2 running Ubuntu.
First install the dependencies:
apt install mesa-utils libglu1-mesa-dev freeglut3-dev mesa-common-devThere are more than we need, but also include GLut and Glu libraries to link aginst during compilation for application development (these can be removed if that functionality is not required).
Then, you will need to setup a window server. Windows 11 should have this built in and work out of the box (skip to step 3). In Windows 10 you will need to install one VcXsrv is a popular option (also known as XLaunch).
Once installed, then you will need to make a configuration. You want the following settings:
- First Screen: Multi-Window, Display=0
- Second Screen: Start No Client
- Third Screen: Clipboard=True, Primary Selection=True, Native OpenGL=False, Disable Access Control=True
I recomend you save your configuration file somewhere so that each time you start you window server you can open it instead of rebuilding it. Then start your window server.
Once you have setup and started your Window server, you need to tell Ubuntu/WSL where your display is, we can do this by running the following command:
export DISPLAY=$(awk '/nameserver / {print $2; exit}' /etc/resolv.conf 2>/dev/null):0
export LIBGL_ALWAYS_INDIRECT=0You will need to do this for every new shell you open. Alternatively, you can add this to your .bashrc file to have your shell do it for you an start up.
After the following configuration you should be able to run the test application below and see some multi-colored gears spinning:
glxgears


Hi, thanks for this gist!
About "WSL Display", on my computer (maybe on others different and OK) has this not worked.
As solution I found where works on WSL v1 and v2 is to use the IP given on Windows
ipconfig.exe(where also listed onifconfigby v1 only), there his output aboutEDIT: VcXsrv moved to GitHub: https://github.com/marchaesen/vcxsrv
Here what I found during fault search:
During test I seen following parts:
/etc/resolv.confnot match in my case:Here his output:
With
ifconfigI checked and brought:Has tried the second IP with
export DISPLAY="172.27.16.1:0"and has worked with it.wsl.exe --set-version ubuntu 2)There brings
resolv.confthis:The ifconfig brings there:
But the IP's
10.255.255.254and172.27.27.235are not usable.