Easy graphics: A beginner's guide to SVGAlib
gcc -O3 -o gradient gradient.c -lvgagl -lvgaNote that -lvgagl comes before -lvga. It is mandatory that you refer to vgagl first when using that library. Did you remember to chmod u+s ? Here's the code:
#includeNote that we now need to #include <vgagl.h>. We start our code by setting the graphics context:
GraphicsContext *physicalscreen GraphicsContext *virtualscreenThen we'll declare our variables and use vga_setmode() to set the screen mode. We'll use mode 5 (G320x200x256) like before. We need to initialize both the visible "physical" screen and the invisible "virtual" screen. We then save the contexts into variables:
gl_setcontextvga(5) gl_setcontextvgavirtual(5) physicalscreen = gl_allocatecontext() gl_getcontext(physicalscreen) virtualscreen = gl_allocatecontext() gl_getcontext(virtualscreen)We now announce that we'll be working with the virtual screen:
gl_setcontext(virtualscreen).Gl_setpalettecolor() gives us 64 shades of blue. We'll draw three lines per shade for a total of 192 lines. The remaining eight lines will be black anyway so they won't stand out. When we are finished, we copy the contents of the virtual screen (our current screen) to the physical screen with gl_copyscreen(physicalscreen). This time, we'll let the user decide how long to leave the picture visible. Getchar() waits for user input. After receiving a keystroke (any key, it doesn't matter which), we gl_clearscreen(0) and vga_setmode(0) to return to text. 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 (the Slackware distribution, for example, while a good one, has a tendancy to install SVGAlib to the wrong directories), you can find the latest version of SVGAlib at the MetaLab in pub/Linux/libs/graphics. At the time of this writing, the current version is 1.4.0.ø
Related resources1. SVGAlib home page Web-based resource to download the most recent version of SVGAlib, ask for help and read tutorials. 2. Brion Vibber's FAQ More help for SVGAlib developers. 3. SVGAlib mailing list The Rutgers mailing list. Very helpful. Jay Link is twenty-something and lives in Springfield, IL. He administrates InterLink BBS - an unintentionally nonprofit Internet service provider - in his fleeting spare moments as well as working various odd jobs to pay the rent.
Page 2 of 2