Can OF be compiled to webAssembly?

Hi, I know OF can currently be compiled to JavaScript using Emscripten.
And I wonder if it’s also possible to compile OF to webAssembly.

I learned from this website that webAssembly can use C/C++ APIs such as the C and C++ standard libraries, OpenGL, SDL, pthreads, and others, just as in normal C/C++ development .

If it is possible, would it be much faster to run OF on web browsers using webAssembly than using JavaScript? And would it still support all standard OF features such as ofFbo, ofTexure and ofThread?

Thanks a lot in advance.

webAssembly is build on the specification of asm.js. Emscripten is a compiler, and it can compile to asm.js or webAssembly.

This article explain how to use emscripten to create a web assembly module.
Note the -s WASM=1 flag

“An open source community project supported by Mozilla, Emscripten is a GCC/Clang-compatible compiler toolchain that allows building WebAssembly applications on the web. The main scope of Emscripten is support for the C/C++ language family, but because Emscripten is powered by LLVM, it has potential to allow other languages to compile as well. If your game is developed in C/C++ and it targets OpenGL ES 2 or 3, an Emscripten-based port to the web can be a viable approach.”


Actually, you can use webAssembly just as module, you still need javascript to load that module. In the future, you will probably not need javascript anymore, but for now yes, you need. More details in this recent post
What you can do now is to write a module in C++, c, rust or whatever, compile it (using Emscripten), and include it in your web application.

If you are interested in webAssembly, I suggest you to read this article serie, it is absolutely great:

1 Like

Hi @edapx Thank you so much for your answer! It was really helpful.

Hey @cuinjune, I’ve just read this issue

It looks like you’ve already found how to get there! did you find a way to compile it to WASM? I’m having some problems too.

Nope… I couldn’t even compile to normal emscripten as explained here.

It’s weird because I remember I ran the example successfully when I first tried out with the earlier version of OF 0.9 but now it doesn’t work.
Or it could be the OS, or the browser’s problem. I don’t know…
I use OF 0.9.8 on Mac OS X 10.11.6.