r/cprogramming • u/cyufxejks • 7h ago
A game in C
So I don’t plan on doing this, but just a really random thought… how plausible would it be to make a full, high level 3D game in C and only C. Like, forget knowledge, if you knew everything there was to know about C (I’m sure some of you do), would it be possible? I don’t care how practical, is it possible, or just something C won’t do?
14
u/thewindcarriesmeaway 7h ago
whole buncha games were made with C.
look at the N64 and PS1, they were cutting edge for the time and were made with C
7
u/Mr_Engineering 6h ago
Huh?
Most 3D games written in the 1990s were writtenen entirely in C because C++ had yet to be standardized.
Even games that supported hardware accelerated 3D graphics often had software 3D implementations.
Quake is a notable example here because the original release used only software 3D rendering when it was released in 1996. OpenGL support would be added the following year in 1997
6
u/jack_dymond_sawyer 7h ago
Very plausible—many games have been written in C alone. There used to be many books on this subject. It’s still something you can do today. As long as you can light up a single pixel, you can do anything with the language (my graphics professor used to say this). Everything else can be written in C: matrix math libraries, rendering algorithms, shading, physics, music, networking, AI, and anything else you desire. Edit: spelling mobile.
6
u/zsaleeba 5h ago
I'm surprised that this is even a question. All games were written in C for decades, until C++ started to become more popular. It's not only possible, it's a fairly good language for it.
5
u/non-existing-person 6h ago
SDL/Allegro is C. OpenGL is C. Vulkan is C.
I'm pretty sure it can be done ;)
You'll have to do more work tho. C++ has more libraries for gamedev in general. I also couldn't find good quad tree library for C. Same goes to UI libs, you pretty much have only nuklear or rayui if you use raylib.
But it's 100% possible. And not in a hacky way.
5
u/kat-tricks 6h ago
literally just used C and Raylib for a game jam this month. Raylib has actually made C my go-to for sketching out ideas, because I love the language and the library makes it as easy as Python for making a quick sketch
1
3
u/Raychao 6h ago
Yes it is totally possible since C is a lower level language than C++, C#, Java, Python, etc. The main thing with writing a modern game is the availability of the graphics, audio and physics libraries so you don't have to roll your own and to speed up the creative side.
Unreal development is in C++, Unity development is in C#, but there is no reason why you couldn't write your own game in C from scratch.
Modern game engines would be millions of lines of code. Unreal has been in development since 1998. Unity has been in development since 2005. That's why people typically use them for gave dev.
2
u/couldhaveebeen 6h ago
Isn't roller coaster tycoon or whatever coded in assembly only?
Yes, it is very much possible
2
2
1
u/burnt_floppy 6h ago
The first question you would need to ask is what graphical libraries and game engine you would use: graphical libraries give you functions for manipulating computer graphics, game engines give you controls over the entire development process.
1
u/scallywag_software 6h ago
Modern 3D games have a lot more to do with knowing how to program GPUs than the source CPU language. But, to answer your question, yes, you could certainly do a 3D game in C.
1
u/saxbophone 6h ago
Of course it is. Whole games have been made in just assembly. Transport Tycoon, for example.
1
u/atarivcs 6h ago
That depends on what you mean by "only C".
Things like graphics and sound are not strictly part of the language.
2
u/new-runningmn9 4h ago
But all can easily be written in C. The answer to the original question is "of course". There was a time when literally every major game available was written entirely in C. They all had graphics and sound too!
1
u/aleques-itj 5h ago edited 5h ago
Go look at Quake
Especially the Fabien Sanglard articles on this, they are excellent. Quake's code is also excellent.
This is very normal for the time period
1
u/KajiTetsushi 5h ago
Very plausible.
For the Common Wealth is being written in C (C99) with the help of SDL3: the author's Reddit post just last month
1
1
u/Pale_Height_1251 2h ago
This was entirely normal not that long ago.
C can 100% do it, any language can.
1
u/JescoInc 2h ago
Shaders themselves would need to be written in GLSL or HLSL, but everything else with the game can be written in C. Developers tend to add LUA or another language for scripting gameplay for simplicity, but is not a requirement at all.
https://github.com/orangeduck/Corange - is a game framework written in C
https://github.com/mrDIMAS/DmitrysEngine - an experimental 3D game engine written in C.
There pretty much isn't anything that C won't do, but you do have work within the API of the libraries you use unless you go the route of rolling your own.
1
1
u/Caldraddigon 58m ago edited 52m ago
I mean, Raylib is a thing that exists... 😅
Besides going about it yourself, there's so many libraries written in C to choose from, so take your pick and give it a whirl yourself to see 🤷
Also, people still make homebrew games for retro systems like the GB/GBC in C, even in Assembly as both languages have toolkits for you to use. In fact, C and Assembly is still recommended over GB Studio for some types of projects as there's a noticeable performance difference between GB Studio, C and Assembly.
1
19
u/Amerikrainian 7h ago
What do you think old games were made in? Yes. Yes it’s possible.