Tech stack - Graphics API and wasm


For this project I was looking for an abstraction API over the different OpenGL implementations so that I don't have to write my code twice, and that would compile to both native targets and web (via wasm). In C++ land you would use something like SDL, BGFX or my favorite, Raylib to do this. In pure C# land this a big pain point.

Libraries like OpenTk and Silk.Net could theoretically support wasm targets (from the same codebase as OpenGL targets), but they currently don't. It is planned for a future version of Silk.Net, but judging by the slow development speed it might take years before it's ready.

Then there's Monogame and its derivatives. It could theoretically do it, but there has been little interest from the maintainers for this feature in the last decade. But the first ray of light pops up from KNI, a fork of Monogame which has a few browser based games on itch. It manages this by implementing bindings to Web APIs under Monogame's abstractions. Unfortunately it seems very Windows focused and I couldn't get it to run from my Linux machine in a reasonable time.

Then there's the possibility of using bindings to native libraries like SDL2 and Raylib which works... surprisingly well! When the native libraries get compiled, Emscripten searches for OpenGL ES calls and replaces them with WebGL calls. This is surprisingly transparent and works well for you in C# land, provided you can get a compiled version of the library. It also somehow manages to work well with input (I haven't tried audio yet). 

So far this is the approach that I like best, and although I was curious to test SDL, it has a bit more boilerplate than Raylib for the same things, so I will stick with Raylib, as I have not had any issues with it until now and I don't really see a reason to switch. So for now I have a prototype running with one project for managed, desktop compilation, one for wasm compilation, and a shared library project where most of my game logic will go into.

Given how popular C# is in the gamedev world, this is a pretty weak point of the open source ecosystem outside of the closed source Unity engine (which still dominates as far as cross platform is concerned), and Godot C# (which has stopped working on the web since the 4.0 release 2 years ago, although for different reasons). Although the Java world has fewer options, LibGDX seems to have good support for web targets and the engine has some very welcome features and tools, while being OSS. On the flip side, console support is the pain point there, apart from, you know, being Java. LWJGL is also battle tested on many devices through its use in Minecraft.

Now enough talk and setup, let's get into rogueliking!

Leave a comment

Log in with itch.io to leave a comment.