Emscripten is a compiler that translates code written in C and C++ to WebAssembly, or to a subset of JavaScript known as asm.js
).
Applications compiled with Emscripten are more performant and therefore faster than interpreted or dynamically compiled JavaScript.
How to install Emscripten
Dependencies: CMake, gcc and Python.
On Unix-based systems:
Test with the command:
If using Windows, see here.
Example of use
Suppose you have this code:
main.cpp
Save this image:
Compile and run:
Need SDL2 installed!
Modify the code above and make it look like this:
Compile with the following command:
Create a new index.html
file and insert this content:
If the file already exists, remove all content from it and paste this code inside.
And now view and use in your browser!
After running this command the game will automatically open in your default browser.
For more information visit the official website of Emscripten:
gamedev
cpp
sdl2
web
Marcos Oliveira
Software developer