is it possible to use the emscripten wasm port of sdl in cheerp?

207 Views Asked by At

I started using cheerp recently and I would like to know if I can use the emscripten SDL library in cheerp or if there is an SDL port for cheerp

1

There are 1 best solutions below

0
Carlo Piovesan On

Developer for Cheerp here.

Cheerp does not currently provide a compatibly layer for SDL, but it's possible to leverage DOM & JavaScript interoperability to implement one.

There are 2 possible approaches:

  1. main logic in C++, [[jsexport]] (see link) functions to be called from hand-written JavaScript
  2. main logic in C++, rendering logic also in C++ thanks to clientlib.h-style forward declarations.

C++ stubs to be put together in JS is probably the faster way to get started, but both options have their merits, depends a bit on what you are more comfortable working on.

I am not sure what you are trying to achieve, I have put out an example, based on this article: https://gist.github.com/carlopi/e06214ac66594d41cdfcbff7581ddd79

To note that Cheerp capabilities to compile also the JavaScript (glue-) code allow to have the total code to be roughly 2000 Bytes (1500 JS + 300 Wasm + some HTML), significantly smaller than the 100 000+ required by the Emscripten version in this case.

If you share code / other questions, I will be happy to help.