Is there any way of accessing canvas 2D context under C++ when using emscripten?
I'd like to be able to draw simple shapes/paths using canvas' api functions like lineTo
, fillRect
1d done, etc. (so basically use any of the functions listed here.
I will point out that I would prefer not to rely on SDL, but if it's the only reliable approach then is there a way to force it to compile to JavaScript so that the result won't use WebGL, but basic canvas api?
Or should I maybe do a simple mapping of the api functions following this suggestion: Calling JavaScript From C/C++ ?
Until anyone shares a better solution I will most likely do the mapping and share it here as soon as I'm done with it.
According to the Emscripten documentation you can use SDL with C++ to get at the canvas when you generate Javascript. The SDL conversion is implemented in native canvas calls.
From my understanding, SDL initialized with SDL_SWSURFACE
will created a "2d" context rather than a "webgl"/"experimental-webgl" one. Functionality can be seen in the sdl_rotozoom test or on GitHub: https://github.com/kripken/emscripten/blob/master/tests/sdl_rotozoom.c
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With