- Download the installer from https://sourceforge.net/projects/vcxsrv/
- Install the VcXsrv by the installer.
- Open XLaunch and keep clicking "Next" until you see the option: "Disable access control". Enable this option.
- At the last step, save the config file: "config.xlaunch" at a path you like.
sudo apt-get update
sudo apt-get install libsdl2-dev libsdl2-gfx-dev libsdl2-image-dev
- vim ~/.bashrc
Paste the 5 lines below.
alias xlaunch='/c/Program\ Files/VcXsrv/xlaunch.exe -run ~/Projects/config.xlaunch'
export DISPLAY=$(cat /etc/resolv.conf | grep nameserver | awk '{print $2}'):0
export LIBGL_ALWAYS_INDIRECT=1
export XDG_RUNTIME_DIR=/home/james/Projects
export RUNLEVEL=3
The path at the first line: "~/Projects/config.xlaunch" can be a path you like, same for the "/home/james/Projects" at the fourth line. Make sure these two pathes are the same folder. If you are using WSL1, please change the export DISPLAY=$(cat /etc/resolv.conf | grep nameserver | awk '{print $2}'):0
to export DISPLAY=:0
. You can type wsl -l -v
on PowerShell to check which version you are using.
- source ~/.bashrc
Make sure you reopen all terminals that are opened before setting the .bashrc.
Build and run the main program
g++ main.cpp -lSDL2 -lSDL2_image -o mySDL; ./mySDL
brew install SDL2
brew install SDL2_image
Make sure you reopen all terminals that are opened before installing the SDL2 by brew.
Build and run the main program
g++ main.cpp -lSDL2 -lSDL2_image -o mySDL; ./mySDL
https://lazyfoo.net/tutorials/SDL/
If an example uses #include <SDL.h>
, just replace it with #include <SDL2/SDL.h>
, same for other SDL libraries.