Yes, that's essentially what I've done here:
https://floooh.github.io/virtualkc/
The emulator is written in C++ and the emulator framebuffer is rendered via
OpenGL calls through emscripten's GL-to-WebGL wrapper.
The buttons on the left border are done via regular handwritten HTML5+CSS,
and there's also file drag'n'drop implemented in Javascript via the HTML5
drag'n'drop API. The C++ emulator code exposes a few C functions to the
Javascript side to "remote-control" the C++ side from the JS side.
For instance: you can open the browser's devtools JS console and type
"yakc_toggle_crt()", this is a C function which is made visible to JS via
EMSCRIPTEN_KEEPALIVE, and which toggles the CRT shader effect on and off
(all implemented on the C/C++ side), and the HTML5 "CRT" button in the
bottom calls this function in its onclick handler.
The starting points in the emscripten docs for this type of stuff are:
- EMSCRIPTEN_KEEPALIVE (make a C function visible from the Javascript side)
- EM_JS and EM_ASM ("magic" C macros to embed Javascript code into C code)
-
https://emscripten.org/docs/porting/connecting_cpp_and_javascript/Interacting-with-code.html
- emscripten also has C wrapper functions around some (but not all) HTML5
APIs (for getting input events
etc...): https://emscripten.org/docs/api_reference/html5.h.html
...but in general, all of this is also possible to do yourself via
EMSCRIPTEN_KEEPALIVE and EM_JS, the emscripten-provided functions just also
handle a lot more edge cases. But understanding the low-level
"do-it-yourself" approach is important for HTML5 APIs that are not covered
by emscripten (for instance drag'n'drop).
Cheers,
-Floh.
On Friday, 30 October 2020 19:15:59 UTC+1, Alessio Mochi wrote:
>
> I would like port my opengl application on web with emscripten.
> It's possible use a css web gui with emscripten and to do the opengl
> rendering is in the c++ side? I have seen some examples and that there is
> an html5 library but I don't understand how I can capture events like html
> button clicked and connect this event to the main loop in the c ++ side.
>
> Thanks in advance
>
--
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 [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/emscripten-discuss/23f9329b-c4ec-404e-a2e5-391a81494e90o%40googlegroups.com.