Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

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.

like image 856
Konrad Madej Avatar asked Jun 16 '13 09:06

Konrad Madej


2 Answers

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.

like image 81
Jonas Schubert Erlandsson Avatar answered Oct 20 '22 12:10

Jonas Schubert Erlandsson


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

like image 25
Mike Weir Avatar answered Oct 20 '22 13:10

Mike Weir