Using C for Graphics
Hello again fellow users, I want to ask a question that maybe someone can point me in a direction that is helpful. I have in the past learned you can make your own libraries and header files for c programs like stdio.h but I want to know how does someone like x11 make a c program render graphics? is there any way to make my own functions that will print colors on the screen and text on the screen without using someone elses graphics library? How are they doing it? I want to make my own graphics library for fun and maybe learn something. Thanks for your time answering my questions.
|
There are a lot of different ways to do graphics.
Probably I would start here: https://www.x.org/wiki/Development/ (if I understand it well) |
Quote:
|
actually im not sure but that might have helped some, says they use pixman but now im wondering how pixman makes their libraries.
|
You want to program against hardware in the way of “libraries” (and other stuff) that you do not want to use. A graphics-driver. Look there.
For the time when you are done, bookmark this: https://www.x.org/releases/X11R7.5/doc/libxcb/tutorial/ ... then a few of the others (that you do not yet want to use) |
if you want to write directly into the video you need to write first a kernel driver and a library to use that driver, finally you can implement an app which can use that library.
Otherwise you must use libraries implemented by others. |
Wisdom read at the bottom of a bird cage:
Quote:
|
I recommend using GTK 3 for GUIs and Cairo for 2D drawing.
There is a lot of plumbing between the high-level graphics APIs and the hardware. You don't want to re-invent that. Rather, you can draw pixels on a Cairo image surface and call Cairo to display them. This provides enough flexibility to draw anything. Ed |
Target a retro platform if you don’t want to use libraries. In a modern platform, the lowest level you could really touch is the graphics driver, and you use libraries to interact with that.
|
Probably some of you can remember the hercules cards I wrote a program (in assembler) to directly write video memory to draw what I wanted (something like this, just monochrome: https://i.stack.imgur.com/wMyWm.gif), but that was hm, 40 years ago.
|
I remember those days, "pan," and right now do not want to be reminded of them ... :)
|
Aaah! Addressing registers...
My Boss did not give me a card with an unknown controller on it and said: "Make it work". He just said: Find a vendor of this kind of card and write a Linux-driver that we can use in a real-time application (I ordered some books, first). But hey... here is an argument *AGAINST* using what has already been written: I spent a lot of time talking to the engineers of the company which produced the interface-card and the micro-controller, on the phone and by mail. My learning-curve was close to vertical. |
There is a way to work with the screen without using any libraries - FrameBuffer. It doesn't work with modern desktop managers, but if you open a console (Control-Alt-F2), you can write to /dev/fb0 and have direct control of the pixels on the screen. Each pixel is 4 bytes - RGBA - and you just use mmap to get an array to work with. I found a guide here:
https://cmcenroe.me/2018/01/30/fbclock.html |
Quote:
Quote:
Quote:
Use a tool kit, like gtk2, and a graphics drawing/rendering library, like cairo. Trying to find something that I have, that I can put together, small enough to post, and works, that one could actually see working... Here, everyone needs to look at a pdf. pdfviewer.c Code:
#include <stdio.h> |
Quote:
Here is another reference I found to a simple 'x11' example : https://stackoverflow.com/questions/...ng-improvement |
All times are GMT -5. The time now is 04:02 PM. |