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 PlatformandWindows Subsystem for Linux - Confirm and reboot as prompted
- Open Microsoft Store, search for and install Ubuntu
- Open
Ubuntufrom 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 --updateto 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.gitcd 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 raylibcd raylibmkdir build && cd buildcmake -DBUILD_SHARED_LIBS=ON ..makesudo make installexport LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/libexport DISPLAY=:0- Edit
/home/$USER/raylib/src/Makefile- Update
EMSDK_PATHto be/home/$(USER)/emsdk
- Update
source ~/emsdk/emsdk_env.shto activate emsdk environment variablescd ~/raylib/srcmake PLATFORM=PLATFORM_WEB
- Install deps
- Clone this repo
cd ~git clone https://github.com/bradmartin333/WSL2RaylibWASM.gitcd WSL2RaylibWASM
- Build
main.cppexecutable namedtestg++ main.cpp -lraylib -o test./testto run
- Build
main.cppfor wasmcd ~/WSL2RaylibWASM./wasm_build.sh- Take a look at file to understand what is happening
- Open
build/game.htmlin a live serverpython3 -m http.server 8080- Go to http://localhost:8080 in browser and navigate to the file