I wanted a bare-bones program for SDL2 + OpenGL 2D rendering that also compiled to JS+WebGL with Emscripten+Wasm. There are some SDL2 + OpenGL tutorials out there but most of them don’t target the WebGL subset of OpenGL. I can’t use the fixed function pipeline, so older OpenGL code won’t work, and I can’t use newer things like vertex array objects, instancing, or geometry shaders, so newer OpenGL code often won’t work.
The Makefile only works on Mac OS X, but the code should work on Linux and Windows and other SDL+OpenGL platforms (I haven’t tried though). On Mac I installed these libraries for compilation:
brew install SDL2 SDL2_image emscripten
git submodule init
git submodule update
To run the native code:
make && bin/main
To run the emscripten code:
make www
and then tell the webserver to serve the files from www/
.
The Emscripten-ed wasm output is here.
I’ve also written a partial CMakeLists.txt
file but am not using it yet.
To disable WebAssembly, take out the -s WASM=1
flag in the Makefile.
The font included in this project is Droid Sans, under the Apache License v2. The ImGui library includes the Proggy font.