by HyperCrab2000 » Thu Feb 20, 2025 4:22 am
I'm curious if I can port GZDoom to WASM for a web browser and I figure the only real hurdle is WebGL, and so I played around with it and got stuck and I'm not sure what's going on so I hope someone can help out?
I'm trying to build GZDoom into WASM and run it in the browser. However, I'm not very familiar with C and the instructions don't seem to be very clear to me. Here's what I did.
I modified CMakeLists.txt to add this at the very top
cmake_minimum_required(VERSION 3.10)
set(BUILD_SHARED_LIBS OFF) # Disable shared libraries
set(BUILD_STATIC ON)
Changed this block
#Change for Emscripten
include(CheckSymbolExists)
if (NOT CMAKE_SYSTEM_NAME MATCHES "Emscripten")
check_symbol_exists(backtrace "execinfo.h" HAS_BACKTRACE)
if (HAS_BACKTRACE)
add_definitions(-DHAS_BACKTRACE)
endif()
endif()
if(CMAKE_SYSTEM_NAME MATCHES "Windows" OR CMAKE_SYSTEM_NAME MATCHES "MSYS")
set(NOX11 ON)
set(NO_GBM ON)
set(WIN32_PLATFORM ON)
if(CMAKE_C_COMPILER_ID MATCHES "MSVC" OR "x${CMAKE_C_SIMULATE_ID}" STREQUAL "xMSVC")
set(WIN32_MSVC ON) #msvc or icl or clang-cl
endif()
endif()
#Emscripten
if (CMAKE_SYSTEM_NAME MATCHES "Emscripten")
set(STATICLIB ON)
endif()
Added this at the bottom
# Ensure the linker knows where to find libGL.a
link_directories(/Users/me/IdeaProjects/react-boilerplate/gzdoom-build/gl4es/lib)
# Define gzdoom and make sure it links AFTER GL is built
add_executable(gzdoom main.c)
# Make sure gzdoom depends on GL
add_dependencies(gzdoom GL)
# Link gzdoom against GL (the static library)
target_link_libraries(gzdoom /Users/me/IdeaProjects/react-boilerplate/gzdoom-build/gl4es/lib/libGL.a)
And added this main.c file because I needed an entry point I guess?
#include <stdio.h>
#include <stdlib.h>
// External function to initialize GL4ES
extern void initialize_gl4es();
int main() {
// Initialize GL4ES before any OpenGL functions are used
initialize_gl4es();
// Your WebAssembly application logic here
printf("GL4ES Initialized, now running WebAssembly app...\n");
return 0;
}
To build I ran this
emcmake cmake ..
emmake make -j$(sysctl -n hw.ncpu)
And finally this command:
emcc -s USE_WEBGL2=1 -s FULL_ES2=1 -s ALLOW_MEMORY_GROWTH=1 -s AUDIO_WORKLET=1 -s WASM_WORKERS=1 -pthread \
--preload-file ../doom2.wad@/doom/doom2.wad \
../main.c -L../lib -I../include -o gzdoom.html \
-s EXPORTED_FUNCTIONS="['_initialize_gl4es', '_main']" \
-s EXPORTED_RUNTIME_METHODS="['callMain']" \
../lib/libGL.a
Which gives me a .wasm file and an .html file I can serve using
python3 -m http.server 8080
However, when I do I see this:
LIBGL: Initialising gl4es
LIBGL: v1.1.7 built on Feb 20 2025 01:24:52
LIBGL: Using GLES 2.0 backend
LIBGL: Hardware test disabled, nothing activated...
LIBGL: Targeting OpenGL 2.1
LIBGL: Not forcing NPOT support
LIBGL: Not trying to batch small subsequent glDrawXXXX
LIBGL: Trying to use VBO
LIBGL: Force texture for Attachment color0 on FBO
LIBGL: Hack to trigger a SwapBuffers when a Full Framebuffer Blit on default FBO is done
LIBGL: Current folder is:/
LIBGL: Not using PSA (prgbin_n=0, notexarray=0)
GL4ES Initialized, now running WebAssembly app...
And nothing happens. What am I missing? GZDoom doesn't seem to be running and I see no console errors.
Apologies for not formatting this cleaner but I don't see a way of enabling BBCode for this post so I hope someone can help out? I'm stuck and I'm not sure what else to do.
I'm curious if I can port GZDoom to WASM for a web browser and I figure the only real hurdle is WebGL, and so I played around with it and got stuck and I'm not sure what's going on so I hope someone can help out?
I'm trying to build GZDoom into WASM and run it in the browser. However, I'm not very familiar with C and the instructions don't seem to be very clear to me. Here's what I did.
I modified CMakeLists.txt to add this at the very top
cmake_minimum_required(VERSION 3.10)
set(BUILD_SHARED_LIBS OFF) # Disable shared libraries
set(BUILD_STATIC ON)
Changed this block
#Change for Emscripten
include(CheckSymbolExists)
if (NOT CMAKE_SYSTEM_NAME MATCHES "Emscripten")
check_symbol_exists(backtrace "execinfo.h" HAS_BACKTRACE)
if (HAS_BACKTRACE)
add_definitions(-DHAS_BACKTRACE)
endif()
endif()
if(CMAKE_SYSTEM_NAME MATCHES "Windows" OR CMAKE_SYSTEM_NAME MATCHES "MSYS")
set(NOX11 ON)
set(NO_GBM ON)
set(WIN32_PLATFORM ON)
if(CMAKE_C_COMPILER_ID MATCHES "MSVC" OR "x${CMAKE_C_SIMULATE_ID}" STREQUAL "xMSVC")
set(WIN32_MSVC ON) #msvc or icl or clang-cl
endif()
endif()
#Emscripten
if (CMAKE_SYSTEM_NAME MATCHES "Emscripten")
set(STATICLIB ON)
endif()
Added this at the bottom
# Ensure the linker knows where to find libGL.a
link_directories(/Users/me/IdeaProjects/react-boilerplate/gzdoom-build/gl4es/lib)
# Define gzdoom and make sure it links AFTER GL is built
add_executable(gzdoom main.c)
# Make sure gzdoom depends on GL
add_dependencies(gzdoom GL)
# Link gzdoom against GL (the static library)
target_link_libraries(gzdoom /Users/me/IdeaProjects/react-boilerplate/gzdoom-build/gl4es/lib/libGL.a)
And added this main.c file because I needed an entry point I guess?
#include <stdio.h>
#include <stdlib.h>
// External function to initialize GL4ES
extern void initialize_gl4es();
int main() {
// Initialize GL4ES before any OpenGL functions are used
initialize_gl4es();
// Your WebAssembly application logic here
printf("GL4ES Initialized, now running WebAssembly app...\n");
return 0;
}
To build I ran this
emcmake cmake ..
emmake make -j$(sysctl -n hw.ncpu)
And finally this command:
emcc -s USE_WEBGL2=1 -s FULL_ES2=1 -s ALLOW_MEMORY_GROWTH=1 -s AUDIO_WORKLET=1 -s WASM_WORKERS=1 -pthread \
--preload-file ../doom2.wad@/doom/doom2.wad \
../main.c -L../lib -I../include -o gzdoom.html \
-s EXPORTED_FUNCTIONS="['_initialize_gl4es', '_main']" \
-s EXPORTED_RUNTIME_METHODS="['callMain']" \
../lib/libGL.a
Which gives me a .wasm file and an .html file I can serve using
python3 -m http.server 8080
However, when I do I see this:
LIBGL: Initialising gl4es
LIBGL: v1.1.7 built on Feb 20 2025 01:24:52
LIBGL: Using GLES 2.0 backend
LIBGL: Hardware test disabled, nothing activated...
LIBGL: Targeting OpenGL 2.1
LIBGL: Not forcing NPOT support
LIBGL: Not trying to batch small subsequent glDrawXXXX
LIBGL: Trying to use VBO
LIBGL: Force texture for Attachment color0 on FBO
LIBGL: Hack to trigger a SwapBuffers when a Full Framebuffer Blit on default FBO is done
LIBGL: Current folder is:/
LIBGL: Not using PSA (prgbin_n=0, notexarray=0)
GL4ES Initialized, now running WebAssembly app...
And nothing happens. What am I missing? GZDoom doesn't seem to be running and I see no console errors.
Apologies for not formatting this cleaner but I don't see a way of enabling BBCode for this post so I hope someone can help out? I'm stuck and I'm not sure what else to do.