Example C++ game made with RayLib and emscripten on WSL2
- Click the windows icon in the toolbar and type
Turn Windows features on or off
- Turn on
Virtual Machine Platform
andWindows Subsystem for Linux
- Confirm and reboot as prompted
- Open Microsoft Store, search for and install Ubuntu
- Open
Ubuntu
from the windows app launcher when complete - If it fails, download and install the x64 machine patch (Typically happens on Win11)
- Wait for install and enter desired username as password when prompted
- Turn on
- Close all windows and open Command Prompt as admin
wsl --update
to enable X11 server
- Python3 comes with WSL2, so we don't have to install that
- Install CMake and build tools
sudo apt-get update && sudo apt-get install cmake build-essential
- Install emscripten from source
cd ~
git clone https://github.com/emscripten-core/emsdk.git
cd emsdk/
./emsdk install latest
./emsdk activate latest
- Install raylib from source for web
- Install deps
sudo apt install vlc libasound2-dev libx11-dev libxrandr-dev libxi-dev libgl1-mesa-dev libglu1-mesa-dev libxcursor-dev libxinerama-dev
cd ~
git clone https://github.com/raysan5/raylib.git raylib
cd raylib
mkdir build && cd build
cmake -DBUILD_SHARED_LIBS=ON ..
make
sudo make install
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/lib
export DISPLAY=:0
- Edit
/home/$USER/raylib/src/Makefile
- Update
EMSDK_PATH
to be/home/$(USER)/emsdk
- Update
source ~/emsdk/emsdk_env.sh
to activate emsdk environment variablescd ~/raylib/src
make PLATFORM=PLATFORM_WEB
- Install deps
- Clone this repo
cd ~
git clone https://github.com/bradmartin333/WSL2RaylibWASM.git
cd WSL2RaylibWASM
- Build
main.cpp
executable namedtest
g++ main.cpp -lraylib -o test
./test
to run
- Build
main.cpp
for wasmcd ~/WSL2RaylibWASM
./wasm_build.sh
- Take a look at file to understand what is happening
- Open
build/game.html
in a live serverpython3 -m http.server 8080
- Go to http://localhost:8080 in browser and navigate to the file