ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
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)
Hey thanks but i want to know how they make the libraries that do what their libraries do not learn how to use their libraries. Have any idea how they do it?
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.
Somebody else already worked out a bunch of graphics libraries for you. Even linked them easily to easier-to-use interpreted languages like Python. Did all the hard stuff so you don't have to. Just grab it and go ...
Last edited by sundialsvcs; 05-03-2022 at 09:01 AM.
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.
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:
Me too, in DOS land. At the time (for me), it was fun to write some assembly code to draw points, lines, circles, and other primitives to use in 'C' programs. But now ... SDL2 or some such library is the way to go. It is as close as I need to get to graphics hardware any more! I've even got a thick OpenGL Programming Guide book which I decided after a few pages of reading, I really don't want to learn this! So there it sits.... Save it for the gung-ho youngsters!
Here is another reference I found to a simple 'x11' example :
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.