Emscripten - C++ with pure html5 canvas support (not WebGL)

Konrad Madej picture Konrad Madej · Jun 16, 2013 · Viewed 7.5k times · Source

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, fillRect1d 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.

Answer

Jonas Schubert Erlandsson picture Jonas Schubert Erlandsson · Jun 24, 2013

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.