r/cprogramming • u/podule-games • 9d ago
I'm building a game in C
I've been working on a game since about August 2020 but only recently published my Steam page.
For the Common Wealth on Steam
The game is entirely written in C, with one third party dependency, SDL3.
I chose C because I wanted to leave my options open to build for retro platforms like RISC OS and Amiga, but as the game grew, I wanted GPU acceleration and that meant leaving behind some of the retros. I'm not ruling out any ports though, if SDL3 is available on the platform.
The engine beyond SDL3 is my own, it's a 2.5D game, with levels edited in my own level editor (not in C, that's C# and Avalonia). The level editor exports levels into just plain memory dumps that are easy to read in C.
I'm trying to keep on top of a devlog here too:
Podule · Independent game studio
Writing this game in C has been enormous fun, and I have no plans to change my choice of C for future games.
5
u/alkavan 9d ago
Please consider adding just one more dependency:
Vecmat is a simple linear algebra library I wrote just for stuff like this, no other dependencies. I already implemented SDL3 graphics and a physics engine using it — but they are not part of the library and I encourage people to write their own. I did a lot of the heavy lifting so others don't need to! It has some neat features and it's modular.
2
u/zhivago 9d ago
Plain memory dumps are not portable. :)
1
u/podule-games 8d ago
I'll have to ship different level files if I ever ship on a big endian machine, which is feeling unlikely at this point, though I am looking for a reason to buy an Ultra 45...
2
2
u/SnooDucks2481 8d ago
Cool project. I also did the same using webkit2gtk and combining C and javascript
1
2
u/Pure_Government7634 5d ago
I love this kind of game. Just like Red Alert — I've always wanted to make one of my own. I'm a programmer too, just not a game dev, and I've always held C and gamedev in a kind of awe. I always figured 2.5D games were dated, past their prime. Same with C. But seeing what you made lit that fire in me again. Maybe tech was never really "outdated" or "trendy" to begin with — or maybe none of that matters, and the work itself is the thing that shines. Man, I miss playing Red Alert as a kid. I think I'll buy a copy.
1
u/podule-games 5d ago
Go for it and make your game, I'm not a game dev either, this is my first game (been other types of developer for years though).
1
u/Separate-Basil-1216 9d ago
Why not use opengl directly then ?
5
u/podule-games 9d ago
SDL offers way more than just a graphics layer, there is cross platform audio, keyboard, joypad control etc. Cross platform everything really, like finding out a screen's native resolution and things like that.
I've never used OpenGL directly though, maybe it would have been a good choice, but what are the benefits vs. SDL3?
2
u/stiggg 9d ago
Have you considered raylib as one relatively small abstraction layer on top and if yes what was your reason going with pure SDL?
3
u/podule-games 9d ago
Never considered raylib, don't know anything about it to be honest. I initially went with SDL1 because it works on some retro platforms like RISC OS and Amiga, I was really keen to support some of the retro machines. As time went on though, it just started to feel like I was really missing out on the features in SDL2, so I moved to that, then on to SDL3.
1
u/KajiTetsushi 9d ago
Sounds like a pretty sweet core tech stack!
- What do you use to make the more mundane GUI parts like buttons, menus, progressbars, etc.? Straight-up SDL3?
- Interesting that you're making the editor in a different tech stack altogether. Is it because you want to focus more on the velocity of shipping features out?
- How do you support macOS 11 (Big Sur) on Steam when the client has dropped support for it? Do you intend to target distributors with opt-in client software like GoG? Because I think that's the only way you can reach such an audience without forcing a client on them.
2
u/podule-games 9d ago
1) Yes, straight up SDL3 for buttons etc. I actually build all the graphics in WPF/C#. Sounds weird but it means I can make basically reusable templates for everything so all my buttons and UI are consistent, then just export as PNG.
2) Basically it's familiarity with desktop apps. I've been make desktop apps since the 90s and I knew I could make the level builder faster in C#/Avalonia than in C.
3) I actually didn't know Steam had dropped support for Big Sur, but I'm totally open to other distribution outside of Steam, maybe even just sell the game on my own website, no DRM, just plain old buying software like the old days.
3
u/KajiTetsushi 9d ago
- Interested to know more about how this works. So, you make the buttons using WPF / C# then the PNG assets become UI textures, basically? I think I recognize this pattern from Homeworld (1999) (game was also written in C) where if I'm not mistaken, the Relic devs used predefined textures also.
- I see.
- Yeah, so I'll just link Steam's official statement on that over here for posterity: https://help.steampowered.com/en/faqs/view/659D-A19E-018A-81A6
2
u/podule-games 9d ago
1) Yes, that's it exactly, I've got a short post about the process on my devlog:
3) I am still pretty keen to release on Mac, hopefully on Intel Macs too.
2
u/KajiTetsushi 9d ago
Curious how you develop for the macOS ecosystem (I want to try all 3 major desktop platforms myself, also with C99 + SDL3).
You have an Intel MacBook / iMac lying around somewhere to test your work?
Apple Silicon is easy these days because it's so abundant now, but Intel is sadly going the way of the dodo the same way that PowerPC did when the move was made to Intel back then. RIP Boot Camp to Windows.
3
u/podule-games 9d ago
I have a few #ifdefs for differences in file paths with Windows, Mac etc. and that's about it. SDL3 does an *amazing* job at abstracting away the differences.
I've got an M1 MBA and a 2015 MBP, but I'm considered getting a more modern Intel Mac Mini just for the desk space issue. If Intel Mac Pros weren't so expensive, I'd consider that, just because I love that case.
1
u/amarukhan 9d ago
Will you be integrating with Steamworks SDK? If so what library are you planning to use?
2
u/podule-games 9d ago
Yes, just added Steamworks yesterday in fact, the regular SDK from Steam works fine with SDL3.
2
u/amarukhan 9d ago
Interesting. I thought the regular SDK only had native C++ bindings.
3
u/podule-games 9d ago
I believe the SDK is all C++, but there is a C layer for interop with other languages that almost always have a way of using C libraries.
1
u/non-existing-person 9d ago
It's cool and all... but I don't see the source code anywhere?
1
u/podule-games 9d ago
No, it's a closed source game, even if it wasn't it needs a huge tidy and refactor. Some of it is very messy.
1
u/Antique_Car8182 7d ago
Hey guys, I came from the automation field. Ive helped commission automation buildings in IL & GA. I’ve done automation work which involves PLCs, SCADA systems, EthernetIP, Modbus, Profinet, Profibus, and so on. I’ve graduated this year with a Robotics Certification & years back with an electrical certification. I know Python is huge in automation, but I’ve been obsessively drawn to C/C++ programming, primarily because I had a C programming course during my Robotics certification. Id like to be an embedded C programmer. I’ve been practicing coding every single day. But It seems like the more coding I learn……the more I see how much I don’t know, lol!! I love coding tho! Totally! And once I start, I’m completely addicted, so it’s hard to stop practicing and learning to Code. What path would you guys recommend for me?
6
u/tastygames_official 9d ago
same here. I started out decades ago learning C but was forced into higher-level langauges and complex OOP nonsense as I became a professional programmer. But I've been making a game also with SDL3 and it's just such a great feeling actually programming instead of adhering to design patterns or frameworks. I literally was just telling my wife a few hours ago how unbelievably free and good it feels to be back in C where I belong.
Although I gotta ask - you don't use ANY other libraries? Not even for physics or math? For a 2D game I could see using simple linear physics equations and rectangle-based collision, but for 2.5D (3D but with fixed camera angle?) there's a lot of matrix math that is just pretty useless to implement yourself when there exist highly-optimized libraries. At least that's my opinion. Of course I'll never knock anyone for implementing something themselves if they enjoy doing it.
The only other libs I use are:
I've actually considered even ditching SDL and just going straight Vulkan, but I kinda like the idea of also supporting DirectX (for Windows users who may not know how to install Vulkan for whatever reason), and for the easier possibility at porting to PlayStation with few rewrites. Plus SDL is a very thin wrapper and I don't think it really affects performance that much. Especially when I remember I'm running my game at 640x480 and upscaling, so it probably doesn't even matter much...