tl;dr Deploy games written in C++ and OpenGL via WASM + Electron

About

I like to propose an idea for (small) OpenGL games written in C++

Custom C++ engine using OpenGL feels deprecated

A few years ago I wrote a custom engine, using C++ and OpenGL. It’s been a fun project and back then the decision to use OpenGL felt just right: it’s supported by Android, iOS, Windows, Linux and even macOS. Consoles aside: the major platforms.

However, things have changed. Considering what happened the last years I’m not so sure OpenGL has a future. Apple focuses on Metal, Microsoft on DirectX and there is Vulkan.

Especially when targeting desktop machines there might be a time when OpenGL support is an issue. Rewriting the code to Vulkan is possible but lots of work and I really feel Vulkan is more for big teams than for small projects. Using an engine like Unity would be an option but imposes a horrible vendor lock and throw out the C++ part.

Do it the crazy way :-)

Especially for small projects I think there is an option that is not just crazy but also fun and might even have a future: WASM + WebGL + Electron

Adjust the existing code base to work in a WASM + WebGL environment, pack it into a Electron application and by that use the entire power of the recent years of browser development. Electron is based on Chromium and it means that you will get maybe the best OpenGL emulation in the world: the one from Google. It is likely that they’ll support WebGL for a long time and make sure that it works perfectly. A solid and stable browser is one of Chromes major goals, after all :).

The packaged application should be easy to deploy. Electron is already used by game developers and it should be possible to inject things like the Steam API (check out this: greenworks). Another nice thing is that you only need to build the application once on a machine of your preference. Once the WASM solution is setup you don’t need to figure out how to compile all those C++ libraries for the other platforms anymore because WASM serves as a middle man. You only have to build the Electron application for the target platform.

WASM + Electron
WASM + Electron

Once setup it should be highly compatible. The main reason for that is the fact that Electron brings it’s own browser. This allows you to test the entire software stack before deployment. You only rely on things you ship. This is a major difference to solutions like Cordova where you have to hope that the target operating system has a compatible web view for your game. In many ways this is a traditional workflow only that we rely on Google to write proper browser and emulation code. Which they’ll probably do :).

Grain of salt

There are some things I left out here: performance, OpenGL != OpenGL ES, things like files API and debugging. If the game makes heavy us of APIs that are bound to a specific operating system than those need to be rewritten.

However, I still think it’s an interesting approach.