Emscripten - Introduction to cross platform game development
In this post I’m showing some tests with Emscripten for cross platform game development!
If possible, I’ll start to code a game engine soon, focusing on the cross platforms and something easy to use! Until them, take a look in some Emscripten samples!
I - About Emscripten
Emscripten makes native code immediately available on the Web: a platform that is standards-based, has numerous independent compatible implementations, and runs everywhere from PCs to iPads.
II - How it works
III - Let’s test Emscripten
First, just check this link on how to install Emscripten. Now, let’s create just a hello world to test if it’s working. Code a classical hello world with C/C++, like this one. Save the file as hello.c:
When using gcc, or g++, you just need to call
With Emscripten, we do the same, but now we use emcc or em++ To build run:
You can run your hello.js with node, spidermonkey or any others js tool. Or just open the hello.html in your browser.
IV - OpenGL hello world
Emscripten supports the WebGL-friendly subset of OpenGL by default. This is the set of commands that map directly to WebGL, so that each GL command becomes a direct call to WebGL. It includes almost all of OpenGL ES 2.0, with the notable exception of client-side arrays. I just created a c++ file called sdl.cpp, with the code:
On linux, I can build and run it with:
But now, to run this same code on the web, I just need to compile it with Emscripten, like this:
And here is the output:
Very very nice!
V - My goals
Ok, now I’m doing some extra tests and if possible, I’ll start to work in a very interesting project. I’d like to create a cross platform game engine with Emscripten! I’m defining how it will works, but it’ll be probably running with C++ code and then you can build it for mobile devices and if you want to, built to the web with Emscripten. I’m doing some tests with SpiderMonkey too, so maybe this game engine can be packaged with SiderMonkey. So you code your game in some programming language - need more tests to define one - and them you just build it across devices!
Thanks for reading,