Thanks to Emscripten, it is possible to convert C++ and OpenGL into WASM and WebGL in order to run in the browser.

Installing Emscripten

Note that the following has been tested on macOS (intel) and Linux (Ubuntu 64bit.)

  1. Get the emsk repo
    git clone https://github.com/emscripten-core/emsdk.git
    cd emsdk
    
  2. Download and install the latest SDK tools
    ./emsdk install latest
    
  3. Make the latest SDK active for the current user
    ./emsdk activate latest
    
  4. To be done each time a terminal is started:
    export EMSCRIPTEN_PATH=path/to/emsdk/upstream/emscripten
    cd $EMSCRIPTEN_PATH
    source ../../emsdk_env.sh
    
  5. In order to test Emscripten, and to install zlib port:
    cd $EMSCRIPTEN_PATH
    emcc test/hello_world.cpp -s USE_ZLIB=1
    

    If it’s not working, you’re maybe using an older version of emscripten. Try:

    emcc tests/hello_world.cpp -s USE_ZLIB=1
    

If you haven’t done so yet

Assuming that you have followed the steps described in the prerequisites part of Hello, world

Clone the repository:

git clone --recurse-submodules https://github.com/arielm/chronotext-cross

To be done each time a terminal is started (will set the CROSS_PATH variable):

cd path/to/chronotext-cross
source setup.sh

Building the chronotext-cross library

cd $CROSS_PATH/core/src
./build.emscripten.sh

It must be done the first time you clone the repository, or when you pull from the repository, or after you make your own changes.

TL;DR

Pick an application from the tests folder, then build and run it, e.g.

cd $CROSS_PATH/tests/TestingTriangle
RUN_TEST -DPLATFORM=emscripten

It should open a new Safari browser and show a nice colored triangle. If you want to use another browser, edit this file accordingly.

The resulting .wasm, .js and .data files will be in build/emscripten.