home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Shareware Supreme Volume 6 #1
/
swsii.zip
/
swsii
/
099
/
TGE101.ZIP
/
TGE.DOC
< prev
next >
Wrap
Text File
|
1993-02-04
|
28KB
|
640 lines
The Graphics Engine v1.01 Documentation
February 4, 1993
The Graphics Engine software and manual are copyright (c) 1993
by Matthew Hildebrand. All rights reserved.
Topics covered in this document:
-------------------------------
INTRODUCTION
MAJOR FEATURES OF THE GRAPHICS ENGINE
SYSTEM REQUIREMENTS
PACKING LIST
RELEASE NOTES FOR v1.01
INCORPORATING THE GRAPHICS ENGINE
THE GRAPHICS ENGINE'S FUNCTION SET
initGraphics()
deInitGraphics()
putImage()
getImage()
putLine()
getLine()
imageSize()
putPixel()
getPixel()
line()
horizLine()
drawRect()
filledRect()
setPaletteReg()
getPaletteReg()
setBlockPalette()
getBlockPalette()
clearGraphics()
WRITING GRAPHICS DRIVERS
TERMS OF USAGE AND DISTRIBUTION
CONTACTING THE AUTHOR
OBTAINING THE GRAPHICS ENGINE
REVISION HISTORY
ACKNOWLEDGEMENT
LEGAL MUMBO JUMBO
INTRODUCTION
The Graphics Engine is the result of my efforts to construct
a library of C/C++ routines designed to make writing
graphics applications easier. I have used it in my own
programs with excellent results.
The Graphics Engine allows the DOS programmer to easily
access any graphics mode, without having to do special
coding for each. The complications involved with supporting
more than one graphics mode are essentially removed! The
Graphics Engine also provides remarkable flexibility and
expandability through its modular design.
MAJOR FEATURES OF THE GRAPHICS ENGINE
The Graphics Engine provides a simple, standard interface
with which programs may access a powerful library of
graphical functions. As an added bonus, this library
occupies much less memory than other popular commercial
packages do, such as Borland's BGI.
The Graphics Engine uses loadable graphics drivers. This
design means that all code and data necessary to handle a
certain graphics mode is stored in a disk file. When a
program runs, this file will be loaded into memory and the
code it contains will be made available. Consequently:
- Support for more graphics modes may be added simply by
creating more drivers; programs need not be recompiled.
- Since the code to manage the specifics of each mode is
contained in the drivers, the main program needs not
concern itself with what mode it is operating in. The
same code can work in any graphics mode.
- Memory is saved for programs which support many
graphics modes. Instead of keeping the code and data
necessary for each in memory at all times, only the
memory required for one driver is used.
When writing drivers, it is not necessary to write assembly
code for every graphical function that The Graphics Engine
supports. For instance, if a certain driver does not
contain a line-drawing routine, The Graphics Engine will use
its own. Therefore, the programmer needs not waste time
writing assembly code which will seldom or never be used,
thus slashing development time. Essentially, no matter what
a particular driver contains, the entire set of The Graphics
Engine's graphical functions will be available.
SYSTEM REQUIREMENTS
The Graphics Engine is a C/C++ programmer's library. As
such, it requires a C or C++ compiler of some sort to work
with it. The Graphics Engine was written and tested with
Borland C++ 2.0 and Turbo C 2.0, and also tested with Mix
Power C 2.1.2. It should work with other C/C++ compilers as
well.
The loadable drivers are written in assembly language. In
order to write drivers, an assembler will be required.
The drivers that come with The Graphics Engine are written
using 80286 instructions. They therefore cannot be used on
a processor older than the 286. Naturally, this restriction
does not apply to all drivers; drivers created using only
8088 instructions, for instance, would run on an 8088.
PACKING LIST
The current version of The Graphics Engine consists of the
following files:
TGE.DOC The Graphics Engine documentation
TGE.H Header file
TGE.C Main program module
TGE.OBJ TGE.C compiled by Borland C++ 2.0.
TGEDEMO.C Source code of The Graphics Engine
demonstration program
TGEDEMO.EXE The executable version of The Graphics
Engine demonstration program
320x200.ASM 320x200x256 source code
320X200.DRV Driver for VGA 320x200x256
320X240.ASM 320x240x256 source code
320X240.DRV Driver for VGA 320x240x256
320X400.ASM 320x400x256 source code
320X400.DRV Driver for VGA 320x400x256
640X480.ASM 640x480x256 source code
640X480.DRV Driver for SuperVGA/VESA 640x480x256
(autodetect)
800X600.ASM 800x600x256 source code
800X600.DRV Driver for SuperVGA/VESA 800x600x256
(autodetect)
SHELL.ASM The source code of the skeleton graphics
driver, which is designed as a basis for
other graphics drivers
SHELL.DRV Skeleton graphics driver
CDRV.BAT Batch file to create a .DRV from .ASM
If you did not receive all of these files, you have an
illegal copy of The Graphics Engine.
RELEASE NOTES FOR v1.01
The Graphics Engine has not been tested with any compilers
other than Borland C++ 2.0, Turbo C 2.0, and Mix Power C
2.1.2. Although provisions have been made in the code which
aid portability, it may not work with other compilers in
spite of these efforts.
INCORPORATING THE GRAPHICS ENGINE
Incorporating The Graphics Engine into a program is a simple
process involving four simple steps.
First, the header file TGE.H must be #included into any
source file which accesses any of The Graphics Engine's
routines. TGE.C must be compiled and linked into the .EXE
file.
Second, a graphics driver MUST be loaded before any
graphical functions are accessed; results are undefined if
this step is not followed. Code to load a driver might look
like this:
if (!loadGraphDriver(drvFileName))
{
printf("Error loading \"%s\".\n\n", drvFileName);
exit(1);
}
else
atexit(unloadGraphDriver);
Obviously, the function loadGraphDriver() MUST be called.
As its only parameter, it takes a string consisting of the
file name (which may include any valid DOS path) of the
driver to be loaded. As its return value, it returns a
success code. If loadGraphDriver() returns 1, the loading
was successful; if it returns 0, an error occurred.
Third, information about the graphics mode should be
obtained from the graphics driver. The following code will
store the maximum X-coordinate, Y-coordinate, and colour
number in the variables maxx, maxy, and colours
respectively:
maxx = _grSystemDrv->maxx; // set up variables
maxy = _grSystemDrv->maxy;
colours = _grSystemDrv->colours;
Fourth, after The Graphics Engine's graphical functions are
no longer needed (usually just before a program exit), the
function unloadGraphDriver() must be called. It takes no
parameters, and returns nothing. It simply frees the memory
taken up by a driver after it has been loaded.
Note that the initGraphics() function must be called to
enter graphics mode; for more information, see the next
section.
THE GRAPHICS ENGINE'S FUNCTION SET
After a driver has been loaded, all of The Graphics Engine's
graphical functions can be accessed. To call a function,
simply execute
functionName(parameter list);
where functionName is the name of the desired function (eg.
line, filledRect) and parameter list is all parameters to
that function, if any.
A complete list of The Graphics Engine's functions follows.
*** Function: initGraphics
Syntax: void far initGraphics(void);
Purpose: Initialize graphics mode.
Parameters: None.
Return value: 1 on success, or 0 on error.
Remarks: On any call other than its first,
initGraphics will also restore the colour
palette which was active at the time
deInitGraphics was last called.
See also: deInitGraphics
*** Function: deInitGraphics
Syntax: void far deInitGraphics(void);
Purpose: Revert to 80x25 colour text mode.
Parameters: None.
Return value: None.
Remarks: deInitGraphics will keep a copy of the active
colour palette before shutting off graphics.
This palette will be restored by any future
call to initGraphics.
See also: initGraphics
*** Function: putImage
Syntax: void far putImage(int x, int y, void far
*image);
Purpose: Place a bitmap, or image, onto the screen.
Parameters: The bitmap starting at image will be placed
onto the screen with its upper-left
coordinate at (x,y).
Return value: None.
Remarks: Clipping is performed; the image may be
placed entirely on-screen, partially on-
screen, or entirely off-screen.
See also: getImage, imageSize, putLine, getLine
*** Function: putImageInv
Syntax: void far putImageInv(int x, int y, void far
*image);
Purpose: Place a bitmap, or image, on the screen.
Parameters: The bitmap starting at image will be placed
onto the screen with its upper-left
coordinate at (x,y).
Return value: None.
Remarks: putImageInv() differs from putImage() only in
that it allows for transparent, or invisible,
colours. If any pixel in the image buffer
has a value of zero, the corresponding pixel
on-screen will not be modified. Using
putImageInv() can avoid having black borders
around non-rectangular shapes.
*** Function: getImage
Syntax: void far getImage(int ulx, int uly, int lrx,
int lry, void far *image);
Purpose: Copy the specified rectangular portion of the
screen to memory.
Parameters: The portion of the screen with its upper-left
coordinate at (ulx,uly) and its lower-left
coordinate at (lrx,lry) will be copied into
the previously allocated memory region at
image (see imageSize).
Return value: None.
Remarks: Coordinates may be off-screen; getImage will
still function reliably.
See also: putImage, imageSize, putLine, getLine
*** Function: putLine
Syntax: void far putLine(int lineNum, int xOff, int
lineLen, void far *buf);
Purpose: Place one horizontal line of image data on
the screen.
Parameters: The one-line bitmap contained at buf, of
lineLen pixels, will be placed on-screen
starting at (lineNum,xOff).
Return value: None.
Remarks: No clipping is performed. Results are
undefined if any coordinate on the line is
off-screen.
See also: getLine, putImage, getImage
*** Function: getLine
Syntax: void far getLine(int lineNum, int xOff, int
lineLen, void far *buf);
Purpose: Copy one horizontal line from the screen to
memory.
Parameters: The horizontal line whose left coordinate is
(xOff,lineNum) and whose length is lineLen
pixels will be copied into the previously
allocated memory region at buf.
Return value: None.
Remarks: No clipping is performed. Results are
undefined if any coordinate on the line is
off-screen.
See also: putLine, putImage, getImage
*** Function: imageSize
Syntax: unsigned long far imageSize(int ulx, int uly,
int lrx, int lry);
Purpose: Determine the amount of memory required to
hold a rectangular portion of the screen.
Parameters: imageSize will calculate the amount of memory
required to hold the porion of the screen
whose upper-left coordinate is (ulx,uly) and
whose lower-left coordinate is (lrx,lry).
Return value: imageSize returns an unsigned long containing
the size of the area in bytes.
Remarks: Clipping is performed. imageSize is designed
for use with putImage and getImage. To use
it with putLine and getLine, subtract 4 from
the value it returns. (Image buffers have
four bytes of dimension information in them;
line buffers do not.)
See also: putImage, getImage, putLine, getLine
*** Function: putPixel
Syntax: void far putPixel(int x, int y, unsigned
colour);
Purpose: Place a single pixel on-screen.
Parameters: The pixel located at (x,y) will be set to the
colour contained in colour.
Return value: None.
Remarks: Clipping is not performed.
See also: getPixel
*** Function: getPixel
Syntax: unsigned far getPixel(int x, int y);
Purpose: Return the value of a pixel.
Parameters: getPixel will return the value of the pixel
at (x,y).
Return value: The value of the pixel at (x,y) is returned.
Remarks: Clipping is not performed.
See also: putPixel
*** Function: line
Syntax: void far line(int x1, int y1, int x2, int y2,
unsigned colour);
Purpose: Draw a line between two points.
Parameters: The line will be drawn joining (x1,y1) and
(x2,y2) in the colour contained in colour.
Return value: None.
Remarks: Clipping is not performed.
See also: horizLine
*** Function: horizLine
Syntax: void far horizLine(int y, int x1, int x2,
unsigned colour);
Purpose: Draw a horizontal line between two points.
Parameters: The line will be drawn between (x1,y) and
(x2,y) in the colour contained in colour.
Return value: None.
Remarks: Clipping is not performed.
See also: line
*** Function: drawRect
Syntax: void far drawRect(int ulx, int uly, int lrx,
int lry, unsigned colour);
Purpose: Draw a rectangle.
Parameters: The rectangle will be drawn with its upper-
left coordinates at (ulx,uly) and its lower-
left coordinates at (lrx,lry), in the colour
contained in colour.
Return value: None.
Remarks: Clipping is not performed.
See also: filledRect
*** Function: filledRect
Syntax: void far filledRect(int ulx, int uly, int
lrx, int lry, unsigned colour);
Purpose: Draw a filled rectangle.
Parameters: The rectangle will be drawn with its upper-
left coordinates at (ulx,uly) and its lower-
left coordinates at (lrx,lry), in the colour
contained in colour.
Return value: None.
Remarks: Clipping is not performed.
See also: drawRect
*** Function: setPaletteReg
Syntax: void far setPaletteReg(unsigned palReg,
unsigned char red, unsigned char green,
unsigned char blue);
Purpose: Set a palette register.
Parameters: The red, green, and blue components of the
palette register palReg will be set to red,
green, and blue respectively.
Return value: None.
Remarks: None.
See also: getPaletteReg, setBlockPalette,
getBlockPalette
*** Function: getPaletteReg
Syntax: void far getPaletteReg(unsigned palReg,
unsigned char far *red, unsigned char far
*green, unsigned char far *blue);
Purpose: Return the current settings of a palette
register.
Parameters: The red, green, and blue contents of the
palette register palReg will be stored in
red, green, and blue respectively.
Return value: The red, green, and blue components of the
palette register are returned in red, green,
and blue.
Remarks: None.
See also: setPaletteReg, setBlockPalette,
getBlockPalette
*** Function: setBlockPalette
Syntax: void far setBlockPalette(unsigned firstReg,
unsigned numRegs, void far *data);
Purpose: Set a block of palette registers.
Parameters: numRegs palette registers, starting at
firstReg, will be set to the values contained
in data.
Return value: None.
Remarks: The memory region at data is organised in
groups of three bytes; each group corresponds
to one palette register, and each group is
made up of, in order, the red, green, and
blue components. The first group is for the
first register, the second for the second,
and so on.
See also: getBlockPalette, setPaletteReg, getPaletteReg
*** Function: getBlockPalette
Syntax: void far getBlockPalette(unsigned firstReg,
unsigned numRegs, void far *data);
Purpose: Get the values of a block of palette
registers.
Parameters: The values of numRegs palette registers,
starting at firstReg, will be stored in the
previously allocated data.
Return value: The values are returned in data.
Remarks: The memory region at data is organised in
groups of three bytes; each group corresponds
to one palette register, and each group is
made up of, in order, the red, green, and
blue components. The first group is for the
first register, the second for the second,
and so on.
See also: setBlockPalette, setPaletteReg, getPaletteReg
*** Function: clearGraphics
Syntax: void far clearGraphics(unsigned colour);
Purpose: Clear the screen.
Parameters: The screen will be cleared to the colour
contained in colour.
Return value: None.
Remarks: None.
See also: filledRect
WRITING GRAPHICS DRIVERS
To build a new graphics driver, follow these steps:
1. Copy the file SHELL.ASM to another file, for example,
MYDRV.ASM.
2. Change the maximum X-coordinate, Y-coordinate, and
colour number to the appropriate values. (They are clearly
identified with comments.)
3. A graphics driver must always contain the initGraphics
routine. Replace the default one from SHELL.ASM with
whatever the appropriate code is. (Be sure to add return
value logic, described in the initGraphics() description
above.)
4. If the new video mode is not supported by the video
BIOS, custom putPixel and getPixel routines must be written
and placed in the driver. Doing so is advised anyway, as
the BIOS is notoriously slow.
5. The default palette management routines assume that the
video mode's palette registers have a resolution of six
bits. The standard VGA has only 18-bit resolution (six bits
for each of red, green, and blue), but some SuperVGAs
support 24-bit resolution (8 bits each). If the video mode
for which the driver is being written supports a true eight-
bit palette, the four palette management routines should be
written and placed in the driver.
6. Many routines assume that each pixel has a size of
exactly one byte, as 256-colour modes are so common.
(Namely, these routines are putImage, getImage, putLine,
getLine, imageSize, putPixel, and getPixel.) If the new
video mode does not have one-byte pixels, these routines
should be written and placed in the driver.
7. If speed is important, write any routines that have not
already been written.
8. For every routine that has been written, a change must
be made in the header of the driver's source code. As an
example, assume that horizLine has been written. Find the
"; horizLine" comment near the top of the source file.
Change the "0" to the left of it to the exact name of the
new horizLine routine. Repeat this procedure if necessary,
until the change has been made for every routine contained
in the driver.
9. A usable driver must be created from the source code.
This process involves three steps. First, assemble the .ASM
source file to an .OBJ object file. Then, link the .OBJ so
it becomes an .EXE file. Third, run EXE2BIN, which comes
with DOS. Assuming the driver's source code was called
MYDRV, EXE2BIN's command line would be "EXE2BIN MYDRV.EXE
MYDRV.DRV". When this last step is completed, there will be
a newly created driver, ready to be loaded and used with The
Graphics Engine. The file CDRV.BAT is included to automate
this chore; it assumes the use of TASM and TLINK. Note
that, since 16-bit offsets are used, the final driver may
not be larger than 64 Kb (not a likely problem).
TERMS OF USAGE AND DISTRIBUTION
The Graphics Engine source code and associated documentation
are copyright (c) 1993 by Matthew Hildebrand.
The Graphics Engine, consisting of the files listed in the
PACKING LIST section, may be distributed freely, so long as:
1. The distributed package is complete, and its
contents are not modified in any way.
2. The distributed package is not sold for profit.
The Graphics Engine is not free; no part of it may be used
in any program without first purchasing it. After an
individual or organization ("the Purchaser") has purchased a
copy of The Graphics Engine, the Purchaser is granted
permission to:
1. Use any or all of The Graphics Engine in as many
software packages as the Purchaser likes.
2. Distribute any software packages built using The
Graphics Engine without royalties.
3. Modify any of the program code, and use the
modified code as described in 1 and 2 above.
Note that the Purchaser is granted permission to use any
version of The Graphics Engine, including any new ones when
they are released; ie., upgrades are free.
The privileges granted to the Purchaser by purchasing The
Graphics Engine may be retracted if either or both of the
following conditions is broken:
1. The copyright notice, which reads "The Graphics
Engine -- Copyright (c) 1993 by Matthew
Hildebrand" must be included in the executable
portion of any software package built using it, as
well as in any driver files (designed to work with
The Graphics Engine) which are part of that
software package. The file TGE.C, as it is
shipped, contains this notice, as do the sources
for the drivers.
2. Any program code derived or directly obtained from
The Graphics Engine may not be distributed in any
way, unless the recipient has also purchased a
copy of The Graphics Engine.
In order to purchase a copy of The Graphics Engine, send $20
(US or Canadian) to Matthew Hildebrand at the address listed
in CONTACTING THE AUTHOR below. Payment by money order,
check, or cash is acceptable. Thank you in advance.
CONTACTING THE AUTHOR
I would appreciate hearing any questions, comments, bug
reports, or suggestions for improvement. If you have any,
feel free to contact me. I can be reached at either of the
following addresses. Contributions of any kind to help
improve this project are welcome.
Snail mail:
Matthew Hildebrand
4 College St.
St. Catharines, ON
Canada
L2R 2W7
Fido NetMail:
1:247/128.2
OBTAINING THE GRAPHICS ENGINE
The most recent copy of The Graphics Engine may be obtained
via File Request from 1:247/128 (14400 bps V.32bis) using
the magic file name "TGE"; unlisted nodes and points are
welcome. The Graphics Engine is also available via first-
call download from 1:247/128 at (416)-935-6628.
REVISION HISTORY
1.01 First public release.
ACKNOWLEDGEMENT
There are people whom I would like to thank for their
suggestions, beta-testing, patience, and help with
distribution. You know who you are.
LEGAL MUMBO JUMBO
All software and documentation associated with The Graphics
Engine is provided "as is", and without warranty of any
kind. The author may not be held liable for any damage or
misfortune that the usage of this software may cause.
Although the software has undergone extensive testing, there
is a chance that it may crash anyway.
All registered trademarks in this document belong to
whomever it is that owns them.