1. NAME▲
vgagl - a fast framebuffer-level graphics library based on svgalib
2. TABLE OF CONTENTS ▲
R 0.
R 1.
R 2.
R 3.
3. 0. INTRODUCTION ▲
This is a fast framebuffer-level graphics library for linear 1, 2, 3 and 4 byte-per-pixel modes (256-color, hicolor, truecolor). It uses a limited number of functions from svgalib (libvga) for low-level hardware communication (the library is included in the svgalib shared image). In particular,
R svgalib (7) maps the 64K VGA frame buffer window, and this library directly addresses the buffer. For SVGA modes that use more than 64K of screen memory, SVGA paging is required when writing to the physical screen; this is done automatically for most functions (at a certain cost). Alternatively, any number of virtual screens of any type in system memory can be used, which can then be copied to the physical screen. There is also support for 4 bytes per pixel framebuffers (and copying them to a 3 bytes per pixel context), and limited planar 256 color mode support (copyscreen, aligned putbox). The planar 256 color modes (available on all VGA cards) can now be used with a virtual screen, which is copied to the physical screen (with optional page-flipping). Bitmaps are raw, with one (or more) bytes per pixel (like pixmaps in X), stored in row-major order. They are usually manipulated with the getbox and putbox functions.
vgagl does also make use of the graphic cards accelerator (if it is supported) in some situations. A graphics context is just a structure that holds the size of the associated graphics screen, how it is organized, clipping status etc. You can define a custom virtual (system memory) graphics context of any size with the setcontextvirtual function. All operations work on the current context. Any questions, bug-reports, additions, suggestions etc. are welcome.
4. 1. HOW TO USE VGAGL ▲
Programs that use
vgagl must
R Linking must be done with
R Functions in the
vgagl library have the prefix
R gl_* . To initialize
R vgagl , the graphics context must be set. Example:
vga_setmode(G320x200x256);
gl_setcontextvga(G320x200x256); In this example, the context is set to the physical screen. The context can be saved (only the screen type, not the contents) into a variable, e.g.
GraphicsContext physicalscreen;
gl_getcontext(&physicalscreen). To define a virtual screen in system memory, use
R gl_setcontextvgavirtual (3):
gl_setcontextvgavirtual(G320x200x256) which allocates space for a screen identical to 320x200x256 graphics mode, and makes this virtual screen the current graphics context. The virtual screen can now be copied to the physical screen as follows:
gl_copyscreen(&physicalscreen); Note that with a virtual screen in system memory, it is possible to add fast X-Window support to a program, using MITSHM to copy the framebuffer to the screen window.
5. 2. DESCRIPTION OF VGAGL FUNCTIONS ▲
5.1. Context management ▲
R gl_getcontext
get the current graphics contents..
R gl_setcontext (3)
set a previously saved context.
R gl_setcontextvga (3)
set the context to the physical screen.
R gl_setcontextvgavirtual (3)
set the context to a virtual mode.
R gl_setcontextvirtual (3)
define a virtual context.
R gl_allocatecontext (3)
allocate a graphics context.
R gl_freecontext (3)
free a virtual screen.
R gl_setcontextwidth
set the dimension of a context.
5.2. Drawing primitives ▲
R gl_clearscreen (3)
clear the screen.
R gl_rgbcolor (3)
return pixel value corresponding to an rgb color.
R gl_setpixel
draw a pixel.
R gl_getpixel (3)
return the color of a pixel.
R gl_getpixelrgb (3)
store color components of a pixel.
R gl_hline (3)
draw a horizontal line.
R gl_line (3)
draw a line.
R gl_circle (3)
draw a circle.
R gl_fillbox (3)
fill a rectangular area.
5.3. Copying of screen buffers and page flipping ▲
R gl_copyscreen (3)
copy the screen contents of contexts.
R gl_setscreenoffset (3)
set a memory offset for copyscreen.
R gl_setdisplaystart (3)
set the start of the screen are displayed.
R gl_enablepageflipping (3)
enables automatic page flipping.
5.4. Clipping ▲
R gl_disableclipping (3)
disables clipping.
R gl_enableclipping (3)
enables clipping.
R gl_setclippingwindow (3)
set the clipping window.
5.5. Text drawing primitives ▲
R gl_setfont (3)
set the text font to be used.
R gl_setfontcolors (3)
set the font colors.
R gl_expandfont (3)
expand a packed pixel font.
R gl_colorfont (3)
change the color of a font.
R gl_setwritemode (3)
set the font writemode flags.
R gl_write
write a text string.
R gl_printf (3)
formatted output to the graphics screen.
R gl_font8x8 (3)
a packed 8x8 pixel font.
5.6. Pix- and Bitmap drawing ▲
R gl_getbox (3)
copy a rectangular pixmap from the screen to a buffer.
R gl_copybox (3)
copy a rectangular screen area.
R gl_copyboxfromcontext (3)
copy rectangular area from another context.
R gl_copyboxtocontext (3)
copy a rectangular area to another context.
R gl_putbox (3)
copy a pixmap to a rectangular area.
R gl_putboxpart (3)
copy a partial pixmap to a rectangular area.
R gl_putboxmask (3)
copy a masked pixmap to a rectangular area.
R gl_putboxmaskcompiled (3)
copy a compiled masked pixmap to a rectangular area.
R gl_compileboxmask (3)
compress a masked bitmap.
R gl_compiledboxmasksize (3)
compute the size of a compiled masked box.
R gl_scalebox (3)
scale a pixmap.
5.7. Palette handling ▲
R gl_getpalettecolor
read the color palette.
R gl_setpalettecolor
set the color palette.
R gl_setrgbpalette (3)
set a 256-color RGB palette.
5.8. Triangle primitives from threeDkit ▲
R gl_striangle (3)
draw a solid colored triangle.
R gl_triangle (3)
draw a triangle with interpolated colors.
R gl_swtriangle (3)
draw a solid pixmap mapped on a triangle.
R gl_wtriangle (3)
draw a shadowed pixmap mapped on a triangle.
R gl_trisetcolorlookup
manages a color lookup table for shadowing.
R gl_trisetdrawpoint (3)
set a triangle drawing function.
6. 3. MACROS DEFINED IN VGAGL.H: ▲
WIDTH
The width in pixels of the current graphics context.
HEIGHT
Height in pixels.
BYTESPERPIXEL
Number of bytes per pixel (1, 2, 3 or 4).
BYTEWIDTH
Width of a scanline in bytes.
COLORS
Number of colors.
BITSPERPIXEL
Number of significant color bits.
VBUF
Address of the framebuffer.
__clip
Clipping flag.
__clipx1
__clipy1
Top-left corner of clipping window.
__clipx2
__clipy2
Bottom-right corner of clipping window.
7. BUGS ▲
For three bytes per pixel (true color) modes, it is possible that pixels cross a SVGA segment boundary. This should be correctly handled by most functions, but you never know. It can be avoided by using a logical scanline length that is a divisor of 65536 (a power of 2), like 1024 (as opposed to 960) for 320x200 and 2048 (1920) for 640x480. For 800x600, this is impractical (4096 as opposed to 2400 doesn't fit in 2MB). Alternatively, avoid those functions by using a virtual screen.
8. SEE ALSO ▲
R svgalib (7),
R libvga.config (5),
R testgl (6),
R threedkit (7),
R currentcontext (3),
R gl_allocatecontext (3),
R gl_circle (3),
R gl_clearscreen (3),
R gl_colorfont (3),
R gl_compileboxmask (3),
R gl_compiledboxmasksize (3),
R gl_copybox (3),
R gl_copyboxfromcontext (3),
R gl_copyboxtocontext (3),
R gl_copyscreen (3),
R gl_disableclipping (3),
R gl_enableclipping (3),
R gl_enablepageflipping (3),
R gl_expandfont (3),
R gl_fillbox (3),
R gl_font8x8 (3),
R gl_freecontext (3),
R gl_getbox (3),
R gl_getcontext (3),
R gl_getpalette (3),
R gl_getpalettecolor (3),
R gl_getpalettecolors (3),
R gl_getpixel (3),
R gl_getpixelrgb (3),
R gl_hline (3),
R gl_line (3),
R gl_putbox (3),
R gl_putboxmask (3),
R gl_putboxmaskcompiled (3),
R gl_putboxpart (3),
R gl_rgbcolor (3),
R gl_scalebox (3),
R gl_setclippingwindow (3),
R gl_setcontext (3),
R gl_setcontextheight (3),
R gl_setcontextvga (3),
R gl_setcontextvgavirtual (3),
R gl_setcontextvirtual (3),
R gl_setcontextwidth (3),
R gl_setdisplaystart (3),
R gl_setfont (3),
R gl_setfontcolors (3),
R gl_setpalette (3),
R gl_setpalettecolor (3),
R gl_setpalettecolors (3),
R gl_setpixel (3),
R gl_setpixelrgb (3),
R gl_setrgbpalette (3),
R gl_setscreenoffset (3),
R gl_setwritemode (3),
R gl_striangle (3),
R gl_swtriangle (3),
R gl_triangle (3),
R gl_trigetcolorlookup (3),
R gl_trisetcolorlookup (3),
R gl_trisetdrawpoint (3),
R gl_write (3),
R gl_writen (3),
R gl_wtriangle (3).
9. AUTHOR ▲
There are many authors of svgalib. This page was edited by Michael Weller <>. The original documentation and most of
vgagl was done by Harm Hanemaayer <> though.