From c5c1436bc708be9f788306096aa734ee8729ba4b Mon Sep 17 00:00:00 2001 From: Gabriel Kaszewski Date: Sat, 7 Mar 2026 00:39:03 +0100 Subject: [PATCH] Fix WebGL2 for web build (raylib 5 requires VAOs) Add -sUSE_WEBGL2=1 -sMIN_WEBGL_VERSION=2 -sMAX_WEBGL_VERSION=2 to both EMCC_CFLAGS and linker flags. raylib 5.x enables VAOs by default which require WebGL2; without it glVertexAttribPointer fails on the clientside property of an undefined VAO object. Co-Authored-By: Claude Sonnet 4.6 --- .cargo/config.toml | 4 +++- build_web.sh | 4 ++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/.cargo/config.toml b/.cargo/config.toml index 7259cf1..e277ef6 100644 --- a/.cargo/config.toml +++ b/.cargo/config.toml @@ -7,5 +7,7 @@ rustflags = [ "-C", "link-arg=-sWASM=1", "-C", "link-arg=-sALLOW_MEMORY_GROWTH=1", "-C", "link-arg=-sINITIAL_MEMORY=67108864", - "-C", "link-arg=-sFULL_ES3=1", + "-C", "link-arg=-sUSE_WEBGL2=1", + "-C", "link-arg=-sMIN_WEBGL_VERSION=2", + "-C", "link-arg=-sMAX_WEBGL_VERSION=2", ] diff --git a/build_web.sh b/build_web.sh index 76ee9a5..496812d 100755 --- a/build_web.sh +++ b/build_web.sh @@ -4,7 +4,7 @@ set -euo pipefail # Flags required by raylib-sys for WASM compilation. -export EMCC_CFLAGS="-O3 -sUSE_GLFW=3 -sASSERTIONS=1 -sWASM=1 -sASYNCIFY -sGL_ENABLE_GET_PROC_ADDRESS=1" +export EMCC_CFLAGS="-O3 -sUSE_GLFW=3 -sASSERTIONS=1 -sWASM=1 -sASYNCIFY -sGL_ENABLE_GET_PROC_ADDRESS=1 -sUSE_WEBGL2=1 -sMIN_WEBGL_VERSION=2 -sMAX_WEBGL_VERSION=2" echo "Building for wasm32-unknown-emscripten..." cargo build --target wasm32-unknown-emscripten --release @@ -20,5 +20,5 @@ echo "Build complete. Output in web/" if [[ "${1-}" == "--serve" ]]; then echo "Serving at http://localhost:8080" - python3 -m http.server 8080 --directory web + cd web && python3 -m http.server 8080 fi