SVGALib

From Wikipedia, the free encyclopedia
Jump to: navigation, search
SVGALib
Original author(s) Harm Hanemaayer
Stable release 1.4.3 / June 2, 2001; 14 years ago (2001-06-02)
Preview release 1.9.25
Written in C
Operating system Linux, FreeBSD
Platform x86, x86-64
Type Library
Website www.svgalib.org

SVGAlib is an open-source low-level graphics library which runs on Linux and FreeBSD and allows programs to change video mode and display full-screen graphics. Some popular games like Quake and Doom have been ported to use SVGAlib.

History[edit]

The library was popular in mid-1990s. Toward 2000, many applications that used it migrated to X11 and SDL, which itself can make use of SVGAlib as a video driver.

A sample of SVGAlib code is shown below.

#include <stdlib.h>
#include <unistd.h>
#include <vga.h>

int main(void)
{
   int color = 4;
   int x = 10;
   int y = 10;
   unsigned int seconds = 5;

   /* detect the chipset and give up supervisor rights */
   if (vga_init() < 0)
        return EXIT_FAILURE;

   vga_setmode(G320x200x256);
   vga_setcolor(color);
   vga_drawpixel(x, y);
 
   sleep(seconds);
 
   /* restore textmode and fall back to ordinary text console handling */
   vga_setmode(TEXT);
 
   return EXIT_SUCCESS;
}

Example of use on linux mint 17.3 mate 32-bit dvd-live :

open software manager and install : libsvga1 libsvga1-dev svgalib.bin

or with terminal :

$ cd Desktop
$ sudo su 
# apt-get install svgalib-bin
....
# apt-get install libsvga1
....
# apt-get install libsvga1-dev

create and open with text editor a text file svga.c on desktop

then copy and paste the program in text file svga.c

modify the program resolution with :

vga_setmode(G1024x768x256);    // or your vga desktop screen mode

and save the file.

if you have not already opened, open Terminal and switch as superuser :

$ cd Desktop
$ sudo su 
# ls 
... ... svga.c ... ...

compile with :

# gcc svga.c -lvga

running with :

# ./a.out

It appears a very small red dot in the upper left for 5 seconds.

Example of yellow circle with math functions

#include <stdlib.h>
#include <math.h>
#include <unistd.h>
#include <vga.h>

int main(void)
{
   int x,y,color = 14; 
   float a;
   unsigned int seconds = 5;

   /* detect the chipset and give up supervisor rights */
   if (vga_init() < 0)
        return EXIT_FAILURE;

   vga_setmode(G1024x768x256);  /* some low resolution dont work */ 
   vga_setcolor(color);         /* color of pixel */
   
   for (a=0; a<6.28; a+=0.02)
   { x=(int)(512+100*cos(a));  
     y=(int)(348-100*sin(a));
     vga_drawpixel(x, y);      /* draw pixel */
   }
   sleep(seconds);
 
   /* restore textmode and fall back to ordinary text console handling */
   vga_setmode(TEXT);
 
   return EXIT_SUCCESS;
}

dont forget to compile with math library :

$ gcc svga.c -lvga -lm

See also[edit]

External links[edit]