Resources on programming in C without libraries?
Posted by BriefCautious7063@reddit | learnprogramming | View on Reddit | 11 comments
I want to learn how to program graphics and keyboard/mouse inputs with genuinely no libraries. No openGL, SDL, not even the standard library. The goal is to learn how these libraries were made in the first place. I know a decent bit about how to use libraries to do what I want, I just don't know how to use C and/or ASM to directly write to the screen or respond to hardware inputs. Anyone have any resources and/or github examples demonstrating this?
peterlinddk@reddit
You might find OneLoneCoder's simple engines useful - https://www.youtube.com/watch?v=kRH6oJLFYxY - he doesn't explain much about how to actually make the libraries, but perhaps the fairly simple code is useful in seeing how you could create something similar.
Haven't tried it myself - a bit afraid to get lost in the depths of graphic drivers :)
jqVgawJG@reddit
See you in 70 years when you're done 😂
teraflop@reddit
If you're programming on a modern operating system, you can't directly access the hardware. At a minimum, you have to go through the OS kernel and drivers. And if you want your program to be able to coexist with the rest of the GUI, you need to go through the windowing system.
Since the libraries that you would normally use to write a GUI program are just ordinary userspace code, there is nothing in principle that would stop you from recreating them. It's just a lot of work.
On Linux, you can look at the X Window System protocol specification for "legacy" systems, or the Wayland protocol specification for more modern environments. Both of these protocols can ultimately be boiled down to bytes that are sent over a socket. So if you're meticulous and bloody-minded enough, you can implement them using raw syscalls.
I don't really know how the corresponding low-level protocols work on Windows or Mac OS, and you may have more difficulty finding out since those platforms are not fully open-source.
ElsartjCrocus@reddit
Yep, that's ththe hard path.
jeffwithhat@reddit
What kind of understanding are you hoping to achieve on the graphics front?
In Days Of Yore, the programmer was faced with a bunch of raw pixels, and built up 2D and 3D graphics primitives from there (hidden surface removal, shading, texturing…) usinga bunch of math that ran on the main CPU. Are you hoping to learn the math behind those concepts?
Nowadays a GPU has a bunch of lightweight processors that handle some of this same work in parallel, coupled with specialized hardware units to handle other work. This is older, I think, but gives the flavor: https://www.dcce.ibilce.unesp.br/~aleardo/cursos/arqcomp/TDCI_Arch.pdf
So perhaps you want to learn how those earlier concepts can be parallelized in software or implemented directly in hardware.
Or perhaps you just want to know how to talk directly to the GPU in front of you: its Application Binary Interface, or ABI.
There is a mountain of work here, so you’ll need to choose a subset to focus on. Then it will be easier for folks to point you in the right direction.
code_tutor@reddit
For graphics, study Linear Algebra and Multivarible Calculus.
For easier things, look at pixel games, like TI-83 code.Â
Computer Engineering if you want to learn about hardware.
Or look up how to program drivers in Linux.
VoiceOfSoftware@reddit
Ben Eater’s Youtube series is fantastic, and shows how to build things like Hello, World from assembly. He even walks you through building a simple computer from scratch.
Tell_Me_More__@reddit
Op this is the answer
Jim-Jones@reddit
I think you should check out this book, "Beginner's Step-by-Step Coding Course: Learn Computer Programming the Easy Way (DK Complete Courses)" by DK.
Start reading it for free: https://a.co/7Fprv2a
Also
C Programming Full Course for free
https://youtu.be/87SH2Cn0s9A
Mighty_McBosh@reddit
I'd start looking into embedded graphics on like a RPI or even something smaller.
One does not just jump immediately into reverse engineering opengl.
isa_marsh@reddit
You want to write DirectX from scratch ?