allbery@ncoast.UUCP (08/29/87)
#! /bin/sh # This is a shell archive, meaning: # 1. Remove everything above the #! /bin/sh line. # 2. Save the resulting text in a file. # 3. Execute the file with /bin/sh (not csh) to create the files: # doc # This archive created: Thu Aug 27 10:21:01 1987 export PATH; PATH=/bin:$PATH if test ! -d 'doc' then echo shar: creating directory "'doc'" mkdir 'doc' fi echo shar: entering directory "'doc'" cd 'doc' echo shar: extracting "'grafex1.c'" '(1427 characters)' if test -f 'grafex1.c' then echo shar: will not over-write existing file "'grafex1.c'" else sed 's/^X//' << \SHAR_EOF > 'grafex1.c' X/* X * grafex1.c X * X * example program using the Grafix library. draws an n-gon and all X * its diagonals. X * X * compile with: X * MSC - msc grafex1; X * link grafex1,,,grafix X * X * TC - tcc grafex1 <grafix lib directory>\grafix.lib X */ X X#include <stdio.h> X#include <conio.h> X#include <math.h> X#include "graf.h" X X#define pi 3.1415926 X#define MAXVERT 100 X Xmain() X{ X int n, i, j, d; X unsigned c; X struct g_info inf; X struct { X int x, y; X } vert[MAXVERT]; X X printf("n: "); X scanf("%d", &n); X if (n < 2 || n > MAXVERT) { X printf("Oop Ack!\n"); X exit(1); X } X X g_init(0); X g_open(CGA_320); /* use 4-color mode on CGA. on an EGA, the mode */ X /* parameter is ignored and 16-color mode is used */ X g_info(&inf); X X/* space n vertices equally on an ellipse that fits nicely on the screen */ X X for (i=0; i<n; i++) { X vert[i].x = inf.xsize/2 + (inf.xsize/3)*sin(2*pi/n*i); X vert[i].y = inf.ysize/2 - (inf.ysize/3)*cos(2*pi/n*i); X } X X/* X * draw the figure. the colors are selected so that points that are the X * same distance from each other on the ellipse have the same color. X */ X X for (i=0; i<n; i++) X for (j=i+1; j<n; j++) { X d = j-i; X if (d > n/2) d = n - d; X c = (float)d/(n/2+1)*inf.colormax + 1; X g_line(vert[i].x, vert[i].y, vert[j].x, vert[j].y, c); X } X X/* wait... */ X X g_writestr(0, 0, "Press any key...", 1, -1); X getch(); X X/* and clean up. */ X X g_close(); X} SHAR_EOF if test 1427 -ne "`wc -c < 'grafex1.c'`" then echo shar: error transmitting "'grafex1.c'" '(should have been 1427 characters)' fi fi # end of overwriting check echo shar: extracting "'grafex2.c'" '(1557 characters)' if test -f 'grafex2.c' then echo shar: will not over-write existing file "'grafex2.c'" else sed 's/^X//' << \SHAR_EOF > 'grafex2.c' X/* X * grafex2.c X * X * the same example program, done with halo calls X * X * compile with: X * MSC - msc grafex2; X * link grafex2,,,grafix X * X * TC - tcc grafex2 <grafix lib directory>\grafix.lib X */ X X#include <stdio.h> X#include <conio.h> X#include <math.h> X#include "graf.h" X#include "halo.h" X X#define pi 3.1415926 X#define MAXVERT 100 X Xmain() X{ X int n, i, j, d; X float x1, y1, x2, y2; X int c; X struct g_info inf; X struct { X float x, y; X } vert[MAXVERT]; X X printf("n: "); X scanf("%d", &n); X if (n < 2 || n > MAXVERT) { X printf("Oop Ack!\n"); X exit(1); X } X X g_init(0); X g_open(CGA_320); /* use 4-color mode on CGA. on an EGA, the mode */ X /* parameter is ignored and 16-color mode is used */ X g_info(&inf); X halo_init(); X X x1 = -3; /* lower left corner */ X y1 = -3; X x2 = 3; /* upper right corner */ X y2 = 3; X setworld(&x1, &y1, &x2, &y2); X X/* space n vertices equally on an ellipse that fits nicely on the screen */ X X for (i=0; i<n; i++) { X vert[i].x = 2.0*sin(2*pi/n*i); X vert[i].y = 2.0*cos(2*pi/n*i); X } X X/* X * draw the figure. the colors are selected so that points that are the X * same distance from each other on the ellipse have the same color. X */ X X for (i=0; i<n; i++) X for (j=i+1; j<n; j++) { X d = j-i; X if (d > n/2) d = n - d; X c = (float)d/(n/2+1)*inf.colormax + 1; X setcolor(&c); X movabs(&vert[i].x, &vert[i].y); X lnabs(&vert[j].x, &vert[j].y); X } X X/* wait... */ X X g_writestr(0, 0, "Press any key...", 1, -1); X getch(); X X/* and clean up. */ X X g_close(); X} SHAR_EOF if test 1557 -ne "`wc -c < 'grafex2.c'`" then echo shar: error transmitting "'grafex2.c'" '(should have been 1557 characters)' fi fi # end of overwriting check echo shar: extracting "'grafix.tex'" '(835 characters)' if test -f 'grafix.tex' then echo shar: will not over-write existing file "'grafix.tex'" else sed 's/^X//' << \SHAR_EOF > 'grafix.tex' X\input setup.txi X X%\chapter 12 Grafix\par X\def\chapno{0} X\vskip 1cm X\centerline{\bigbf Grafix} X\vskip 0.5cm X\centerline{A PC graphics library} X\bigskip X\centerline{\it By Scott Snyder} X\vskip 1cm X XGrafix is a simple graphics library for the IBM Color Graphics Adapter X(CGA), Enhanced Graphics Adapter (EGA), and compatables. It consists Xof two parts: a collection of simple primitives and a collection of Xroutines that emulate some of the most common functions of the popular XHALO graphics library. Detailed descriptions of the library functions are Xgiven on the following pages. X X\vfill\supeject X\input man.txi X X\def\itpnt (#1, #2){(\hbox{\it #1}, \hbox{\it #2\/})} X\def\itpntb (#1, #2){(\hbox{\it #1}, \break\hbox{\it #2\/})} X X\def\wholemanname {Grafix 1.0} X X\input grafsec1.tex X\input grafsec2.tex X%\input test.tex X X\endchap X X\end X SHAR_EOF if test 835 -ne "`wc -c < 'grafix.tex'`" then echo shar: error transmitting "'grafix.tex'" '(should have been 835 characters)' fi fi # end of overwriting check echo shar: extracting "'grafsec1.tex'" '(20563 characters)' if test -f 'grafsec1.tex' then echo shar: will not over-write existing file "'grafsec1.tex'" else sed 's/^X//' << \SHAR_EOF > 'grafsec1.tex' X\manpage intro(1) X X\manname X intro --- introduction to graphics functions X\mandscr X X\manhead Using the library\par X X When writing a program that uses the Grafix library, you should X include the file \bfnc graf.h . This file defines prototypes for X all the graphics functions and several symbolic constants. X When linking, simply include the Grafix library in the list X of libraries you supply to LINK. The small model library X is named \bfnc grafix.lib , and the medium, compact, and X large model libraries are named \bfnc grafixm.lib , X \bfnc grafixc.lib , and \bfnc grafixl.lib , respectively. X X Note that \itwd g_init must be the first function in the X library to be called, and that \itwd g_open must be the second. X When you finish with the graphics display, you should X call \itwd g_close to reset the display to text mode. X X\manhead Supported hardware\par X X The Grafix library currently supports the following graphics X hardware: X X IBM Color Graphics Adapter (CGA) with a Color Display or equivalents. X X IBM Enhanced Graphics Adapter (EGA) with a Enhanced Graphics Display, X with a Color Display, or with a Monochrome Display or equivalents. X X\manhead Colors\par X It should be kept in mind that the color values which are passed to X the graphics X routines and written into the graphics buffers correspond only X indirectly to the colors actually displayed on the screen. The X mapping between color values and displayed colors can X be changed by the \itwd g_setback and \itwd g_setpal functions. X See the ``colors(1)'' manual page for a description of the available X colors. X\manex X\vinput grafex1.c X\manpend X X\manpage colors(1) X X\manpage colors(1) X X\manname X colors --- summary of displayable colors X\mandscr X The following summarizes the displayable colors in the X various supported graphics modes. X X\manhead CGA 320 by 200 four color mode\par X X In this mode, color value~0 is the background. By default it X is black but may be changed by use of the \itwd g_setback function X to any of the following colors: X\begintable X\centerline{\vbox{% X\settabs\+&\it val&ue\quad&\cr X \+&\it value&&\it color\cr X \smallskip X \+&\hfill 0&& black\cr X \+&\hfill 1&& blue\cr X \+&\hfill 2&& green\cr X \+&\hfill 3&& cyan\cr X \+&\hfill 4&& red\cr X \+&\hfill 5&& purple\cr X \+&\hfill 6&& brown\cr X \+&\hfill 7&& white\cr X \+&\hfill 8&& grey\cr X \+&\hfill 9&& bright blue\cr X \+&\hfill 10&& bright green\cr X \+&\hfill 11&& bright cyan\cr X \+&\hfill 12&& bright red\cr X \+&\hfill 13&& bright purple\cr X \+&\hfill 14&& bright yellow\cr X \+&\hfill 15&& bright white\cr X}} X\endtable X Color values~ 1--3 are the foreground, and two color mappings X or ``palettes'' are available. By default, palette 1 is X active, but it may be X changed with the \itwd g_setpal function with the following X results: X\begintable X\centerline{\vbox{% X \settabs\+&\it color&\it value\quad &background\quad&\cr X \+&\it color value&&$\it palette=0$&$\it palette=1$\cr X \smallskip X \+&& 0 &background&background\cr X \+&& 1 &green&cyan\cr X \+&& 2 &red&magenta\cr X \+&& 3 &yellow&white\cr X}} X\endtable X X\manhead CGA 640 by 200 two color mode\par X X In this mode, color value~0 is the background and is always X displayed as black. Color value~1 is the foreground and has X a default color of white. This may be changed, however, with X the \itwd g_setpal function to any of the colors listed as X a CGA background color in the previous section. X X\manhead EGA sixteen color mode\par X X The EGA has 64 displayable colors, X 16 of which can be displayed at any time. The displayable X colors are represented as a six-bit value with format X rgbRGB, where the intensities of of the primary colors X (red, green, and blue) are in the range 0--3 and represented X as the two-bit values Rr, Gg, and Bb. The mapping of color X values to these colors can be changed using the \itwd g_setpal X function (or \itwd g_setback for color value~0). The default mapping X is as follows: X\begintable X\centerline{\vbox{% X \settabs\+&\it color &\it value\quad&bright yellow\quad&\it six-bit &\cr X \+&\it color value&&\it color&\it six-bit value\cr X \smallskip X \+&\hfill 0&&black&\hfill 0&\cr X \+&\hfill 1&&blue&\hfill 1&\cr X \+&\hfill 2&&green&\hfill 2&\cr X \+&\hfill 3&&cyan&\hfill 3&\cr X \+&\hfill 4&&red&\hfill 4&\cr X \+&\hfill 5&&purple&\hfill 5&\cr X \+&\hfill 6&&brown&\hfill 20&\cr X \+&\hfill 7&&white&\hfill 7&\cr X \+&\hfill 8&&grey&\hfill 56&\cr X \+&\hfill 9&&bright blue&\hfill 57&\cr X \+&\hfill 10&&bright green&\hfill 58&\cr X \+&\hfill 11&&bright cyan&\hfill 59&\cr X \+&\hfill 12&&bright red&\hfill 60&\cr X \+&\hfill 13&&bright purple&\hfill 61&\cr X \+&\hfill 14&&bright yellow&\hfill 62&\cr X \+&\hfill 15&&bright white&\hfill 63&\cr X}} X\endtable X X\mansee X intro(1), g_setback(1), g_setpal(1). X\manpend X X\manpage g_box(1) X X\manname X g_box --- draw a rectangular box X\mansyn X void g_box(x1, y1, x2, y2, color) X X int x1, y1, x2, y2; X unsigned color; X\mandscr X The \itwd g_box function draws the rectangular box X defined by the points X \itpnt (x1, y1) and \itpnt (x2, y2) in the current drawing buffer X with color~\itnc color . If xor mode is on, the rectangle will be X logically xor'ed with the existing data in the buffer. X\mansee X g_line(1). X\manpend X X\manpage g_circle(1) X X\manname X g_circle --- draw a circle X\mansyn X void g_circle(x, y, r, color) X X int x, y, r; X unsigned color; X\mandscr X The \itwd g_circle function draws a circle centered on the point X \itpnt (x, y) with radius~\itnc r . The circle is drawn in the X current drawing buffer with color~\itnc color . If xor mode is X on, the circle is logically xor'ed with the existing data in the X buffer. The radius is taken to be half of the horizontal diameter X of the circle, in pixels (because of the graphics display's X aspect ratio, this will not in general be the same as the vertical X radius of the circle). X\mansee X g_ellipse(1). X\manpend X X\manpage g_clear(1) X X\manname X g_clear --- clear the area within the clipping boundary to a X given color X\mansyn X void g_clear(color) X X unsigned color; X\mandscr X The \itwd g_clear function sets all the pixels within the current X clipping boundary in the current drawing buffer to color \itnc color . X\mansee X g_clearall(1), g_regfill(1), g_setclip(1). X\manpend X X\manpage g_clearall(1) X X\manname X g_clearall --- clear an entire buffer to a specified color X\mansyn X void g_clearall(color) X X unsigned color; X\mandscr X The \itwd g_clearall function sets the entire current drawing buffer X to color~\itnc color , regardless of clipping boundaries. For X clearing the entire screen, \itwd g_clearall should be X somewhat faster than \itnc g_clear . X\mansee X g_clear(1). X\manpend X X\manpage g_close(1) X X\manname X g_close --- terminate graphics drawing X\mansyn X void g_close() X\mandscr X The \itwd g_close function terminates graphics drawing and X resets the display to 80-column text mode. X\mansee X g_init(1), g_open(1). X\manpend X X\manpage g_ellipse(1) X X\manname X g_ellipse --- draw an ellipse X\mansyn X void g_ellipse(x, y, r_sub_m, aspect, color) X X int x, y, r_sub_m; X float aspect; X unsigned color; X\mandscr X The \itwd g_ellipse function draws an ellipse in the current X drawing buffer X with color~\itwd color centered on the point~\itpnt (x, y) with X semi-major axis length~\itwd r_sub_m and aspect ratio~\itnc aspect . X The aspect ratio is defined as the ratio of the vertical diameter X of the ellipse to its horizontal diameter, and the semi-major X axis length is half the length of the largest diameter (which X is vertical if $ aspect > 1.0 $ and horizontal if $ aspect < 1.0 $). X If xor mode is on, the ellipse will be logically xor'ed with the X existing data in the buffer. X Note that this routine can only be used to draw ellipses that have X their axes oriented horizontally and vertically. X\manbugs X The aspect ratio of the screen is not accounted for in this X routine. If you want to have an ellipse drawn in the same X shape on all supported displays, get the display's aspect X ratio with the \itwd g_info call and multiply your desired X aspect ratio by it before passing it to \itnc g_ellipse . X\mansee X g_circle(1), g_info(1). X\manpend X X\manpage g_info X X\manname X g_info --- get information about the graphics device in use X\mansyn X void g_info(info) X X struct g_info *info; X\mandscr X The \itwd g_info function copies parameters for the current mode X and adapter X into the structure~\itnc info . The \itwd g_info structure X is defined in the file \bfwd graf.h as: X\mancodebeg X struct g_info { X unsigned card; X unsigned display; X unsigned xsize, ysize; X unsigned xchsize, ychsize; X unsigned colormax; X unsigned pages; X unsigned curpage; X }; X\mancodeend X \itwd Card and \itwd display contain the current types of X the graphics card and the graphics display, respectively X (the types are defined in \bfwdn graf.h ). \itwd Xsize X and \itwd ysize contain the X and Y sizes of the display, X \itwd xchsize and \itwd ychsize contain the size of the X screen in characters, and X \itwd colormax contains the maximum color value (i.e., if X there are four colors, \itwd colormax will be 3). \itwd Pages X contains the number of displayable pages that the graphics adapter X supports and \itwd curpage contains the page that is currently X being displayed. X X \itwd G_info must be called \itwd after the display is X opened with \itnc g_open . X\mansee X g_init(1), g_open(1). X\manpend X X X\manname X g_init --- initialize the graphics library X\mansyn X void g_init(card, display) X X unsigned card, display; X\mandscr X The \itwd g_init function initializes the graphics library for X the graphics card and display in use. If \itwd g_init is called X with \itwd card set to zero, it will attempt to determine X what graphics hardware is attached. The \itwd display parameter X is ignored in this case and may be omitted. If \itwd card is X one of the (nonzero) symbolic constants for graphics adapters X defined in \bfnc graf.h , the graphics library assumes that X that card is attached. In this case, the parameter~\itwd display X must also be specified as one of the symbolic constants defined X in \bfnc graf.h . X X This function must be called before any others. X\mansee X g_open(1), g_close(1), g_info(1). X\manpend X X\manpage g_line(1) X X\manname X g_line --- draw a line X\mansyn X void g_line(x1, y1, x2, y2, color) X X int x1, y1, x2, y2; X unsigned color; X\mandscr X The \itwd g_line function draws a line in the current drawing X buffer with color~\itwd color between the points \itpnt (x1, y1) X and~\itpnt (x2, y2). If xor mode is on, the line is logically X xor'ed with the existing data in the buffer. X\mansee X g_box(1), g_point(1). X\manpend X X\manpage g_open(1) X X\manname X g_open --- turn on graphics mode and prepare for drawing X\mansyn X void g_open(mode) X X unsigned mode; X\mandscr X The \itwd g_open function switches the display to a graphics X mode and prepares the graphics routines for drawing. The X interpretation of the \itwd mode parameter is device-dependent. X Currently, on the CGA, \hbox{mode = CGA_640} is the 640 by 200 X two color X mode, and \hbox{mode = CGA_320} is the 320 by 200 four color mode. X The \itwd CGA_640 and \itwd CGA_320 constants are defined X in \bfnc graf.h . On the X EGA, the \itwd mode parameter is ignored, and the display X is opened in the 640 by 350 sixteen color mode using the X Enhanced Color Display, the 640 by 200 sixteen color mode X using the Color Display, and the 640 by 350 monochrome X mode using the Monochrome Display. To use an EGA in a X CGA mode, pass CGA as the \itwd card parameter to \itnc g_init . X X Besides setting the graphics mode, the \itwd g_open function X also clears the screen, resets the color mapping to the default, X turns off xor mode and screen buffering, and resets the X clipping boundaries to the physical boundaries of the screen. X X This function must be called after \itnc g_init , and before X any other graphics functions. X\mansee X g_init(1), g_close(1), g_info(1). X\manpend X X\manpage g_point(1) X X\manname X g_point --- plot a point X\mansyn X void g_point(x, y, color) X X int x, y; X unsigned color; X\mandscr X The \itwd g_point function sets the point~\itpnt (x, y) in the X current drawing buffer to color~\itnc color . If xor mode is on, X the point is xor'ed with the existing data in the buffer. X\mansee X g_line(1). X\manpend X X\manpage g_regfill(1) X X\manname X g_regfill --- fill a rectangular region with a color X\mansyn X void g_regfill(x1, y1, x2, y2, color) X X int x1, y1, x2, y2; X unsigned color; X\mandscr X The \itwd g_regfill function sets all the points in the current X drawing buffer within the rectangle defined by the points X \itpnt (x1, y1) and \itpnt (x2, y2) (and within the current X clipping boundary) to color~\itnc color . X\manbugs X Doesn't support xor mode X\mansee X g_clear(1). X\manpend X X\manpage g_setback(1) X X\manname X g_setback --- set the background color X\mansyn X void g_setback(color) X X unsigned color; X\mandscr X The \itwd g_setback function changes the color X displayed for the background color value (0). X X The actual functioning of this routine depends on the X graphics mode as follows: X X\manhead CGA 640 by 200 two color mode\par X X The \itwd g_setback function X does not work in this mode. X X\manhead CGA 320 by 200 four color mode\par X X The \itwd color parameter should X be the value of X one of the colors listed in the CGA background color table X on the ``colors(1)'' manual page. X X\manhead EGA sixteen color mode\par X X The \itwd color parameter is a six-bit color value X as discussed on the EGA section in the ``colors(1)'' manual page. X\manbugs X Doesn't work in the CGA two color mode. X\mansee X intro(1), colors(1), g_setpal(1). X\manpend X X\manpage g_setbuf(1) X X\manname X g_setbuf --- turn on screen buffering X\mansyn X void g_setbuf(flag) X X unsigned flag; X\mandscr X The \itwd g_setbuf function turns screen buffering on, if X \itwd flag is nonzero, or off if \itwd flag is zero. X When screen buffering is on, drawing takes place in X an off-screen buffer, instead of in the buffer that is currently X being displayed. This off-screen buffer can then be made X visible almost instantaneously with the \itwd g_show function. X This can be a great help in achieving smooth animation X and other effects. X X There is, however, one important consideration to keep in X mind. For effeciency reasons, the \itwd g_show function X is implemented differently on X different graphics devices. On the CGA, the drawing is X done in a single off-screen buffer which is then copied X to the physical screen buffer when \itwd g_show is X called. On the EGA, which has two display pages, drawing X is done in the page that is not visible and the pages are X swapped when \itwd g_show is called. This means that X immediately after calling \itwd g_show on a CGA, X the drawing buffer contains a copy of the image X being shown on the display. But X immediately after calling it on an EGA, X the drawing buffer contains the image that was visible X just \itncs before it was called. This difficulty X can be avoided by the simple expedient of erasing the X active area of the drawing buffer immediately after X every call to \itnc g_show . X\mansee X g_show(1). X\manpend X X\manpage g_setclip(1) X X\manname X g_setclip --- set the clipping boundaries X\mansyn X void g_setclip(x1, y1, x2, y2) X X int x1, y1, x2, y2; X\mandscr X The \itwd g_setclip function restricts drawing X to the rectangular area defined by the points X \itpnt (x1, y1) and \itpnt (x2, y2). Points that lie outside X this rectangle (the ``clipping boundaries'') will be protected X from change by any the routines that respect the clipping boundaries. X The clipping boundaries X cannot be set outside of the physical screen. The functions X which respect the clipping boundaries are {\it g_box, X g_circle, g_clear, g_ellipse, g_line, g_point, } and X \itnc g_regfill . X\manpend X X\manpage g_setpal(1) X X\manname X g_setpal --- change the color mapping X\mansyn X void g_setpal(palette, value) X X unsigned palette, value; X\mandscr X The \itwd g_setpal function allows one to change the mapping X between the foreground color values passed to the graphics X routines and the visible colors actually displayed. X X The actual functioning of this routine depends on the graphics X mode in use as follows: X X\manhead CGA 640 by 200 two color mode\par X X The \itwd g_setpal function X changes the color of the foreground color X value (1). The value of \itwd palette is ignored, X and \itwd value should be the value of one of the X colors listed in CGA background color table in the X ``colors(1)'' manual page. X The visible color of the foreground will be changed to this X color. X X\manhead CGA 320 by 200 four color mode\par X X In this mode, the \itwd value parameter is ignored, and X \itwd palette should be either 0 or 1. X The displayed colors are given by the following table: X\begintable X\centerline{\vbox{% X \settabs\+&\it color&\it value\quad &background\quad&\cr X \+&\it color value&&$\it palette=0$&$\it palette=1$\cr X \smallskip X \+&& 0 &background&background\cr X \+&& 1 &green&cyan\cr X \+&& 2 &red&magenta\cr X \+&& 3 &yellow&white\cr X}} X\endtable X X\manhead EGA sixteen color mode\par X X In this mode, the \itwd g_setpal function X directly sets the visible color of the color value given X by \itwd palette to \itnc value , which is a six-bit X color as discussed in the EGA section of the ``colors(1)'' X manual page. X\mansee X intro(1), colors(1), g_setback(1). X\manpend X X X\manpage g_setxor(1) X X\manname X g_setxor --- turn xor mode on or off X\mansyn X void g_setxor(flag) X X unsigned flag; X\mandscr X The \itwd g_setxor function turns xor mode on if~\itwd flag X is nonzero, or off if~\itwd flag is zero. When xor mode is X off, drawn objects are simply written over existing data in X the drawing buffer. But if xor mode is on, drawn objects X are logically xor'ed with the existing data. Thus if an object X is drawn twice in a row in exactly the same position with xor X mode on, it will be completely erased after the second X drawing and the image on the X screen restored to its state previous to the first drawing. X This makes xor mode useful for animation and other effects. X Functions which support xor mode are {\it g_box, g_circle, X g_ellipse, g_line,} and \itnc g_point . X\manpend X X\manpage g_show(1) X X\manname X g_show --- make the drawing buffer visible X\mansyn X void g_show() X\mandscr X If screen buffering is on, the \itwd g_show function makes X the drawing buffer visible by either copying it to the X physical screen buffer (on adapters with only one page) or X swapping it with the currently visible page (on adapters X with more than one page). If screen buffering is off, X \itwd g_show does nothing. X X See the description of the \itwd g_setbuf function for X further discussion of screen buffering. X\mansee X g_setbuf(1). X\manpend X X\manpage g_writech(1) X X\manname X g_writech --- write a character X\mansyn X void g_writech(row, col, ch, color, page) X X unsigned row, col; X char ch; X unsigned color; X int page; X\mandscr X The \itwd g_writech function writes the single character~\itwd ch X at character position~\itpnt (row, col) with color~\itnc color . X If~\itwd page is $-$1, the character is written to the current X drawing buffer; otherwise it is written to page~\itwd page X (note: this is not supported with the CGA, as it only X has one page). X\manbugs X With the CGA adapter, the \itwd page parameter is ignored. X X Xor mode is not supported. X X Clipping boundaries are not respected. X\mansee X g_writestr(1). X\manpend X X\manpage g_writestr(1) X X\manname X g_writestr --- write a string teletype style X\mansyn X void g_writestr(row, col, s, color, page) X X unsigned row, col; X char *s; X unsigned color; X int page; X\mandscr X The \itwd g_writestr writes the null-terminated string X pointed to by~\itwd s starting at character position X \itpnt (row, col) with color~\itnc color . X If~\itwd page is $-$1, the character is written to the current X drawing buffer; otherwise it is written to page~\itwd page X (note: this is not supported with the CGA, as it only X has one page). X X The characters are written from left to right, top to bottom. X If the writing goes off the right edge of the screen, it X continues at the beginning of the next line. If the X writing goes off the bottom of the screen, the function is aborted. X X The only special characters recognized are newline (octal X 12), which causes the writing to wrap around to the beginning X of the next line, and carriage return (octal 15) which X is simply ignored. X\manbugs X With the CGA adapter, the \itwd page parameter is ignored. X X Xor mode is not supported. X X Clipping boundaries are not respected. X\mansee X g_writech(1). X\manpend X X SHAR_EOF if test 20563 -ne "`wc -c < 'grafsec1.tex'`" then echo shar: error transmitting "'grafsec1.tex'" '(should have been 20563 characters)' fi fi # end of overwriting check echo shar: extracting "'grafsec2.tex'" '(14504 characters)' if test -f 'grafsec2.tex' then echo shar: will not over-write existing file "'grafsec2.tex'" else sed 's/^X//' << \SHAR_EOF > 'grafsec2.tex' X\manpage intro(2) X X\manname X intro --- introduction to halo emulation library X\mandscr X The halo emulation library is a collection of routines that X emulate some of the most frequently used routines of the X popular HALO graphics library. It was written to assist in X converting HALO programs to the Grafix library. X X To use the halo functions, you should include the X file \bfwd halo.h at the start of your program and X link with the graphics library as usual. X X Most of these functions are fairly straightforward; however, X there are a few things you should be aware of. First of X all, and probably most important, all the parameters to all X the halo routines must be passed by reference, i.e., you must pass X pointers to the desired arguments to the graphics routines, not X the arguments themselves. Second, the halo routines X remember one point, called the graphics cursor, and X a color, called the current drawing color. The halo X drawing routines use these values instead of explicitly X passed parameters in many instances. They may be set with X the \itnc movabs , \itnc movrel , and \itwd setcolor functions. X And third, the halo drawing routines always take X world coordinates, never device coordinates (as is X possible in the original HALO library). X\manex X\vinput grafex2.c X\manpend X X\manpage box(2) X X\manname X box --- draw a rectangular box X\mansyn X void box(x1, y1, x2, y2) X X float *x1, *y1, *x2, *y2; X\mandscr X The \itwd box function draws the rectangular box defined by the points X \itpnt (*x1, *y1) and \itpnt (*x2, *y2) (in world coordinates) X in the current drawing buffer with the current drawing color. X If xor mode is on, the rectangle is logically xor'ed with the X existing data in the buffer. X\mansee X g_box(1). X\manpend X X\manpage cir(2) X X\manname X cir --- draw a circle X\mansyn X void cir(r) X X float *r; X\mandscr X The \itwd g_cir function draws a circle centered on the current X graphics cursor with radius~\itwd r (in world coordinates). X The circle is drawn in the current drawing buffer with the current X drawing color. If xor mode is X on, the circle is logically xor'ed with the existing data in the X buffer. The radius is taken to be half of the horizontal diameter X of the circle, in world coordinates. X\mansee X g_circle(1). X\manpend X X\manpage coordinates(2) X X\manname X coordinates --- coordinate systems used X\mandscr X The halo routines utilize three different coordinate X systems: device, normalized device, and world. The following X sections explain these coordinate systems and their X interrelationships. X X\manhead Device coordinates\par X X The first and simplest coordinate system is device coordinates. X In device coordinates, the origin is at the upper left X corner of the screen and the axes are scaled in pixels. X Thus in the four-color mode of the CGA, for example, X device coordinates range from (0, 0) to (319, 199). X All the graphics routines listed in section 1 of this manual X use device coordinates. X Device coordinates are always expressed as integers. X X\vskip\baselineskip X\centerline{\vbox{% X \hbox to 4in{(0, 0)\hfill (319, 0)}% X \smallskip X \hrule width4in X \hbox to 4in{\vrule height3in X \hfill X \vbox to 3in{\vfill\hbox{Device coordinates}\vfill}% X \hfill X \vrule height3in}% X \hrule width4in X \smallskip X \hbox to 4in{(0, 199)\hfill (319, 199)}% X}} X\bigskip X X\manhead Normalized device coordinates\par X X In normalized device coordinates, the origin is still the X upper left corner of the screen, but the point (1.0, 1.0) X is fixed at the lower right corner. This allows one to specify X coordinates without knowing the physical size of the screen. X Normalized device coordinates are always expressed as floats. X X\vskip\baselineskip X\centerline{\vbox{% X \hbox to 4in{(0.0, 0.0)\hfill (1.0, 0.0)}% X \smallskip X \hrule width4in X \hbox to 4in{\vrule height3in X \hfill X \vbox to 3in{\vfill\hbox{Normalized device coordinates}\vfill}% X \hfill X \vrule height3in}% X \hrule width4in X \smallskip X \hbox to 4in{(0.0, 1.0)\hfill (1.0, 1.0)}% X}} X\bigskip X X\manhead World coordinates\par X X In world coordinates you can set up a coordinate system X with an arbitrary offset and scale. For example, if you X want to have the x coordinates range from $-100$ to $+100$ X and the y coordinates range from $-50$ to $+50$, you would X call the \itwd setworld function as follows: X\mancodebeg X x1 = -100.0; /* lower left corner */ X y1 = -50.0; X x2 = 100.0; /* upper right corner */ X y2 = 50.0; X setworld(&x1, &y1, &x2, &y2); X\mancodeend X This sequence results in the following situation: X X\vskip\baselineskip X\centerline{\vbox{% X \hbox to 4in{($-$100.0, 50.0)\hfill (100.0, 50.0)}% X \smallskip X \hrule width4in X \hbox to 4in{\vrule height3in X \hfill X \vbox to 3in{\vfill\hbox{World coordinates}\vfill}% X \hfill X \vrule height3in}% X \hrule width4in X \smallskip X \hbox to 4in{($-$100.0, $-$50.0)\hfill (100.0, $-$50.0)}% X}} X\bigskip X X\manhead Coordinate transformations\par X X The following routines are available for converting points X from one coordinate system to another: X{\obeylines X mapdton --- convert device to normalized device coordinates X mapdtow --- convert device to world coordinates X mapntod --- convert normalized device to device coordinates X mapntow --- convert normalized device to world coordinates X mapwtod --- convert world to device coordinates X mapwton --- convert world to normalized device coordinates X} X X\manhead Viewports\par X X Viewports allow one to draw only on a portion of the screen. X For example, if we wanted the same coordinate system as X we had in the last example but we wanted to use only the X upper left corner of the screen, we could use: X\mancodebeg X x1 = 0.0; /* upper left corner of viewport in NDC */ X y1 = 0.0; X x2 = 0.5; /* lower right corner of viewport in NDC */ X y2 = 0.5; X c = -1; /* no border or clearing */ X setviewport(&x1, &y1, &x2, &y2, &c, &c); X X x1 = -100.0; /* lower left corner */ X y1 = -50.0; X x2 = 100.0; /* upper right corner */ X y2 = 50.0; X setworld(&x1, &y1, &x2, &y2); X\mancodeend X This results in the following: X X\vskip\baselineskip X\centerline{\vbox{% X \hbox to 4in{($-$100.0, 50.0)\hfill \hbox to 2in{(100.0, 50.0)\hfill}}% X \smallskip X \hrule width 4in X \hbox to 4in{% X \vrule height 3in X \vbox to 3in{% X \hbox to 2in{% X \hfill X \vbox to 1.5in{% X \vfill X \hbox{\hfill Viewport\hfill}% X \vfill X }% X \hfill X \vrule height 1.5in X }% X \hrule width 2in X \smallskip X \hbox to 2in{($-$100.0, $-$50.0)\hfill}% X \vfill X }% X \vbox to 3in{% X \vskip 1.5in X \smallskip X \hbox{(100.0, $-$50.0)\hfill}% X \vfill X }% X \hfill X \vrule height 3in X }% X \hrule width 4in X}} X\bigskip X X Note that the viewport corners are specified using normalized X device coordinates. X\mansee X mapdton(2), X mapdtow(2), mapntod(2), mapntow(2), mapwtod(2), X mapwton(2), \hint setworld(2), setviewport(2). X\manpend X X\manpage halo_init(2) X X\manname X halo_init --- initialize the halo routines X\mansyn X void halo_init() X\mandscr X The \itwd halo_init function initializes the halo routines, X resets the viewport to the entire screen, and resets world X coordinates to device coordinates (i.e., x coordinates X range from 0 to the x size of the device, similarly for X y coordinates). It also moves the graphics cursor X to~(0, 0) and sets the current drawing color to~0. X This function must be called \itwd after X every call to \itwd g_open and \itwd before any X other halo routines are used. X\mansee X g_open(1). X\manpend X X\manpage lnabs(2) X X\manname X lnabs --- draw a line to a specified point X\mansyn X void lnabs(x, y) X X float *x, *y; X\mandscr X The \itwd lnabs function draws a line from the current graphics X cursor position to the point~\itpnt (*x, *y) in world coordinates and X the graphics cursor is set to~\itpnt (*x, *y). The line is X drawn in the current drawing buffer with the current drawing X color. If xor mode is on the line is logically xor'ed with X the existing data in the buffer. X\mansee X g_line(1), lnrel(2). X\manpend X X\manpage lnrel(2) X X\manname X lnrel --- draw a line relative to the current graphics cursor position X\mansyn X void lnrel(dx, dy) X X float *dx, *dy; X\mandscr X The \itwd lnrel function draws a line from the current graphics X cursor to the point \break \itpnt ({cur_x + *dx}, {cur_y + *dy}) in X world coordinates, where \itpnt (cur_x, cur_y) is the current X position of the graphic cursor. After the line is drawn, X the graphics cursor is moved to \itpnt ({cur_x + *dx}, X {cur_y + *dy}). The line is X drawn in the current drawing buffer with the current drawing X color. If xor mode is on the line is logically xor'ed with X the existing data in the buffer. X\mansee X g_line(1), lnabs(2). X\manpend X X\manpage mapdton(2) X X\manname X mapdton --- map device to normalized device coordinates X\mansyn X void mapdton(dx, dy, nx, ny) X X int *dx, *dy; X float *nx, *ny; X\mandscr X The \itwd mapdton function converts the device coordinates X \itpnt (*dx, *dy) to the corresponding normalized device X coordinates \itpnt (*nx, *ny). X\mansee X coordinates(2), X mapdtow(2), mapntod(2), mapntow(2), mapwtod(2), X mapwton(2), setworld(2), setviewport(2). X\manpend X X\manpage mapdtow(2) X X\manname X mapdtow --- map device to world coordinates X\mansyn X void mapdtow(dx, dy, wx, wy) X X int *dx, *dy; X float *wx, *wy; X\mandscr X The \itwd mapdtow function converts the device coordinates X \itpnt (*dx, *dy) to the corresponding world X coordinates \itpnt (*wx, *wy). X\mansee X coordinates(2), X mapdton(2), mapntod(2), mapntow(2), mapwtod(2), X mapwton(2), setworld(2), setviewport(2). X\manpend X X\manpage mapntod(2) X X\manname X mapntod --- map normalized device to device coordinates X\mansyn X void mapntod(nx, ny, dx, dy) X X float *nx, *ny; X int *dx, *dy; X\mandscr X The \itwd mapntod function converts the normalized device coordinates X \itpnt (*nx, *ny) to the corresponding device X coordinates \itpnt (*dx, *dy). X\mansee X coordinates(2), X mapdton(2), mapdtow(2), mapntow(2), mapwtod(2), X mapwton(2), setworld(2), setviewport(2). X\manpend X X\manpage mapntow(2) X X\manname X mapntow --- map normalized device to world coordinates X\mansyn X void mapntow(nx, ny, wx, wy) X X float *nx, *ny; X float *wx, *wy; X\mandscr X The \itwd mapntow function converts the normalized device coordinates X \itpnt (*nx, *ny) to the corresponding world X coordinates \itpnt (*wx, *wy). X\mansee X coordinates(2), X mapdton(2), mapdtow(2), mapntod(2), mapwtod(2), X mapwton(2), setworld(2), setviewport(2). X\manpend X X\manpage mapwtod(2) X X\manname X mapwtod --- map world to device coordinates X\mansyn X void mapwtod(wx, wy, dx, dy) X X float *wx, *wy; X int *dx, *dy; X\mandscr X The \itwd mapwtod function converts the world coordinates X \itpnt (*wx, *wy) to the corresponding device X coordinates \itpnt (*dx, *dy). X\mansee X coordinates(2), X mapdton(2), mapdtow(2), mapntod(2), mapntow(2), X mapwton(2), setworld(2), setviewport(2). X\manpend X X\manpage mapwton(2) X X\manname X mapwton --- map world to normalized device coordinates X\mansyn X void mapwton(wx, wy, nx, ny) X X float *wx, *wy; X float *nx, *ny; X\mandscr X The \itwd mapwton function converts the world coordinates X \itpnt (*wx, *wy) to the corresponding normalized device X coordinates \itpnt (*nx, *ny). X\mansee X coordinates(2), X mapdton(2), mapdtow(2), mapntod(2), mapntow(2), mapwtod(2), X setworld(2), setviewport(2). X\manpend X X\manpage movabs(2) X X\manname X movabs --- move the graphics cursor to a specified point X\mansyn X void movabs(x, y) X X float *x, *y; X\mandscr X The \itwd movabs function moves the graphics cursor to the X position \itpnt (*x, *y) in world coordinates. X\mansee X movrel(2). X\manpend X X\manpage movrel(2) X X\manname X movrel --- move the graphics cursor relatively X\mansyn X void movrel(dx, dy) X X float *dx, *dy; X\mandscr X The \itwd movrel function moves the graphics cursor to the X position \itpntb ({cur_x + *dx}, {cur_y + *dy}) in world X coordinates where \itpnt (cur_x, cur_y) is the current position X of the graphics cursor. X\mansee X movabs(2). X\manpend X X\manpage setcolor(2) X X\manname X setcolor --- set the current drawing color X\mansyn X void setcolor(c) X X int *c; X\mandscr X The \itwd setcolor function sets the current drawing color X to~\itnc c . If~\itwd c is greater than the maximum color X value available on the graphics device in use, the X maximum value is used instead. X\manpend X X\manpage setviewport(2) X X\manname X setviewport --- set the active viewport X\mansyn X void setviewport(x1, y1, x2, y2, border, backgnd) X X float *x1, *y1, *x2, *y2; X int *border, *backgnd; X\mandscr X The \itwd setviewport function sets the viewport and the X clipping boundaries to the rectangular area defined by the X points \itpnt (x1, y1) and \itpnt (x2, y2) in normalized device X coordinates. If \itwd border is not $-$1, a border of X color~\itwd border will be drawn around the viewport (if there is X room for it), and if~\itwd backgnd is not $-$1, the interior X of the viewport will be cleared to color~\itnc backgnd . X\mansee X g_setclip(1), coordinates(2), setworld(2). X\manpend X X\manpage setworld(2) X X\manname X setworld --- set world coordinates X\mansyn X void setworld(x1, y1, x2, y2) X X float *x1, *y1, *x2, *y2; X\mandscr X The \itwd setworld function changes the current world coordinate X system. The world coordinates of the lower left corner of X the viewport become \itpnt (x1, y1), and the world X coordinates of the upper right corner of the viewport X become \itpnt (x2, y2). X\mansee X coordinates(2), setviewport(2). X\manpend X X\manpage setxor(2) X X\manname X setxor --- turn xor mode on or off X\mansyn X void setxor(flag) X X int *flag; X\mandscr X The \itwd setxor function turns xor mode on if \itwd~*flag X is nonzero, or off if \itwd~*flag is zero. When xor mode is X off, drawn objects are simply written over existing data in X the drawing buffer. But if xor mode is on, drawn objects X are logically xor'ed with the existing data. Thus if an object X is drawn twice in a row in exactly the same position with xor X mode on, it will be completely erased after the second drawing X and the image on the X screen restored to its state previous to the first drawing. X This makes xor mode useful for animation and other effects. X Functions which support xor mode are {\it g_box, g_circle, X g_ellipse, g_line, g_point, box, cir, lnabs,} and \itnc lnrel . X\manpend SHAR_EOF if test 14504 -ne "`wc -c < 'grafsec2.tex'`" then echo shar: error transmitting "'grafsec2.tex'" '(should have been 14504 characters)' fi fi # end of overwriting check echo shar: done with directory "'doc'" cd .. # End of shell archive exit 0