home *** CD-ROM | disk | FTP | other *** search
/ Il CD di internet / CD.iso / SOURCE / D / SVGALIB / SVGALIB1.TAR / svgalib / gl / README < prev    next >
Encoding:
Text File  |  1995-01-27  |  12.2 KB  |  336 lines

  1.  
  2. This is a fast framebuffer-level graphics library for linear 1, 2, 3 and 4
  3. byte-per-pixel modes (256-color, hicolor, truecolor). It uses a limited
  4. number of functions from svgalib (libvga) for low-level hardware
  5. communication (the library is included in the svgalib shared image).
  6. In particular, svgalib maps the 64K VGA frame buffer window, and this library
  7. directly addresses the buffer. For SVGA modes that use more than 64K of
  8. screen memory, SVGA paging is required when writing to the physical screen;
  9. this is done automatically for most functions (at a certain cost).
  10. Alternatively, any number of virtual screens of any type in system memory can
  11. be used, which can then be copied to the physical screen. There is also
  12. support for 4 bytes per pixel framebuffers (and copying them to a 3 bytes per
  13. pixel context), and limited planar 256 color mode support (copyscreen,
  14. aligned putbox).
  15.  
  16. The planar 256 color modes (available on all VGA cards) can now be used
  17. with a virtual screen, which is copied to the physical screen (with optional
  18. page-flipping).
  19.  
  20. Bitmaps are raw, with one (or more) bytes per pixel (like pixmaps in X),
  21. stored in row-major order. They are usually manipulated with the getbox
  22. and putbox functions.
  23.  
  24. A graphics context is just a structure that holds the size of the associated
  25. graphics screen, how it is organized, clipping status etc. You can define a
  26. custom virtual (system memory) graphics context of any size with the
  27. setcontextvirtual function. All operations work on the current context.
  28.  
  29. Any questions, bug-reports, additions, suggestions etc. are welcome.
  30.  
  31.  
  32. Functions (all have a "gl_" prefix):
  33.  
  34.     - simple line drawing 
  35.  
  36.     setpixel( int x, int y, int c )
  37.         Draw a single pixel at position (x, y) in color c. The lower
  38.         8, 15, 16 or 24 bits of the color are significant, depending
  39.         on the number of colors the current mode supports. 
  40.  
  41.     setpixelrgb( int x, int y, int r, int g, int b )
  42.         Draw a single pixel at (x, y) with color components r, g,
  43.         and b, ranging from 0 to 255. In 256 color mode, only
  44.         meaningful if the RGB palette is set (setrgbpalette).
  45.  
  46.     int getpixel( int x, int y )
  47.         Returns color of pixel at position (x, y).
  48.  
  49.     getpixelrgb( int x, int y, int *r, int *g, int *b )
  50.         Store color components from pixel at (x, y) ranging from 0
  51.         to 255, into integers pointed to by r, g and b.
  52.  
  53.     int rgbcolor( int r, int g, int b )
  54.         Returns pixel value that corresponds with the given color
  55.         components. Used by setpixelrgb.
  56.  
  57.     line( int x1, int y1, int x2, int y2, int c )
  58.         Draw a line from (x1, y1) to (x2, y2) inclusive in 
  59.         color c.
  60.  
  61.     hline( int x1, int y, int x2, int c )
  62.         Draw a horizontal line from (x1, y) to (x2, y) in color c.
  63.  
  64.     circle( int x, int y, int r, int c )
  65.         Draw a circle of radius r in color c.
  66.  
  67.  
  68.     - box (bitmap) functions 
  69.  
  70.     fillbox( int x, int y, int w, int h, int c )
  71.         Screen position (x, y), box size (w, h).
  72.         Fill a rectangular area of the screen with a single color.
  73.  
  74.     getbox( int x, int y, int w, int h, void *dp )
  75.         Bitmap data pointer dp. Bitmaps are in row-major order.
  76.         Copy a rectangular bitmap from the screen to a buffer.
  77.  
  78.     putbox(    int x, int y, int w, int h, void *dp )
  79.         Bitmap data pointer dp.
  80.         Copy a bitmap to a rectangular area of the screen.
  81.  
  82.     putboxpart( int x, int y, int w, int h, int bw, int bh, void *bp,
  83.     int xo, int yo )
  84.         Copy a partial bitmap to the screen. (w, h) is the size
  85.         of the partial bitmap, (bw, bh) that of the source bitmap,
  86.         and (xo, yo) is the offset in pixels into the source bitmap.
  87.  
  88.     putboxmask( int x, int y, int w, int h, void *dp )
  89.         As putbox, but do not write bitmap pixels of color zero.
  90.  
  91.     copybox( int x1, int y1, int w, int h, int x2, int y2 )
  92.         Copy the rectangular area at (x1, y1) of size (w, h),
  93.         to (x2, y2) (bitblit).
  94.  
  95.     copyboxtocontext( int x1, int y1, int w, int h, GraphicsContext *gc,
  96.     int x2, int y2 )
  97.         Copy the rectangular area at (x1, y1) of size (w, h), to
  98.         position (x2, y2) in the context gc. If possible use
  99.         copyboxfromcontext.
  100.  
  101.     copyboxfromtocontext( GraphicsContext *gc, int x1, int y1, int w,
  102.     int h, int x2, int y2 )
  103.         Copy the rectangular area at (x1, y1) in the context gc, of
  104.         size (w, h), to position (x2, y2) in the current context.
  105.         This is more efficient than copyboxtocontext.
  106.  
  107.  
  108.     - compiled bitmaps (linear 256 color mode only)
  109.  
  110.     compileboxmask( int w, int h, void *sdp, void *ddp )
  111.         Convert rectangular masked bitmap of size (w, h) at sdp to
  112.         a compressed format that allows faster drawing, which is
  113.         stored at ddp. Allocating w * h bytes for the compiled
  114.         version is usually enough; an upper limit should be 
  115.         (w + 2) * h.
  116.  
  117.     int compiledboxmasksize( int w, int h, void *sdp )
  118.         Returns the size of the compiled version of the masked
  119.         bitmap of size (w, h) at sdp that will be generated by
  120.         compileboxmask.
  121.  
  122.     putboxmaskcompiled( int x, int y, int w, int h, void *dp )
  123.         Write compiled bitmap to screen. This is significantly
  124.         faster than non-compiled masked bitmaps, especially for
  125.         sparse bitmaps.
  126.  
  127.  
  128.     - clipping
  129.     
  130.     enableclipping()
  131.         Enable automatic clipping in most functions.
  132.  
  133.     disableclipping()
  134.         Disable clipping.
  135.  
  136.     setclippingwindow( int x1, int y1, int x2, int y2 )
  137.         Set the clipping window to the rectangle with top-left
  138.         corner (x1, y1) and bottom-right corner (x2, y2) (incl.).
  139.  
  140.  
  141.     - graphics contexts and virtual screens
  142.  
  143.     GraphicsContext *allocatecontext()
  144.         Allocate a graphics context. This is preferred to
  145.         hardcoding a context variable in a program since the
  146.         latter is incompatible with a future vgagl version that
  147.         has additional context fields.
  148.  
  149.     setcontextvga( int mode )
  150.         Set the graphics context to the physical screen of a
  151.         vga mode (as defined in svgalib). The mode must be set
  152.         first. The only thing you can do with a planar (mode X-like)
  153.         256 color mode is aligned putbox, and use it as a target for
  154.         copyscreen.
  155.  
  156.     setcontextvgavirtual( int mode )
  157.         Allocate a virtual screen in system memory identical to
  158.         the graphics mode, and make that the current graphics
  159.         context.
  160.  
  161.     setcontextvirtual( int w, int h, int bpp, int bitspp, void *vbuf )
  162.         Define the current graphics context to have a width of w
  163.         pixels, height h, bpp bytes per pixel, bitspp significant
  164.         color bits per pixel (8, 15, 16 or 24), with the framebuffer
  165.         at vbuf. A 4 bytes per pixel context, with 24 significant
  166.         color bits is also valid.
  167.  
  168.     getcontext( GraphicsContext *gc )
  169.         Save the current context in a structure variable.
  170.  
  171.     setcontext( GraphicsContext *gc )
  172.         Restore a previously saved context (make it the current
  173.         context).
  174.  
  175.     freecontext( GraphicsContext *gc )
  176.         Free the space allocated for the virtual screen in the
  177.         given context.
  178.  
  179.     copyscreen( GraphicsContext *gc )
  180.         Copy the current graphics context contents (screen data) to
  181.         the specified graphics context (the physical screen, for
  182.         example). Contexts are assumed to be identical in size.
  183.  
  184.     setscreenoffset( int o )
  185.         Set the offset in pixels into video memory for copyscreen
  186.         and copyboxtoscreen, allows for page-flipping. Must be a
  187.         multiple of the scanline width in bytes. It is reset to
  188.         zero after completion of copyscreen.
  189.  
  190.     int enablepageflipping( GraphicsContext *gc )
  191.         Enable page flipping or triple buffering in copyscreen if
  192.         the physical context gc can do it. Returns 3 if triple
  193.         buffering will be used, 2 for page flipping, 0 if page
  194.         flipping is not possible (due to video memory/mode
  195.         limitations). When pageflipping is enabled, the screenoffset
  196.         is ignored in copyscreen.
  197.  
  198.  
  199.     - text writing, font handling
  200.  
  201.     setfont( int fw, int fh, void *fp )
  202.         Use the font stored as character bitmaps at fp, with 
  203.         characters of size (fw, fh), as the basic font for write
  204.         operations. Note that the font included in the library must
  205.         be expanded first, because it is stored bit-per-pixel;
  206.         this is not required if the FONT_COMPRESSED writemode
  207.         flag is set.
  208.  
  209.     setwritemode( int m )
  210.         Sets writemode flags. If WRITEMODE_MASKED is set (as opposed
  211.         to WRITEMODE_OVERWRITE), only foreground pixels of the font
  212.         are used for write operations; the screen background is not
  213.         erased. If FONT_COMPRESSED is set (as opposed to
  214.         FONT_EXPANDED), text writes will use the compressed
  215.         bit-per-pixel font rather than the expanded font.
  216.  
  217.     write( int x, int y, char *s )
  218.         Write string s at (x, y) using currently selected font.
  219.  
  220.     writen( int x, int y, int n, char *s )
  221.         Write n character string s at (x, y).
  222.  
  223.     expandfont( int fw, int fh, int c, void *sfp, void *dfp )
  224.         Convert bit-per-pixel font at sfp, with characters of size
  225.         (fw, fh), to an expanded font of character bitmaps, stored at
  226.         dfp (size will be 256 * fw * fw * BYTESPERPIXEL). All
  227.         non-zero pixels are set to color c.
  228.  
  229.     colorfont( int fw, int fh, int c, void *fp )
  230.         Set all nonzero pixels in the expanded font to color c.
  231.  
  232.     setfontcolors( int bg, int fg )
  233.         Set the background and foreground colors for the compressed
  234.         font write mode.
  235.  
  236.  
  237.     - VGA 256-color palette handling
  238.  
  239.     These functions are only valid in 256-color modes.
  240.  
  241.     getpalettecolor( int c, int *r, int *g, int *b )
  242.         Get red, green and blue values (in the range 0-63) of 
  243.         color c from the color-lookup-table, and store them as
  244.         integers in the memory locations pointed to by r, g and b.  
  245.  
  246.     setpalettecolor( int c, int r, int g, int b )
  247.         Set RGB values (0-63) for color c.
  248.  
  249.     getpalettecolors( int s, int n, void *dp )
  250.         Get RGB values of n colors starting at s, which are stored
  251.         as a table of groups of three bytes at dp. 
  252.  
  253.     setpalettecolors( int s, int n, void *dp )
  254.         Set RGB values of n colors starting at color s.
  255.  
  256.     getpalette( void *p )
  257.         Equivalent to getpalettecolors(0, 256, p).
  258.  
  259.     setpalette( void *p )
  260.         Equivalent to setpalettecolors(0, 256, p).
  261.  
  262.     setrgbpalette()
  263.         Set 256-color RGB palette (bits 0-2 blue, 3-5 green,
  264.         6-7 red). Use with setpixelrgb.
  265.  
  266.  
  267.     - miscellaneous
  268.  
  269.     clearscreen( int c )
  270.         Fill the entire screen with color c.
  271.  
  272.     scalebox( int w1, int h1, void *sdp, int w2, int h2, void *ddp )
  273.         Scale the bitmap of size (w1, h1) at sdp to size (w2, h2)
  274.         and store it at ddp, which must be a large enough buffer.
  275.         The pixel size of the current graphics context is used.
  276.  
  277.     setdisplaystart(int x, int y)
  278.         Set the physical display start address to the pixel at (x,
  279.         y). Can be used for hardware scrolling, or for page flipping
  280.         (e.g. setdisplaystart(0, HEIGHT) displays from the second
  281.         page). Make sure the scanline width (BYTEWIDTH) in bytes
  282.         of the current context corresponds with the physical
  283.         screen.
  284.  
  285.  
  286. Macros defined in vgagl.h:
  287.  
  288.     WIDTH        The width in pixels of the current graphics context.
  289.     HEIGHT         Height in pixels.
  290.     BYTESPERPIXEL    Number of bytes per pixel (1, 2, 3 or 4).
  291.     BYTEWIDTH    Width of a scanline in bytes.
  292.     COLORS        Number of colors.
  293.     BITSPERPIXEL    Number of significant color bits.
  294.     VBUF        Address of the framebuffer.
  295.     __clip        Clipping flag.
  296.     __clipx1    Top-left corner of clipping window.
  297.     __clipy1
  298.     __clipx2    Bottom-right corner of clipping window.
  299.     __clipy2
  300.  
  301.  
  302. Use the environment variable GSVGAMODE to select the graphics mode used by
  303. the testgl program (e.g. export GSVGAMODE=G640x480x256).
  304.  
  305. Note
  306.  
  307.     For three bytes per pixel (true color) modes, it is possible that
  308.     pixels cross a SVGA segment boundary. This should be correctly
  309.     handled    by most functions. It can be avoided by using a logical
  310.     scanline length that is a divisor of 65536 (a power of 2), like 1024
  311.     (as opposed to 960) for 320x200 and 2048 (1920) for 640x480. For
  312.     800x600, this is impractical (4096 as opposed to 2400 doesn't fit in
  313.     2MB). Alternatively, avoid those functions by using a virtual screen.
  314.  
  315.  
  316. Question: How do I poll the keyboard without waiting and handle multiple
  317.       keypresses?
  318.  
  319. You can have complete keyboard control by using RAW mode. An example should
  320. be in the kbd-08? package (nic.funet.fi, /pub/Linux/PEOPLE/Linus or similar).
  321.  
  322. There is now a low-level keyboard interface in svgalib.
  323. There is also a seperate 'rawkey' library for use with svgalib, by Russell
  324. Marks.
  325.  
  326.  
  327. Q: What's the fuss about a DLL library?
  328. A: The building of a DLL library includes a conversion, at the assembler
  329.    level, of all references in the library code of exported global variables
  330.    into indirect references with some overhead added to preserve register
  331.    values. This is not very efficient if the global variables are used all
  332.    over the place (e.g. currentcontext and its fields). The testgl program
  333.    ran 20% slower because of this. Therefore, the library internally uses a
  334.    copy of currentcontext that is not exported. This means that the current
  335.    context may only be changed with vgagl functions.
  336.