r/GraphicsProgramming • • Jan 12 '23

Question Getting Started With GFX Programming in C in 2022

I'm trying to learn graphics programming. I just finished reviewing the K&R C text and really want to start developing graphics in C. I've got a few old texts I wanted to use but it feels like no matter what I do I'm getting hung up on linking issues, header issues, etc. Currently trying to use vscode and I can get helloworld to compile/run from the terminal but the second I try and get so much as opengl into the mix everything falls apart.

Are there any really solid modern resources to learn gfx with C? I'm aware of Abrash's black book but I want to be more comfortable with gfx programming in general before diving into that. I'm trying to work as minimalistically as possible- edit code, link, compile done. Yes, I'm open to options other than VScode. No, I will not touch c++, java, rust, etc. As far as long term goals I'd like to eventually end up with a late 90s-esque 3d game engine. I'd also like to eventually work my way to arm7tdmi assembly for gba homebrew development but for now I'm very insistent on sticking with C.

Any and all input will be very appreciated, thank you.

1 Upvotes

12 comments sorted by

5

u/[deleted] Jan 12 '23

Your first hurdle is just building a program that links to opengl. Since you're using vscode I'd recommend learning cmake. It should make it really easy to setup an opengl project (plus whatever other libs you end up using).

Most tutorials will likely be in C++ but that's not really an issue coz the OpenGL API is all C anyway. You don't need a specific resource for graphics in C as long as you know how to code in C.

So once you have a basic project setup, I recommend looking at learnopengl.com but rewrite all the code in C instead of following their exact code.

1

u/Sonnivate Jan 12 '23

Cmake definitely looks like it should be a big help, will check it out after work!

3

u/rfernung Jan 12 '23

No, I will not touch c++, java, rust, etc. As far as long term goals I'd like to eventually end up with a late 90s-esque 3d game engine

I was going to suggest TheCherno's OpenGL series on youtube, but it uses C++; nothing crazy, just basically classes which you could theoretically swap out with structs.

Is there a reason why you're deadset on C? If it's just comfort zone I completely understand that, but I was able to build pretty much what your long term goals were with C# and was actually pretty fast for just utilizing the CPU for rendering. I'm not suggesting you switch to C# but rather try not to get too tied up with your specifications if you're just wanting to build something for yourself. No one will know the underlying language for the most part, and you can still use the old techniques to get the same results (it may be less code with other languages and easier to work with).

3

u/Sonnivate Jan 12 '23

A lot of it's comfort zone (all the classes I've taken were C or Python), but really I truthfully don't have an interest in modern platforms. I want to eventually target running programs on old hardware and from what I've read and previous attempts all resources for these types of things seem to revolve around assembly and C. I want to understand memory and hardware. I kinda wanna just be immersed in the headspace of 90s graphics development.

3

u/rfernung Jan 12 '23 edited Jan 12 '23

That makes perfect sense to me! If you're not worried about OpenGL and utilizing the GPU, you could alway go with a software rasterizer approach and follow this tutorial. It's in C++ but it's definitely something you can translate into C with very little effort!

Also if you're wanting to understand memory and hardware, I'd definitely suggest learning assembly (maybe something fun like gameboy development to get an idea of working with memory mapped hardware), also any embedded programming like the arduino or esp32 would help you with low level development and learning tricks to overcome the limitations

2

u/Sonnivate Jan 12 '23

Will check it out thanks!

2

u/filch-argus Jan 12 '23

Take a look at CMake, SDL2 and Raylib.

CMake helps when dealing with dependencies. For example, FindOpenGL helps with finding OpenGL in your system.

There are tutorials where you only need the ability to draw a pixel to the screen or to a file.

The first two are language agnostic and the third one uses C++ but you might be able to adapt it to pure C.

1

u/Sonnivate Jan 12 '23

Having looked around the c subreddit sdl2 def looks like something i should become familiar with, will check it out thanks!

5

u/jtsiomb Jan 12 '23

C is perfectly suitable for graphics programming. You don't need to write C++, but many graphics-related tutorials and examples will use C++, so being able to understand it at some level and pick up the relevant ideas will help. Most graphics people don't go overboard with obscure C++ features anyway. Just understanding the basics of classes, operator overloading, and parts of the standard data structures (STL) will probably suffice for understanding most of the graphics-related C++ code out there.

2

u/el0j Jan 12 '23

If you want to start from zero, maybe try this Tsoding Daily's series. It's not OpenGL, but he's got other stuff on that. Have a poke around.

2

u/[deleted] Jan 12 '23 edited Jan 12 '23

Peter Shirley's book on Ray Tracing is neat. It is C++ but nothing fancy, used just for the inheritance (which can be emulated with structs containing duplicates of what would have been inherited). Edit: I see now you're against that :) The thing is, inheritance is very commonly used in graphics. https://raytracing.github.io/books/RayTracingInOneWeekend.html#outputanimage/addingaprogressindicator

1

u/shebbbb Jan 12 '23

C and c++aren't that different and opengl will work, so you shouldn't have any problem.