A 3D Voxel Game in C
My Basics of Programming project: a 3D platformer in pure C with SDL 1.2. Destructible voxel terrain, flying enemies, and a renderer derived on Post-it notes.
2026 update: I haven’t used Windows for a long time now and I’ve been wanting to play with this game again (the game binary was only compiled for Windows). Previously, I couldn’t be bothered to migrate it to SDL2, however, now I could finally just one-shot this migration with an AI agent. So my game from 9 years ago is playable again at schmelczer.dev/platform-game1.
I titled my first proper university project Platform game. I’ve clearly come a long way since then, yet one thing hasn’t changed: I’m still bad at naming things. Back in 2017, I created an actually fun 3D game in pure C with the help of SDL2 1.2.
I’d wanted to build it ever since I first downloaded GameMaker3 and realised that I could make a video game. I’d already tried with Avoid4, and Platform game is essentially its upgraded 3D version.
The maps are randomly generated, but every jump remains possible under the player’s gravity and jump-strength settings. The world is also fully destructible, voxel by voxel. You can build structures to hide from flying enemies, although once they merge and grow large enough, they can destroy the terrain too. After collecting enough power-ups, you can shoot back or trade points to slow down time.
One feature I distinctly recall is the save file format. Initially, it dumped the entire procedurally generated map into a file, so one save file could reach hundreds of megabytes. I eventually discovered run-length encoding5, although I later learnt I wasn’t the first person to come up with it. Each map has long runs of similar voxels, mainly air at the top and ground at the bottom, so the encoding massively reduced file sizes.
One thing I didn’t discover during this project was how to do computer graphics properly: I settled on a software renderer capable only of drawing cubes and derived its 3D-to-2D projection using trigonometry and a lot of Post-it notes. Doing it properly had to wait a few more years for a 2D ray tracer6.
I’ve made the source code public, more as a reminder to myself than as something others should learn from. The project is neither elegant nor efficient, but it produced a genuinely fun game and it made me fully realise my passion for programming.
- https://schmelczer.dev/platform-game↩
- SDL: https://www.libsdl.org/↩
- GameMaker: https://gamemaker.io/↩
- Avoid: https://schmelczer.dev/articles/avoid-early-web-game/↩
- run-length encoding: https://hydrolix.io/blog/run-length-encoding↩
- a 2D ray tracer: https://schmelczer.dev/articles/sdf-2d-ray-tracing/↩