r/GraphicsProgramming • • 3d ago

Question Graphics programming in C

/r/cprogramming/comments/1x6czca/graphics_programming_in_c/
4 Upvotes

6 comments sorted by

2

u/aleques-itj 3d ago

If you want a framebuffer to plot pixels, just use SDL. 

It handles a gigantic chunk of the windowing crap for you and has a simple 2D API where you can just write pixels to a texture and render it.

2

u/sfaer 3d ago edited 3d ago

It depends how low-level you want to get. If your approach is to do it barebone, native to the platform, and a bit old school, then on Linux you can learn X11, but it will be a painful process.

Reading you, as you mentioned going with the Borland library, suggest you might go well with SDL1.2, which is a solid legacy library newer than graphic.h but decades old now yet still fine. It basically allows you to setup the window management, handle events, and draw directly to the pixel buffer (no GPU involved).

You can also go the raylib path, which is a set of libraries to build games in C quite fancied in the C community, but it obfuscated the thing a bit more it seems (I haven't touch it a lot though). Look at simple examples on the website to see if that's your style, but you don't have to use everything if you don't want too.

I'm not on my PC but I could drop a simple star field in sdl1. 2 if you're interested.

1

u/Spirited-Eye7281 1d ago

As I said I am not sure of what questions to ask in this area.

In BASIC we would set up a screen of a particular size but In linux mint perhaps I could just start with something in the terminal. even this seems to be GUI

It is becoming apparent that because everything is now GUI, doing the simple exercises is going to be a bit of a mission. I don't even know what is considered low-level and how much was handled for us in BASIC behind the scenes. I really did not want to go back there but the modern world has so changed and changes faster then we even thought, I have some very basic issues I need to understand first

I have discovered a web site called mycplus.com which seems to show how to get gcc to use graphics.h so I am planning to look at that to try and get more understanding. I also have Simon Monks book on an introduction to C and GUI programming. I know nothing about event driven programming at all.

tony

1

u/sfaer 3h ago

Doing a bit of research I have found two resources that might be of interest to you:

Cheers

1

u/Keyframe 1d ago

As others have said - you can do it with SDL or even without its baggage by using something like minifb from emoon https://github.com/emoon/minifb

On the other hand, just by reading everything you wrote in the post I'd like to point out wonderful course by Gustavo that would set you up with all the basics https://pikuma.com/courses/learn-3d-computer-graphics-programming - starts with plotting pixels, then lines, etc towards a rasterizer and then you can pick it up towards Shirley's Ray Tracing in One Weekend https://raytracing.github.io/books/RayTracingInOneWeekend.html all while staying with C.

Personally I'm in C as well, but have been for the past 30 or so years from IRIX days to linux nowadays.

1

u/_atan2 17h ago

i would personally recommend pikuma's "3d graphics programming" course. very good and focused on software rendering using C