A repo of files to compile and run OpenGL program inside WSL 2 using WSLg.
- Windows 11
- Install WSLg - see instruction on https://github.com/microsoft/wslg#installing-wslg
- Install Docker Desktop with WSL 2 backend enabled: see this documentation from Docker.
- Run your Linux Distro (Ubuntu by default) from Start Menu. This gives access to WSL
bash
. Set username and password if you haven't already. - If you haven't already, install
git
with the following command in Ubuntu:sudo apt install git
- Clone this repository with the following command in Ubuntu:
git clone https://github.com/syoon2/docker-wslg-opengl-dev
- Move to the cloned repository with following command:
cd docker-wslg-opengl-dev
- Run
run.sh
. It will take some time for Docker to set up everything you need.
I personally recommend using VS Code with this setup.
- Install Remote Development Extensions on VS Code.
- Install Docker extension on VS Code.
- Click the newly added Docker button on sidebar. Here you will see list of Docker containers, images, etc. set up on your system.
- Right click on the
gpu_docker_wslg
container we've set up earlier. ClickAttach Visual Studio Code
. - And you are done! You can basically use it like your local system.
Note that this container stores files in its own file system and you may want to move files into / out of the container. For this, use docker cp
command. There are other ways to do so, but I am lazy to go through them.
Note that this configuration does NOT work with Windows 10, as WSLg is not supported in Windows 10.
There are ways to use graphical stuff with WSL in Windows 10 using 3rd-party programs like Xming or X410, but you would have to edit some files in this repository before using. I had used them both in the past and neither of them were as smooth as using WSLg.