I wrote this in 2018; it doesn't work reliably anymore. but see https://github.com/redblobgames/helloworld-sdl2-opengl-emscripten for the version I update.