Linux Graphics Programming With Svgalib by Jay Link available in Trade Paperback on , also read synopsis and reviews. I would like to know what to use to program graphics on the GNU/Linux console or framebuffer, maybe with SVGAlib. I know some current. This is a low level graphics library for Linux, originally based on VGAlib by Tommy Programs that use svgalib must #include; if they also use the.
|Genre:||Health and Food|
|Published (Last):||1 October 2012|
|PDF File Size:||16.2 Mb|
|ePub File Size:||6.36 Mb|
|Price:||Free* [*Free Regsitration Required]|
If so, look no further. SVGAlib is a low-level graphics library for Linux.
svgalib(7): low level graphics library for – Linux man page
It augments the C programming language, which doesn’t provide support for graphics. But there are lots of graphics programs written in C! Yes, but they all rely on external library functions. C itself can only give you text.
That’s because all graphic functions are system dependent and are non-portable. Unfortunately, graphic routines coded for one operating system will not work under another unless they are completely rewritten.
To code graphics in C under Linux, it is necessary to use an external set of functions which are native to Linux. SVGAlib is one such set. This server must be started prior to using any applications which require X.
Furthermore, the X server is unabashedly system-intensive i. SVGAlib, on the other hand, requires no such preparation. If SVGAlib is properly installed, the average user shouldn’t even be aware of its existence. Finally, SVGAlib will not affect your virtual terminals, leaving you free to run multiple applications like always. You can have normal text on one terminal and graphics on another. Also, poorly-written SVGAlib applications can mung-up your console, requiring a reboot.
Finally, you shouldn’t switch back and forth quickly between two consoles using SVGAlib graphics, or you risk screen corruption forcing another reboot. However, it is a myth that SVGAlib is a security risk.
While SVGAlib apps must be setuid root, that privilege is given up immediately after execution. There is no need to be concerned. In summary, despite the aforementioned problems, SVGAlib’s speed and ease of use make it attractive in many situations.
Especially if you just want to doodle on the screen. Here’s about the easiest SVGAlib program there is: After five seconds, it will reset your console to text mode and will exit.
This relinquishes root status and initializes the SVGAlib library. That is to say, your screen becomes a grid which is pixels wide, pixels high, and which supports colors. Either statement is acceptable. We can choose any value from 0 to More colors are available with other commands, but we’ll stick with these basic colors for this example.
Finally, we paint our pixel at coordinate 10, This is eleven spaces right of the screen’s left border, and eleven spaces down.
Follow the Author
It’s eleven, not linxu, because the coordinate grid starts at 0. Coordinate 0,0 is in the upper left-hand corner. It’s always nice to do this at the end of your program. Otherwise, you’ll make life difficult for your users.
To compile this code, use the regular gcc compiler. You’ll also need to link to SVGAlib with the -lvga command.
Lastly, I suggest using -O3the best level of optimization. So here’s our command: We won’t go into all of them here, though. Instead, we’ll write our second sample program using a faster set programmkng SVGAlib functions: Type “man vgagl”, and svglib see that vgagl is “a fast, framebuffer-level graphics library based on SVGAlib.
Below is a program which uses vgagl. It should display a blue gradient screen, just like the ones that some installation programs use. It starts out as light blue on top of the screen, and gradually fades to black as it moves down. One thing that it does differently than the first program is that it does the drawing on an invisible “virtual” screen.
When all the lines have been drawn, it copies the finished picture to the visible “physical” screen in one fell swoop. This eliminates screen flicker, and makes your application look more professional.
I like to think of the virtual screen as being “backstage”, a place where “props” can be assembled between “acts” in the show. To compile, I suggest typing: It is mandatory that you refer to vgagl first when using that library. We start our code by setting the graphics context: We’ll use mode 5 Proyramming like before.
We need to initialize both the visible “physical” screen and the invisible “virtual” screen. We then save the contexts into progrxmming We’ll draw 3 lines per shade, for a total of lines.
The remaining eight lines will be black anyway, so they won’t stand out. This time, we’ll let the user decide how long to leave the picture visible.
Programminb waits for user input. The entire set of functions for SVGAlib can be viewed by typing “man svgalib” and “man vgagl”.
Then, each function has its own man page. After reading this introduction, you should be able to insert new commands into your own programs with relative ease. You also have the demo programs that came with SVGAlib from which to learn.
In the event that your distribution was incomplete, you can find the latest version of SVGAlib at metalab. At the time of this writing, the current version is 1. Finally, the Slackware distribution, while a good one, has a tendancy to install SVGAlib to the wrong directories.