Skip to content

Instantly share code, notes, and snippets.

@cchudant
Last active October 1, 2018 00:39
Show Gist options
  • Save cchudant/287e6d33e57a4a00728bab98c0f71c15 to your computer and use it in GitHub Desktop.
Save cchudant/287e6d33e57a4a00728bab98c0f71c15 to your computer and use it in GitHub Desktop.
Build sdl2 for the web
#!/bin/sh
emcc *.c\
-O2\
-s WASM=1\
-s USE_SDL=2\
-s USE_SDL_IMAGE=2\
-s USE_SDL_NET=2\
-s ALLOW_MEMORY_GROWTH=1\
--use-preload-plugins\
--preload-file resource\
-o target/index.html
# after building, target should have 4 files:
# - target/index.html -- the generated html web page
# - target/index.data -- the generated compressed assets
# - target/index.js -- the generated javascript
# - target/index.wasm -- the generated webassembly binary
<!DOCTYPE html>
<!-- Optional custom mount page -->
<!-- To use it, compile with `-o target/index.js` and put this file in `target/` -->
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
</head>
<body>
<!-- The canvas where the game will be drawn into -->
<canvas id="canvas" oncontextmenu="event.preventDefault()"></canvas>
<script type="text/javascript">
var Module = {
canvas: document.getElementById('canvas')
}
</script>
<!-- Generated by Emscripten -->
<script src="index.js"></script>
<p>SDL2 for the web exemple</p>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment