r/cprogramming • • 27d 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?

50 Upvotes

68 comments sorted by

75

u/Amerikrainian 27d ago

What do you think old games were made in? Yes. Yes it’s possible.

41

u/thewindcarriesmeaway 27d 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

28

u/Mr_Engineering 27d 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

20

u/zsaleeba 27d 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.

14

u/kat-tricks 27d 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

4

u/Gold-Part4688 27d ago

the header file is also amazing

26

u/costajr 27d ago

Doom engine, ID Software, John Carmack.

9

u/jack_dymond_sawyer 27d 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.

7

u/non-existing-person 27d 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.

2

u/tastygames_official 27d ago

no, there are way more UI options than that:

- https://github.com/webview/webview (compiles C++ only, but with C bindings - actually, if you include this, then basically any UI framework is available if it offers C-compatable headers or if you write your own)
- https://www.nappgui.com (cross-platform native OS GUI in C90)
- https://github.com/SamuelMarks/c-multiplatform (same thing as above, but uses HTML rendering)
- https://www.tecgraf.puc-rio.br/iup (cross-platform native)
- https://github.com/nicbarker/clay (C LAYout library)

I've found more in my research, but only these seemed interesting enough for me to write down.

7

u/Low_Lawyer_5684 27d ago

Quake1, Quake2 and Quake 3 Arena were written in plain C. Nowdays people choose C++ mainly because:

  1. "No bro, a game in C? No way, use C++!!! C is an old language"
  2. "Uhm.. physics engine, sound engine and whatever engine component of our game is C++ libraries"

6

u/Raychao 27d 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.

6

u/CS_70 26d ago

What do you mean “plausible”. That’s how games were chiefly made and many still are.

4

u/71d1 27d ago

It is possible and has been done before.

4

u/tpimh 27d ago

There even modern 3D engines that are written entirely in C: Corange, Permafrost Engine, Dmitry's Engine. None of them are as popular as raylib, but it's hard to classify this library as an engine, however it can do 3D.

4

u/johan__A 27d ago

Animal well is written in C (well actually c++ but with barely any c++ features being used) and only two simple libraries being used for loading image files and audio files.

3

u/couldhaveebeen 27d ago

Isn't roller coaster tycoon or whatever coded in assembly only?

Yes, it is very much possible

3

u/ForeignExercise4414 27d ago

Very possible, look up how Roller Coaster Tycoon was made

3

u/burlingk 27d ago

There are a number of well known graphics and audio libraries all written in C.

3

u/Chickfas 27d ago

Yes! Try raylib, its fun

3

u/GodOfSunHimself 26d ago

Quake was written in C. It is open source and the code is amazingly well written. Go check it.

1

u/FederalProfessor7836 25d ago

I’ve been working with the Quake source for 20 years or so and have hammered it into something a bit more modern, consistent, with tests, etc.

https://github.com/jdolan/quetoo

2

u/saxbophone 27d ago

Of course it is. Whole games have been made in just assembly. Transport Tycoon, for example.

2

u/aleques-itj 27d ago edited 27d 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

2

u/KajiTetsushi 27d 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

2

u/Pale_Height_1251 27d ago

This was entirely normal not that long ago.

C can 100% do it, any language can.

2

u/Zerf2k2 27d ago

As an industry veteran of 20+ years, I've started with it already for the next project 

2

u/NaturalTechnician737 27d ago

Yes, perfectly doable!

2

u/Caldraddigon 27d ago edited 27d 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.

2

u/neopunk2025 27d ago

Sans problème. Mon prochain jeu uniquement en C.

1

u/scallywag_software 27d 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/atarivcs 27d ago

That depends on what you mean by "only C".

Things like graphics and sound are not strictly part of the language.

3

u/new-runningmn9 27d 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/mostrecentuser 27d ago

If you have enough time, you can make anything from scratch.

1

u/JescoInc 27d 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

u/tastygames_official 27d ago

I'm doing that right now. In fact, I'm doing it in C90. I'm using SDL3 which actually compiles in C90 mode! I've had to copy some functions (like standard matrix manipulation functions from math libraries and image manipulation functions from image processing libraries) and modify them to get them to be C90-compliant, but so far so good. I've not yet done the physics engine, which I'm kinda worried about since there seem to be no C90-compliant physics engines for use. But Box3D is C17 so maybe I can compile in with C17 and just modify the headers to be C90-compliant. Although I just now see that the author disclosed non-trivial LLM use (the migration of Box2D->Box3D) so might have to avoid that. But there are C physics engine options out there. Then for sound there's simple C libraries to do 3D sound, and there are C libraries to do whatever it is you want to do (parallelization, glTF, vector math, etc).

1

u/friedent 26d ago

much of c++ library are written in c, and the key of these questions is just about the "compiler" itself. for me the reason ppl prefering the c++ bcs it has more 'plus-point' rather than c, like the smart-pointer, oop, lots of methods & generics. and other stuff that was made and optimized to fix the downside of this C lang. and it was an oportunity for ppl to make their project

right now I'm waiting for the zig lang or c3 to be released, bcz it such a pretty language, a lot of stuff are still work-in-progress and hopefully they can make it faster. especially zig (I've try it and there is literaly usefull stuff happens. but unfortunately the documentation and breaking changes really make me annoyed)

1

u/Scheibenpflaster 26d ago

yeah sure (I do 2d but this also applies for 3d)

Raylib already takes care of all your media needs except cutscenes and there are examples for that

My Levels are structs with function pointers pointing to the update and draw functions + a void pointer pointing to level data. I just store that globally as you'll want it everywhere anyways. I Structure them as an ECS which tends to play nicely with C as the data is fairly flat. Each component array is a textblock that stores csv-rows containing key-value pairs. It's human readable like a json but infinitely easier to work with in C. Tradeoff is no nested structures but the ECS makes sure you don't need them

For physics there is box3d or you could implement "Detailed Rigid Body Simulation with Extended Position Based Dynamics" by Müller, Macklin et al. It's ez if you omit the rotation part. Just make sure you don't use Raymath or Raylob vectors for that as they uses floats and the physics library is somewhat susceptible to floating point inaccuracies. Like you can't make bodies stop through forces relative to the velocity without a minimal supported step and with floats that step is too big

1

u/YakubReddit 26d ago

Rollercoaster Tycoon was made in assembly so yes, it's possible You loose classes, raii, generic types etc. But I find it more intuitive, especially with structs (and anonymous structs)

1

u/realmauer01 26d ago

Of course it is possible. In the end everything is just a series of 1s and 0s

You could programm with just that.

You just would need a few lifetimes to do so.

1

u/Comprehensive_Mud803 26d ago

Doom, Quake, and many more games have been written in C, so it’s definitely doable.

1

u/frankster 26d ago

Of course it's possible   Why wouldn't it be possible?

1

u/Low_Independent766 26d ago

C + raylib is pretty goated imo

1

u/mymindisagarden 26d ago

What's high level? Generally totally possible, just as much as in other languages I would say, just takes a bit longer. Old games were written in C alot, think like pre 2000. New indie games are sometimes made in C.

1

u/wrecklass 26d ago

100% possible and many games done that way.

1

u/Pesciodyphus 26d ago

Are you planning to start from scratch or use libraries ? Most libraries are written in C and can bes used instantly without somebody explicitly supporting it. I would recommend SDL + Open GL for the IO.

In terms of vector math, there are libraries for that too (both floating point and fix point), or you can use Open GL for that. It is of course a cool exercise in math to implement stuff like logaritms yourself.

There are also libraries for physics simulation or Network stuff if you want.

Of course if you are into low level programming you can write a software renderer. Tipp: You can use the C-preprocessor to generate multiple variants of Shaders from one source file. Just write an universal shader, and then use #Ifdef statements to generade fast single purpose shaders depending on macros. Then take a seperate C file, and include the shader file several times, each time with different macros defined. The C preprocessor is really powerfull.

System acces in C works generally by systems providing system dependant libraries, like Windows.h wich provide a lot of functions. thought most lowlevel Linux stuff is already in the C standart. The extension POSIX provides full acces to Linux lowlevel acces and also is fully implemented for Windows if you use the MinGW compiler (GCC for Windows). There is even an old but great IDE called "Dev C++" for Windows. While the IDE is from 2005, you can easily updated the compiler as it is provided as seperated command line tool.

For highlevel stuff, you generally want to use SDL for the portability alone as Windows and Linux do thatt different. In Windows you call functions in DLLs, while on Linux you deal with the Pseudo-files in /dev/.

If you are looking for a scripting language (for Level scripts and the like), you can get

  • Angelscript, wich is basically interpreted C
  • Many people also use Lua, thougt its more like BASIC
  • If you want to implement from scratch I recomend FORTH or LISP, as theese languages are very lightweight to implement (~1000 lines of c). Note theese are Funtional Programming Languages wich are drastically different from C.

