To make graphics appear on the screen, there are several layering:
- The creators of graphics cards, motherboards, monitors define a way for these parties to communicate. For example, set the X pin with a Y bit, wait as many nanoseconds, read the bytes in Z address, etc. These conventions can follow standards such as PCI or PCI Express buses, connection with VGA monitor or HDMI, etc. You will only work at this level if you mess with hardware or operating systems.
- The operating system has a driver that controls the above features so that application developers don’t need (and can’t!) to communicate directly with the graphics card. You will only work at this level if you are writing drivers, operating systems, or if using some more primitive system, such as MS-DOS.
- Again the operating system (OS) shall have a interface for application programming (API) for access to what the driver has implemented, with syscalls (system calls). Syscalls can be in Assembly itself or can be made available in a library format for a higher level language such as C.
- A higher-level library can still further abstract the task, providing a new, friendlier API that can be used in the same way across multiple languages and operating systems.
And then, how to create a graphical library "from scratch"? Depends on where you put the zero.
If you have only one board and one processor, you will start from step 2, writing drivers and operating systems.
If you have a board, a processor, and also an operating system, you will start from step 3, using the features that the operating system offers and building upon that.
The case I imagine you want to know is the latter, when you already have the operating system but can’t understand how libraries like Qt, GTK+, and SDL do to draw on the screen. The answer then is: they take the responsibility to speak to the operating system in its "language", whatever it is (Win32? GDI+? Directx? Opengl? Xlib? Wayland? Syscalls direct to the operating system kernel?).
The C language, for historical reasons, provides a unified way (<stdio. h>) to deal with text files (including the screen and keyboard there), but does not provide the same for graphics. In the background the two cases pass through similar layers (library for the application programmer, API of the OS, driver, bits and bytes for the communication with the components of the computer, until arriving at the level of the electric current that makes everything work).
So it’s very common to have a library, which calls another library, which calls another library, which calls a function dependent on the operating system, which calls the driver, which makes the pixel appear on the screen. We can compare it with opening files in C++ where there are several ways: iostream (C++ default), fopen (C standard), open (POSIX standard), Createfile (Win32) (the first two are higher level and the last two are lower level).
Look at these examples:
- The application uses wxWidgets on Linux, which calls
- GTK+, who uses...
- Cairo to make 2D graphics that...
- will do the necessary to generate the graphics in the operating system using Xlib, XCB, Quartz, or Win32...
- that will access the OS with a syscall
- and OS will use the video driver to send pixels to the screen.
In the case of Windows, you need to pass an option to the compiler or to Linker to use "Subsystem windows" and thus avoid the appearance of that command line black screen. But failing to do this does not prevent the program from creating windows on Windows (with Createwindowex or any equivalent function), it would only get uglier for the user.
Note that the programmer could also use GTK+ directly if he thought that wxWidgets is not offering any advantage. But if you go down to Xlib (or XCB), you would certainly have more difficulty porting the app to Windows, or when X becomes obsolete and everyone uses Wayland. And I may have missed some layer on the list above! For example, writing this answer I discovered the existence of XCB as an alternative to Xlib.
Or else:
- A game in SDL
- that will use calls to Apis Win32 and Direct3d for graphics on Windows
- or Cocoa and Opengl for graphics on Mac OS.
Remembering that for 3D graphics the programmer can use Direct3d (Directx) and Opengl directly, if you prefer. More recently, the Vulkan as an alternative to Opengl.
Not to mention Android and iOS, which must have their own Apis, such as Opengl ES.
In the midst of so many, it can be difficult to know which library is the basis of the others and which are just abstractions. So if you look at the links above to wxWidgets, GTK, Cairo and SDL, you can see that I tried to put the link precisely to the page that explains on what basis the library is built.
What are you talking about? Either I don’t understand or the premise of the question is wrong. No text is transformed into images. Explain better what you want to know. You want to know how to get into graphic mode?
– Maniero
@bigown yes, I edited the question
– Silvio Andorinha
I recommend using java graphical interfaces in your programs. https://www.youtube.com/watch?v=312bRmUsRx0
– Jordan Gonçalves