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. [Note: as of 2026, the WebGL 1 vertex array object extension has 100% support, and instancing is near 100%. And both are fully supported in WebGL 2.]
The Makefile should work on Linux and MacOS. The code should work on Windows and other SDL+OpenGL platforms but may need minor modifications; I haven’t tested them.
On Mac using Homebrew:
brew install SDL2 SDL2_imageOn RedHat/Fedora flavors of Linux:
sudo yum install SDL2-devel SDL2_image-develOn Debian/Ubuntu flavors of Linux:
sudo apt install libsdl2-dev libsdl2-image-devOn Arch flavors of Linux:
sudo pacman -S sdl2 sdl2_imagegit submodule init
git submodule updateTo run the native code:
make local && bin/mainTo run the emscripten code: (brew install emscripten on Mac, pacman -S emscripten on Arch Linux):
make emscriptenand then tell the webserver to serve the files from www/.
My Emscripten-ed wasm output is on my web site.
I’ve also written a partial CMakeLists.txt file but am not using it yet.
The font included in this project is Droid Sans, under the Apache License v2. The ImGui library includes the Proggy font.