1

u/RealisticDuck1957 26d ago

To make full use of modern 3D rendering you'd need GLSL or other code for the purpose. OpenGL without the full support can be pure C.

Even scripting of a sort can be in C through the use of an embedded compiler and dynamic linking.

1

u/EclipsedPal 26d ago

Yes, definitely, been done hundreds of times.

1

u/Sol33t303 26d ago

It's how it was done before C++ can.e about, so sure.

Doom and Quake were both C. Rollercoaster Tycoon was assembly.

1

u/PTDegen 26d ago

Imagine all the work needed to make an engine, graphics, shaders, managers, thread handlers, etc in a language.

Now imagine it's in a language where you have to handle your own strings manually.

People have made games in C but they were simple games for simple computers, nowadays at best game engines are made in C (or C++ more likely), but have dev teams exclusively working on them and at least of decade of code built up. There's a reason nobody uses C for games unless they are REALLY passionate (see obsessed or hyperfocused), and most people use game engines.

1

u/Adamstrad 26d ago

In C? Whatever next, people will be wanting to make games in Java, ha!

1

u/Emotion_No 26d ago

You can do anything in C!

1

u/Layzy37 26d ago

Well that's a weird question... I'd say it's still today one of the best languages to make a game in. "Forget practical" why? It is very practical to make a game in C today, given the myriad of game engines written for C (the most well known being raylib/r3d), and even if there wasn't all this for simple games opengl is enough to do most things

1

u/SmokeMuch7356 25d ago

By "only C", do you mean using only those features built into the language and the standard library? No third-party libraries, no system calls, etc.?

If so, the answer is "yes, but it will be extremely difficult." You can draw 3D graphics with ASCII characters, but standard C has no built in facilities for bitmap graphics or sound, and it has no built in facilities for reading the keyboard or other hardware peripherals directly.

Now, if you are allowing for third-party libraries for graphics and hardware control, then sure, no sweat.

1

u/tsh_m 25d ago

This is a great question, I'm not sure if I'm understanding your question correctly. Most of the time developer mention a "full high level 3D game", they are often using a game engine like Unity, Unreal, etc. But as someone who has been using SDL2 and OpenGL for years, i know its possible to make a big scope 3d game using this tools but the idea is scary to think about, so every time i end up thinking to myself "No, i will wait till i learn to Unity or Unreal engine" and never does. Just to answer you question: Yes, it is possible to make a complete 3D games using C, but you will need OpenGL/DirectX knowledge, and a helper library for window creation, input and audio, you can use C for window creation, but the progress is tedious.

1

u/utl94_nordviking 25d ago

What? This was done for decades. Does your birth year begin with 2?

1

u/Far-Note6102 25d ago

I think nintendo still does C? Correct me if I am wrong :3

1

u/aaron_9000 24d ago

It is 100% possible. I released a 3D shooter on Steam that was built from scratch in C and OpenGL. I didn't use raylib but I would also recommend it - it's a great place to start.

1

u/turtlesdontcry 24d ago

DOOM was written in C.  The source code is on Github.  If you want a breakdown of how the code worked Doom Black Book is the book for you.

1

u/New_Cardiologist_641 24d ago

I am trying to do something in C, spent the weekend learning and thinking, the name will de capitalist farm, but Im just going to play it with my friends

1

u/KlutzyCompetition937 23d ago

Possible? Yes; Maintain and improve upon? No; Simply put other higher level language exist to do the same tasks without doing all the manual labor and deep low level knowledge. But if you have time and dedicated enough I don't see a reason why not.

1

u/Standard_Guava3672 23d ago

If you mean creating a 3d app? You can use raylib, or OpenGL. It's not totally clear what you mean by high level, but I use DirectX API and winapi with C++ files but it's all written in C inside.

1

u/Right-Beginning2651 21d ago

To begin with, C is, after all, closer to the operating system than many other languages, and that’s why you can use it to create 3D graphics; otherwise, you wouldn’t be able to do it in Python either (with the help of libraries). In turn, you can create 3D graphics in OpenGL.

1

u/joryzon_dev 21d ago

Writing games in C is incredibly simple, just use raylib if you're just starting out. If getting more comfortable, use sdl2

-1

u/[deleted] 27d 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.

-5

u/frasnian 27d ago

C and "only C?" Not possible, unless it's text-only. That being said, every graphics interface and audio subsystem worth using has a C API.