r/C_Programming • u/TachyonFireGame • Jul 27 '26
Lessons learned from making a game/game engine in C
Github: https://github.com/Krobenlakroc/tachyonfire
In about 2020, my *other* C game engine had become too convoluted to be able to finish any projects and I wanted to venture into more modern rendering techniques so I decided to start on a new one.
Now 6 years later, I am done.
Expanding my C skills and learning graphics was challenging, but I found the process of making something that works on a variety of machines to be extremely painful.
In this post I'm going to go over the pitfalls I ran into.
1.) On Linux, newer glibc is backwards compatible with builds of older glibc but not the other way around. This really sucks because that means if you want to make a build that works on machines older than yours, you need an environment with older glibc.
That is a huge problem, because an older linux distro also has and older compiler from the package manager so newer compiler flags like x86_64-v3 don't work. The workaround for this is building in a debian buster container, downloading a builder a newer gcc, and then using that to compile the game.
Also keep in mind that your libraries will need to use the older glibc version as well, but they can be compiled with the older compiler.
2.) I don't use windows much so making a windows build as someone who learned programming in unix land is a challenge, the msvc interface is alien to me. I found MSYS2 to be easy to use for doing the port.
Windows is nicer to work with than linux, because you can compile against UCRT (universal C runtime) and it just works. The bad news is, there are some types that are different sizes on linux and windows.
If you are reading from a binary file that you generated on linux and you didnt use stdint.h types, you are screwed (but only some of the time not always).
3.) More windows stuff. If you include <windows.h> it pollutes the namespace with a lot of differnt macros that might conflict with your macros or types.
"TokenType" was the one i ran into. This is bad.
4.) Mysterious crashes, this is more common knowledge but i'll include it anyway. I found a lot of "silent" bugs using valgrind, asan, ubsan, and tsan (not all at once). In my experience windows is more sensitive to memory errors than linux, so using these tools is a must if you want to avoid headaches later.
5.) Compiler bugs, I ran into one using an older version of gcc. I was so confused, and it really stressed me out. If you run into something baffling when you change compilers, it might be the compiler.
6.) When testing, you need to make sure that what you think you are testing actually runs. I didn't write a single unit test for the entirety of development, I just tried to play the game in the debugger with some printfs to see if edge cases are being hit during testing. I think it worked out ok.
7.) fopen(). fopen accepts UTF-8 on linux, but not on windows unless you change the locale and you are using a new enough version of UCRT. Windows has its own _wfopen() that takes in wchar_t, so you need to convert to wchar_t using windows' api functions in case the file path includes a non ascii-username.
If you remember one thing, remember this: test across a matrix of different machines.
Laptops, Desktops, AMD/NVIDIA/Intel, different compilers, different operating systems.
Its the only way to truly be sure your app has broad compatibility. Don't trust your development machine.
2
u/False-Dealer-6399 Aug 02 '26
First and foremost, Congratulations 🎊. Second, I want to start C learning journey and I was wondering about where to start, what to read and how to practice C? As someone who looks to have greate experience in C, how would you help me get started? (My goal is to use C for CyberSecurity)
18
u/ewmailing Jul 27 '26
Nice video demo.
Just a tip for your bullet point 1. Steam Runtime is intended to help with this problem. It allows you to create and run inside a containerized environment on your Linux computer that comes with a preinstalled with core dynamic libraries such as glibc and SDL plus compiler tool chains that all match up. The runtime matches what Steam Client itself ships and runs Linux games in, so any player launching their Linux game through Steam gets launched in this container environment and will have the correct glibc version and associated system libraries, and the libraries/executables you ship with your game will also resolve to this runtime.
The first version of the runtime was built around something like Ubuntu 12.04, which was old even when it came out. So you could feel the pain of having such old gcc and clang versions among many other problems. But it also had the advantage that if you could make it work, that environment was so old, binaries could be run directly on any current glibc based Linux distro, sort of like what you figured out for yourself.
Since then, they have added additional Steam Runtime versions, with each sporting a newer version of glibc and compiler versions.
https://github.com/valvesoftware/steam-runtime
But it is still a PITA that developers have to deal with this and depending on if you need to push the envelope on the dependencies you need, you still can hit painful edges. So I can sympathize with developers that say screw it and say the Win32 ABI + Proton is the best solution for Linux.
32
u/green_tory Jul 27 '26
The libc issue can be worked around with AppImage, FlatPak, and Steam Runtime targets.
11
u/murphinate Jul 27 '26
Not a C Programmer, but this was in my feed. This game actually looks pretty fun, the movement reminds me of Starsiege Tribes from back in the day.
6
u/Vistril69 Jul 28 '26
Now this is real cool. Amazing work and you're an honorary scientist and engineer for doing all this.
I have one and a half maybe two questions:
How'd you stay committed? And how'd you do it despite the struggles you mentioned and perhaps on top personal ones too?
5
u/ArtichokeOk2684 Jul 28 '26
WHAT IS GOING ON
3
u/licjon Jul 28 '26
What was the motivation to make this? Did you want to make a Linux-first engine or was there something particular to FPS games that you wanted to do better? I am curious but do not know game engines well enough to tell based on your readme's feature list.
2
u/tastygames_official Jul 28 '26
I'm just getting started writing my own engine in C using SDL3. Thanks for the pointers and for open-sourcing your code. I'm interested to see your implementation of the defered rendering pipeline.
4
u/rodrigocfd Jul 28 '26
Dude, if you're talking about Visual Studio (not VSCode), let me tell you that's the finest C++ IDE ever made. It can handle humongously large projects, and the debugger is just stellar. Maybe you just need some time to get used to it.
Probably won't fully fix your issues, but there are a few ways to alleviate this, like defining
WIN32_LEAN_AND_MEANandNOMINMAX.1
u/d954mas Jul 29 '26
Looks awesome, thanks for sources, i hope to find something interesting to inspired) my engine need a lot of work)
1
u/nomatepa Jul 31 '26
This is really impressive stuff to write in C. Do you mind sharing what your background is? How long have you been programming in C to get to this level?
1
u/ZealousidealRaise537 Jul 28 '26
Couldn’t you just develop for windows and then use proton on Linux? Sounds like less of a headache to me.
-1
u/HealthyCapacitor Jul 28 '26
There are very weird points, why would older glibc be forward compatible?? Also a custom libc is linkable at any time. And everyone knows writing a custom "windows.h" header with only the things you need is the way to go, why complain about it?
-3
u/SupernovifieD Jul 28 '26
I’m not a C programmer. But I just wonder what impact agentic coding has had on C programming. Is AI good in handling C and helping you core, debug, reiterate, and generally develop faster?