Multiple Canvas with Emscripten

915 views
Skip to first unread message

Alon Faraj

unread,
Apr 19, 2017, 8:14:28 AM4/19/17
to emscripten-discuss
Hi,

Is there a way to support multiple canvas in one HTML page?
Currently Im using 1 canvas but I want to handle 2 or more.

thanks for help

Jukka Jylänki

unread,
Apr 19, 2017, 10:38:22 AM4/19/17
to emscripte...@googlegroups.com
Yes, this is supported, but currently only with Emscripten's own HTML5 WebGL context creation API. Use the emscripten_webgl_create_context() function to initialize WebGL contexts on both canvases (give the ID to the specific canvases), and then use regular GLES2 functions to render. To choose which canvas to render to, call the make_current function to activate the canvas for rendering: https://github.com/kripken/emscripten/blob/master/system/include/emscripten/html5.h#L423.

--
You received this message because you are subscribed to the Google Groups "emscripten-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to emscripten-discuss+unsub...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Alon Faraj

unread,
Apr 23, 2017, 6:22:25 AM4/23/17
to emscripten-discuss
thanks, is there any example or documentation I can use?
not sure I completly understand how to do it.

בתאריך יום רביעי, 19 באפריל 2017 בשעה 17:38:22 UTC+3, מאת jj:

Jukka Jylänki

unread,
Apr 26, 2017, 3:16:24 AM4/26/17
to emscripte...@googlegroups.com
The concept of handling multiple contexts with emscripten_webgl_make_context_current() is defined to mirror the native APIs such as wglMakeCurrent() (https://msdn.microsoft.com/en-us/library/windows/desktop/dd374387(v=vs.85).aspx), eglMakeCurrent() (https://www.khronos.org/registry/EGL/sdk/docs/man/html/eglMakeCurrent.xhtml) and glXMakeCurrent() (https://www.khronos.org/registry/OpenGL-Refpages/gl2.1/xhtml/glXMakeCurrent.xml) so the scheme is identical if you are familiar with the native programming APIs.

For a code example, check out the test at https://github.com/kripken/emscripten/blob/master/tests/webgl_create_context.cpp (there are also other test files that use it, search for "emscripten_webgl_make_context_current" in files under the tests/ directory).

To unsubscribe from this group and stop receiving emails from it, send an email to emscripten-discuss+unsubscribe@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.
Reply all
Reply to author
Forward
0 new messages