home *** CD-ROM | disk | FTP | other *** search
/ The Devil's Doorknob BBS Capture (1996-2003) / devilsdoorknobbbscapture1996-2003.iso / Dloads / PROGRAMM / FGL112B.ZIP / USER06.DOC < prev    next >
Text File  |  1992-10-05  |  55KB  |  1,221 lines

  1.  
  2.  
  3. Chapter 6
  4.  
  5. Graphics Fundamentals
  6. 76  Fastgraph User's Guide
  7.  
  8. Overview
  9.  
  10.      This chapter describes Fastgraph's fundamental graphics routines,
  11. sometimes called graphics primitives.  These routines perform such functions
  12. as clearing the screen, drawing points, drawing solid and dashed lines,
  13. drawing closed shapes (polygons, circles, and ellipses), drawing rectangles
  14. (solid and dithered), and filling arbitrary regions.  Most of these routines
  15. have no effect in text video modes, but there are a few exceptions, and they
  16. will be noted in the descriptions of those routines.
  17.  
  18.  
  19. Clearing the Screen
  20.  
  21.      The Fastgraph routine fg_erase clears the entire screen in any video
  22. mode.  In text modes, fg_erase clears the screen by storing a space character
  23. (ASCII 32) with a gray foreground attribute in each character cell.  In
  24. graphics modes, fg_erase clears the screen by setting each pixel to zero.
  25. This of course causes each pixel to be displayed its background color.  The
  26. fg_erase routine has no arguments.
  27.  
  28.  
  29. Clipping
  30.  
  31.      The suppression of graphics outside a pre-defined area is called
  32. clipping.  Many of Fastgraph's graphics-oriented routines provide clipping,
  33. either automatically or through a special version of the routine.
  34.  
  35.      Fastgraph includes two routines, fg_setclip and fg_setclipw, to define a
  36. rectangular clipping region.  The fg_setclip routine defines the clipping
  37. region in screen space, while the fg_setclipw routine performs the same
  38. function in world space.  Each routine takes four arguments:  the minimum x,
  39. the maximum x, the minimum y, and the maximum y coordinate of the clipping
  40. region.  The arguments are integer quantities for fg_setclip and floating
  41. point quantities for fg_setclipw.  For example, the statement
  42.  
  43.                            fg_setclip(0,159,0,99);
  44.  
  45. would define the upper left quadrant of the screen as the clipping region in
  46. a 320 by 200 graphics mode.
  47.  
  48.      An implicit clipping region equal to the entire screen is defined as
  49. part of the fg_setmode routine's initializations.  Clipping is not supported
  50. for text modes.
  51.  
  52.  
  53. Points
  54.  
  55.      The Fastgraph routine fg_point provides the most basic graphics
  56. operation -- setting a pixel to a specified color.  The fg_point routine has
  57. two integer arguments.  The first specifies the pixel's x coordinate, and the
  58. second its y coordinate.  The pixel is drawn using the current color value,
  59. as specified in the most recent call to fg_setcolor.  There is also a world
  60. space version of this routine, fg_pointw, that uses floating point arguments.
  61.  
  62.      Another Fastgraph routine is available for reading a pixel's color
  63. value.  The fg_getpixel routine has two integer arguments that specify the
  64. (x,y) coordinates for the pixel of interest.  There is no world space version
  65.                                          Chapter 6:  Graphics Fundamentals  77
  66.  
  67. of the fg_getpixel routine, but you can obtain a pixel's color value in world
  68. space by applying the fg_xscreen and fg_yscreen functions to the world space
  69. coordinates and passing the resulting values to fg_getpixel.
  70.  
  71.      Example 6-1 uses the fg_point routine to draw 100 random points in
  72. random colors.  It also uses the fg_getpixel routine to insure no two points
  73. are adjacent.  The program establishes a graphics video mode with the
  74. fg_automode and fg_setmode routines.  Next, it determines the maximum color
  75. value for the selected video mode; note if we used virtual colors (color
  76. indices above the maximum color value), some of the colors would be the
  77. background color and would thus produce invisible points.  The main part of
  78. the program is a while loop that first generates a random pair of (x,y)
  79. screen coordinates.  It then calls the fg_getpixel routine to check the
  80. pixels at (x,y) and the eight adjacent positions.  If none of these pixels
  81. are set, the program generates a random color value and draws a point in that
  82. color.  After doing this 100 times, the program waits for a keystroke,
  83. restores the original video mode and screen attributes, and then returns to
  84. DOS.
  85.  
  86.                                  Example 6-1.
  87.  
  88.  
  89.   #include <fastgraf.h>
  90.   #include <stdlib.h>
  91.  
  92.   void main(void);
  93.   void main()
  94.   {
  95.      int area;
  96.      int color, old_color;
  97.      int left;
  98.      int max_color, max_x, max_y;
  99.      int new_mode, old_mode;
  100.      int x, y;
  101.  
  102.      old_mode = fg_getmode();
  103.      new_mode = fg_automode();
  104.      fg_setmode(new_mode);
  105.  
  106. 78  Fastgraph User's Guide
  107.  
  108.      if (new_mode == 4)
  109.         max_color = 3;
  110.  
  111.      else if (new_mode == 11 || new_mode == 17)
  112.         max_color = 1;
  113.  
  114.      else if (new_mode == 19)
  115.         max_color = 255;
  116.  
  117.      else
  118.         max_color = 15;
  119.  
  120.      left = 100;
  121.      max_x = fg_getmaxx() - 1;
  122.      max_y = fg_getmaxy() - 1;
  123.  
  124.      while (left > 0) {
  125.  
  126.         x = rand() % max_x + 1;
  127.         y = rand() % max_y + 1;
  128.  
  129.         area = fg_getpixel(x-1,y-1) + fg_getpixel(x,y-1) + fg_getpixel(x+1,y-1)
  130.              + fg_getpixel(x-1,y)   + fg_getpixel(x,y)   + fg_getpixel(x+1,y)
  131.              + fg_getpixel(x-1,y+1) + fg_getpixel(x,y+1) + fg_getpixel(x+1,y+1);
  132.  
  133.         if (area == 0) {
  134.            color = rand() % max_color + 1;
  135.            fg_setcolor(color);
  136.            fg_point(x,y);
  137.            left--;
  138.            }
  139.         }
  140.  
  141.      fg_waitkey();
  142.  
  143.      fg_setmode(old_mode);
  144.      fg_reset();
  145.   }
  146.  
  147.                                          Chapter 6:  Graphics Fundamentals  79
  148.  
  149. The Graphics Cursor
  150.  
  151.      Many of Fastgraph's graphics routines depend on the position of the
  152. graphics cursor as a reference point.  For example, Fastgraph includes
  153. routines to draw lines from the graphics cursor position to a specified
  154. position, and the image display routines discussed in Chapter 9 display or
  155. retrieve an image relative to the graphics cursor position.  The graphics
  156. cursor is not a cursor in the true sense; it is simply a pair of (x,y)
  157. coordinates with a special meaning.  The fg_setmode routine sets the graphics
  158. cursor position to the screen space coordinates (0,0), and the fg_initw
  159. routine sets it to the world space coordinates (0.0,0.0).
  160.  
  161.      Fastgraph includes four routines for changing the graphics cursor
  162. position.  The fg_move routine sets it to an absolute screen space position,
  163. while the fg_movew routine sets it to an absolute world space position.  The
  164. fg_moverel routine sets the graphics cursor position to a screen space
  165. position relative to its current position.  The fg_moverw routine does the
  166. same in world space.
  167.  
  168.      Each of these routines has two arguments that specify the (x,y)
  169. coordinates of the new position.  For the screen space routines, the
  170. arguments are integer quantities.  For the world space routines, the
  171. arguments are floating point quantities.
  172.  
  173.      You can obtain the screen space coordinates of the graphics cursor
  174. position with the fg_getxpos and fg_getypos routines.  These routines have no
  175. arguments and respectively return the x and y coordinates of the graphics
  176. cursor position as the function value.  To obtain the world space coordinates
  177. of the graphics cursor position, you can apply the fg_xworld and fg_yworld
  178. functions to the return values of fg_getxpos and fg_getypos.
  179.  
  180.  
  181. Solid Lines
  182.  
  183.      Fastgraph includes four routines for drawing solid lines.  All four
  184. routines draw lines in the current color value (as determined by the most
  185. recent call to fg_setcolor) and observe the clipping limits.  The fg_draw
  186. routine draws a line from the current graphics cursor position to an absolute
  187. screen space position, while the fg_draww routine draws a line to an absolute
  188. world space position.  The fg_drawrel routine draws a line from the current
  189. graphics cursor position to a screen space position relative to it.  The
  190. fg_drawrw routine does the same in world space.
  191. 80  Fastgraph User's Guide
  192.  
  193.      Each of these routines has two arguments that specify the (x,y)
  194. coordinates of the destination position.  For the screen space routines, the
  195. arguments are integer quantities.  For the world space routines, the
  196. arguments are floating point quantities.  In either case the destination
  197. position becomes the new graphics cursor position.  This makes it possible to
  198. draw connected lines without calling a graphics cursor movement routine
  199. between successive calls to a line drawing routine.
  200.  
  201.      Examples 6-2 and 6-3 each draw a pair of crossed lines that divide the
  202. screen into quadrants.  Example 6-2 does this using the fg_move and fg_draw
  203. routines, while example 6-3 uses the fg_moverel and fg_drawrel routines.
  204. Both examples draw the lines in bright white, the default for color 15 in all
  205. graphics video modes.
  206.  
  207.               Example 6-2.                          Example 6-3.
  208.  
  209.      #include <fastgraf.h>                 #include <fastgraf.h>
  210.      void main(void);                      void main(void);
  211.  
  212.      void main()                           void main()
  213.      {                                     {
  214.         int max_x, max_y;                     int max_x, max_y;
  215.         int mid_x, mid_y;                     int mid_x, mid_y;
  216.         int new_mode, old_mode;               int new_mode, old_mode;
  217.  
  218.         old_mode = fg_getmode();              old_mode = fg_getmode();
  219.         new_mode = fg_automode();             new_mode = fg_automode();
  220.         fg_setmode(new_mode);                 fg_setmode(new_mode);
  221.  
  222.         max_x = fg_getmaxx();                 max_x = fg_getmaxx();
  223.         max_y = fg_getmaxy();                 max_y = fg_getmaxy();
  224.         mid_x = max_x / 2;                    mid_x = max_x / 2;
  225.         mid_y = max_y / 2;                    mid_y = max_y / 2;
  226.  
  227.         fg_setcolor(15);                      fg_setcolor(15);
  228.         fg_move(mid_x,0);                     fg_move(mid_x,0);
  229.         fg_draw(mid_x,max_y);                 fg_drawrel(0,max_y);
  230.         fg_move(0,mid_y);                     fg_moverel(-mid_x,-mid_y);
  231.         fg_draw(max_x,mid_y);                 fg_drawrel(max_x,0);
  232.         fg_waitkey();                         fg_waitkey();
  233.  
  234.         fg_setmode(old_mode);                 fg_setmode(old_mode);
  235.         fg_reset();                           fg_reset();
  236.      }                                     }
  237.  
  238.  
  239.  
  240.      Examples 6-4 and 6-5 are variations of example 6-2.  Example 6-4 uses
  241. world space rather than screen space to draw the crossed lines.  Example 6-5
  242. is the same as example 6-2 except it defines a clipping area to restrict
  243. drawing to the upper left quadrant of the screen.  The clipping suppresses
  244. the right half of the horizontal line and the lower half of the vertical
  245. line.
  246.                                          Chapter 6:  Graphics Fundamentals  81
  247.  
  248.                Example 6-4.                                Example 6-5.
  249.  
  250.   #include <fastgraf.h>                          #include <fastgraf.h>
  251.   void main(void);                               void main(void);
  252.  
  253.   void main()                                    void main()
  254.   {                                              {
  255.      int new_mode, old_mode;                        int max_x, max_y;
  256.                                                     int mid_x, mid_y;
  257.      old_mode = fg_getmode();                       int new_mode, old_mode;
  258.      new_mode = fg_automode();
  259.      fg_setmode(new_mode);                          old_mode = fg_getmode();
  260.      fg_initw();                                    new_mode = fg_automode();
  261.      fg_setworld(-10.0,10.0,-10.0,10.0);            fg_setmode(new_mode);
  262.  
  263.      fg_setcolor(15);                               max_x = fg_getmaxx();
  264.      fg_movew(0.0,10.0);                            max_y = fg_getmaxy();
  265.      fg_draww(0.0,-10.0);                           mid_x = max_x / 2;
  266.      fg_movew(-10.0,0.0);                           mid_y = max_y / 2;
  267.      fg_draww(10.0,0.0);
  268.      fg_waitkey();                                  fg_setclip(0,mid_x,0,mid_y);
  269.  
  270.      fg_setmode(old_mode);                          fg_setcolor(15);
  271.      fg_reset();                                    fg_move(mid_x,0);
  272.   }                                                 fg_draw(mid_x,max_y);
  273.                                                     fg_move(0,mid_y);
  274.                                                     fg_draw(max_x,mid_y);
  275.                                                     fg_waitkey();
  276.  
  277.                                                     fg_setmode(old_mode);
  278.                                                     fg_reset();
  279.                                                  }
  280.  
  281. 82  Fastgraph User's Guide
  282.  
  283.  
  284. Dashed Lines
  285.  
  286.      Fastgraph includes four routines for drawing dashed lines.  All four
  287. routines draw lines in the current color value (as determined by the most
  288. recent call to fg_setcolor) and observe the clipping limits.  The fg_dash
  289. routine draws a dashed line from the current graphics cursor position to an
  290. absolute screen space position, while the fg_dashw routine draws a dashed
  291. line to an absolute world space position.  The fg_dashrel routine draws a
  292. dashed line from the current graphics cursor position to a screen space
  293. position relative to it.  The fg_dashrw routine does the same in world space.
  294.  
  295.      Each of these routines has three arguments.  The first two specify the
  296. (x,y) coordinates of the destination position.  For the screen space
  297. routines, these arguments are integer quantities.  For the world space
  298. routines, these arguments are floating point quantities.  The third argument
  299. is a 16-bit pattern that defines the appearance of the dashed line.  Bits
  300. that are set in the pattern produce the visible part of the line, while bits
  301. that are reset produce the invisible part.  This pattern is repeated as
  302. necessary to draw the entire line.  For example, the pattern value 3333 hex
  303. would produce a dashed line with the first two pixels off, the next two on,
  304. the next two off, and so forth.  Similarly, the pattern value FFFF hex would
  305. produce a solid line.
  306.  
  307.      The destination position passed to any of the dashed line routines
  308. becomes the new graphics cursor position.  This makes it possible to draw
  309. connected dashed lines without calling a graphics cursor movement routine
  310. between successive calls to a line drawing routine.
  311.  
  312.      Example 6-6 draws a pair of crossed dashed lines that divide the screen
  313. into quadrants.  It does this using the fg_move and fg_dash routines and
  314. draws the lines in bright white, the default for color 15 in all graphics
  315. video modes.  The dash pattern for each line is 3333 hex, which alternates
  316. two pixels off and on.
  317.  
  318.                                  Example 6-6.
  319.  
  320.                        #include <fastgraf.h>
  321.                        void main(void);
  322.  
  323.                        void main()
  324.                        {
  325.                           int max_x, max_y;
  326.                           int mid_x, mid_y;
  327.                           int new_mode, old_mode;
  328.  
  329.                           old_mode = fg_getmode();
  330.                           new_mode = fg_automode();
  331.                           fg_setmode(new_mode);
  332.  
  333.                           max_x = fg_getmaxx();
  334.                           max_y = fg_getmaxy();
  335.                           mid_x = max_x / 2;
  336.  
  337.                                          Chapter 6:  Graphics Fundamentals  83
  338.  
  339.                           mid_y = max_y / 2;
  340.  
  341.                           fg_setcolor(15);
  342.                           fg_move(mid_x,0);
  343.                           fg_dash(mid_x,max_y,0x3333);
  344.                           fg_move(0,mid_y);
  345.                           fg_dash(max_x,mid_y,0x3333);
  346.                           fg_waitkey();
  347.  
  348.                           fg_setmode(old_mode);
  349.                           fg_reset();
  350.                        }
  351.  
  352. Polygons, Circles, and Ellipses
  353.  
  354.      Fastgraph includes routines for drawing three types of closed shapes:
  355. polygons, circles, and ellipses.  Both screen space and world space versions
  356. of these routines are available.  All the routines for drawing closed shapes
  357. observe the clipping limits.
  358.  
  359.      The fg_polygon routine draws an unfilled polygon in screen space.
  360. Fg_polygon requires an array of integer x coordinates as its first argument,
  361. and an array of integer y coordinates as its second argument.  Each (x,y)
  362. coordinate pair from the two arrays is treated as a polygon vertex.  In other
  363. words, the x coordinate of the first polygon vertex is the first element of
  364. the x coordinate array, and the y coordinate of the first vertex is the first
  365. element of the y coordinate array.  Similarly, the second elements of each
  366. array define the second vertex, and so forth.  The third argument for
  367. fg_polygon is an integer quantity that specifies the number of elements in
  368. the two coordinate arrays.
  369.  
  370.      Another routine, fg_polygonw, draws an unfilled polygon in world space.
  371. The fg_polygonw routine is the same as the fg_polygon routine, except its x
  372. and y coordinate arrays must contain floating point values instead of
  373. integers.
  374.  
  375.      The drawing of the polygon begins at the graphics cursor position.  The
  376. routine then draws a solid line in the current color to the first vertex,
  377. then to the second vertex, and continues in this manner up to the last
  378. vertex.  If necessary, fg_polygon and fg_polygonw draw a line connecting the
  379. last vertex and the original graphics cursor position.  This last operation
  380. closes the polygon and effectively leaves the graphics cursor position
  381. unchanged.
  382.  
  383.      Example 6-7 illustrates the use of the fg_polygon routine in the EGA
  384. monochrome or enhanced modes (modes 15 and 16).  The program exits if neither
  385. of these video modes are available.
  386.  
  387.                                  Example 6-7.
  388.  
  389.              #include <fastgraf.h>
  390.              #include <stdio.h>
  391.              #include <stdlib.h>
  392.              void main(void);
  393.  
  394.              #define VERTICES 10
  395.  
  396. 84  Fastgraph User's Guide
  397.  
  398.  
  399.              int x[] = {200,300,400,400,300,240,160,160,200,200};
  400.              int y[] = {100, 80,100,220,320,320,240,200,160,160};
  401.  
  402.              void main()
  403.              {
  404.                 int old_mode;
  405.  
  406.                 old_mode = fg_getmode();
  407.  
  408.                 if (fg_testmode(16,1))
  409.                    fg_setmode(16);
  410.                 else if (fg_testmode(15,1))
  411.                    fg_setmode(15);
  412.                 else {
  413.                    printf("This program requires a 640 x 350 ");
  414.                    printf("EGA graphics mode.\n");
  415.                    exit(1);
  416.                    }
  417.  
  418.                 fg_setcolor(1);
  419.                 fg_polygon(x,y,VERTICES);
  420.                 fg_waitkey();
  421.  
  422.                 fg_setmode(old_mode);
  423.                 fg_reset();
  424.              }
  425.  
  426.  
  427.      The fg_circle routine draws an unfilled circle in screen space, centered
  428. at the graphics cursor position, using the current color.  The routine's only
  429. argument specifies the circle's radius in horizontal screen space units.
  430. Another routine, fg_circlew, draws an unfilled circle where the radius is
  431. measured in horizontal world space units.  Both routines leave the graphics
  432. cursor position unchanged.
  433.  
  434.      The fg_ellipse routine draws an unfilled ellipse in screen space,
  435. centered at the graphics cursor position, using the current color.  The
  436. routine requires two arguments that respectively specify the length of its
  437. horizontal and vertical semi-axes.  In other words, the first argument is the
  438. absolute distance from the center of the ellipse to its horizontal extremity,
  439. and the second argument is the absolute distance from the center of the
  440. ellipse to its vertical extremity.  Another routine, fg_ellipsew, draws an
  441. unfilled ellipse in world space.  Both routines leave the graphics cursor
  442. position unchanged.
  443.  
  444.      Example 6-8 illustrates the use of the fg_circlew and fg_ellipsew
  445. routines.  The program first uses the fg_automode routine to propose a
  446. graphics video mode and then uses the fg_setmode routine to select that video
  447. mode.  It then makes color 15 the current color, which by default is bright
  448. white in all color graphics modes and "on" in the monochrome graphics modes.
  449. Next, it establishes a 200-unit by 200-unit world space coordinate system.
  450. The program then uses fg_ellipsew to draw an ellipse and fg_circlew to draw a
  451. circle, both centered at the middle of the screen (which is the origin of our
  452. world space coordinate system).  The circle has a radius of 1/16 the width of
  453. the screen (12.5 horizontal world space units), and the ellipse is
  454. horizontally inscribed within the circle.
  455.                                          Chapter 6:  Graphics Fundamentals  85
  456.  
  457.      Example 6-9 illustrates the use of the fg_circle and fg_ellipse
  458. routines.  It is functionally identical to the program of example 6-8, but it
  459. uses screen space rather than world space coordinates to draw the circle and
  460. ellipse.  Note the arguments to the fg_circle and fg_ellipse routines are
  461. dependent on the maximum x and y coordinates of the selected video mode.  If
  462. we didn't compute these arguments in this manner, the actual size of the
  463. circle and ellipse would be proportional to the pixel resolution of the video
  464. mode.  No such dependency exists when using world space, but we pay a price
  465. for this feature in slightly slower execution speed.
  466.  
  467.                  Example 6-8.                               Example 6-9.
  468.  
  469.   #include <fastgraf.h>                         #include <fastgraf.h>
  470.   void main(void);                              void main(void);
  471.  
  472.   void main()                                   void main()
  473.   {                                             {
  474.      int old_mode;                                 int mid_x, mid_y;
  475.                                                    int old_mode;
  476.      old_mode = fg_getmode();                      int x,y;
  477.      fg_setmode(fg_automode());
  478.      fg_setcolor(15);                              old_mode = fg_getmode();
  479.                                                    fg_setmode(fg_automode());
  480.      fg_initw();                                   fg_setcolor(15);
  481.      fg_setworld(-100.0,100.0,-100.0,100.0);
  482.                                                    mid_x = fg_getmaxx() / 2;
  483.      fg_movew(0.0,0.0);                            mid_y = fg_getmaxy() / 2;
  484.      fg_ellipsew(12.5,12.5);                       x = mid_x / 8;
  485.      fg_circlew(12.5);                             y = mid_y / 8;
  486.      fg_waitkey();
  487.                                                    fg_move(mid_x,mid_y);
  488.      fg_setmode(old_mode);                         fg_ellipse(x,y);
  489.      fg_reset();                                   fg_circle(x);
  490.   }                                                fg_waitkey();
  491.  
  492.                                                    fg_setmode(old_mode);
  493.                                                    fg_reset();
  494.                                                  }
  495.  
  496. 86  Fastgraph User's Guide
  497.  
  498.  
  499. Solid Rectangles
  500.  
  501.      Fastgraph includes four routines for drawing solid rectangles, two for
  502. screen space and two for world space, with and without clipping.  None of
  503. these routines affect the graphics cursor position.
  504.  
  505.      The fg_rect routine draws a solid rectangle in screen space, without
  506. regard to the clipping limits, using the current color.  Fg_rect requires
  507. four integer arguments that respectively define the minimum x, maximum x,
  508. minimum y, and maximum y screen space coordinates of the rectangle.  The
  509. minimum coordinates must be less than or equal to the maximum coordinates, or
  510. else the results are unpredictable.  The fg_clprect routine is identical in
  511. all respects to the fg_rect routine, except it observes the clipping limits.
  512.  
  513.      The world space versions of the solid rectangle drawing routines are
  514. fg_rectw and fg_clprectw.  Like fg_rect and fg_clprect, they require four
  515. arguments that define the extremes of the rectangle, but the arguments are
  516. floating point world space coordinates.
  517.  
  518.      You also can use the fg_rect routine in text modes.  When used in a text
  519. mode, fg_rect expects its four arguments to be expressed in character space
  520. (that is, rows and columns) rather than screen space.  This means the four
  521. arguments respectively specify the minimum column, maximum column, minimum
  522. row, and maximum row of the rectangle.  Fastgraph constructs the rectangle by
  523. storing the solid block character (ASCII decimal value 219) in each character
  524. cell comprising the rectangle.  The rectangle is drawn using the current
  525. character attribute, but because the solid block character occupies the
  526. entire character cell, the background component of the attribute is
  527. essentially meaningless.
  528.  
  529.      Example 6-10 demonstrates the use of the fg_rect routine by drawing 200
  530. random-size rectangles in random colors.  The program first uses the
  531. fg_automode routine to propose a graphics video mode and then uses the
  532. fg_setmode routine to select that video mode.  Next, it determines the
  533. horizontal and vertical screen resolution for the selected video mode, using
  534. the fg_getmaxx and fg_getmaxy routines.  The main part of the program is a
  535. for loop that generates a random rectangle in each iteration.  Inside the
  536. loop, the C library function rand is used to generate the extremes of the
  537. rectangle.  If necessary, the program then exchanges the coordinates to make
  538. the minimum coordinates less than or equal to the maximum coordinates.
  539. Finally, it again uses rand to generate a random color number between 0 and
  540. 15, and then draws the rectangle in that color.  After drawing all 200
  541. rectangles, the program restores the original video mode and screen
  542. attributes before returning to DOS.
  543.                                          Chapter 6:  Graphics Fundamentals  87
  544.  
  545.                                 Example 6-10.
  546.  
  547.             #include <fastgraf.h>
  548.             void main(void);
  549.  
  550.             #define RECTANGLES 200
  551.             #define SWAP(a,b,temp) { temp = a; a = b; b = temp; }
  552.  
  553.             void main()
  554.             {
  555.                int i;
  556.                int minx, maxx, miny, maxy;
  557.                int old_mode;
  558.                int temp;
  559.                int xres, yres;
  560.  
  561.                old_mode = fg_getmode();
  562.                fg_setmode(fg_automode());
  563.  
  564.                xres = fg_getmaxx() + 1;
  565.                yres = fg_getmaxy() + 1;
  566.  
  567.                for (i = 0; i < RECTANGLES; i++) {
  568.                   minx = rand() % xres;
  569.                   maxx = rand() % xres;
  570.                   miny = rand() % yres;
  571.                   maxy = rand() % yres;
  572.                   if (minx > maxx)
  573.                      SWAP(minx,maxx,temp);
  574.                   if (miny > maxy)
  575.                      SWAP(miny,maxy,temp);
  576.                   fg_setcolor(rand()%16);
  577.                   fg_rect(minx,maxx,miny,maxy);
  578.                   }
  579.  
  580.                fg_setmode(old_mode);
  581.                fg_reset();
  582.             }
  583.  
  584.  
  585. Unfilled Rectangles
  586.  
  587.      Fastgraph includes a routine for drawing unfilled rectangles.  The
  588. fg_box routine draws an unfilled rectangle in screen space, with regard to
  589. the clipping limits, using the current color.  The arguments to fg_box are
  590. the same as those for fg_rect.  The depth of the rectangle's edges is one
  591. pixel by default, but you can change the depth by calling fg_boxdepth.  The
  592. fg_boxdepth routine expects two arguments.  The first argument is the width
  593. of the rectangle's left and right sides, while the second is the height of
  594. its top and bottom sides.  Once you call fg_boxdepth, fg_box draws all
  595. unfilled rectangles using the depth values specified in the most recent call
  596. to fg_boxdepth.  Unlike fg_rect, the fg_box routine has no effect in text
  597. video modes.
  598.  
  599.      Example 6-11 is the same as example 6-10, but it draws unfilled instead
  600. of solid rectangles.  The program uses fg_box to draw the each rectangle and
  601. fg_boxdepth to define the rectangle depth at three pixels in each direction.
  602. 88  Fastgraph User's Guide
  603.  
  604. Note that you don't need to call fg_boxdepth for each rectangle if you want
  605. all of them to have the same depth.
  606.  
  607.                                 Example 6-11.
  608.  
  609.             #include <fastgraf.h>
  610.             void main(void);
  611.  
  612.             #define RECTANGLES 200
  613.             #define SWAP(a,b,temp) { temp = a; a = b; b = temp; }
  614.  
  615.             void main()
  616.             {
  617.                int i;
  618.                int minx, maxx, miny, maxy;
  619.                int old_mode;
  620.                int temp;
  621.                int xres, yres;
  622.  
  623.                old_mode = fg_getmode();
  624.                fg_setmode(fg_automode());
  625.                fg_boxdepth(3,3);
  626.  
  627.                xres = fg_getmaxx() + 1;
  628.                yres = fg_getmaxy() + 1;
  629.  
  630.                for (i = 0; i < RECTANGLES; i++) {
  631.                   minx = rand() % xres;
  632.                   maxx = rand() % xres;
  633.                   miny = rand() % yres;
  634.                   maxy = rand() % yres;
  635.                   if (minx > maxx)
  636.                      SWAP(minx,maxx,temp);
  637.                   if (miny > maxy)
  638.                      SWAP(miny,maxy,temp);
  639.                   fg_setcolor(rand()%16);
  640.                   fg_box(minx,maxx,miny,maxy);
  641.                   }
  642.  
  643.                fg_setmode(old_mode);
  644.                fg_reset();
  645.             }
  646.  
  647.  
  648. Dithered Rectangles
  649.  
  650.      The process of alternating different color pixels across a region of the
  651. display area is called dithering.  This technique is especially useful in the
  652. graphics modes with few colors, such as CGA and Hercules modes, because you
  653. can simulate additional colors through effective uses of dithering.
  654. Fastgraph includes two routines for drawing dithered rectangles, one for
  655. screen space and one for world space.  Neither routine observes the clipping
  656. limits, nor do they affect the graphics cursor position.
  657.  
  658.      The fg_drect routine draws a dithered rectangle in screen space.  Like
  659. the fg_rect routine, fg_drect requires four integer arguments that
  660. respectively define the minimum x, maximum x, minimum y, and maximum y screen
  661.                                          Chapter 6:  Graphics Fundamentals  89
  662.  
  663. space coordinates of the rectangle.  The minimum coordinates must be less
  664. than or equal to the maximum coordinates, or else the results are
  665. unpredictable.  However, fg_drect also requires a fifth argument that defines
  666. the dithering matrix, which in turn determines the pixel pattern used to
  667. build the dithered rectangle.  The size and format of the dithering matrix
  668. are dependent on the video mode.
  669.  
  670.      The world space version of the dithered rectangle drawing routine is
  671. fg_drectw.  Like fg_drect, it requires four arguments that define the
  672. extremes of the rectangle, and a fifth argument that defines the dithering
  673. matrix.
  674.  
  675.      As mentioned earlier, the size and format of the dithering matrix are
  676. dependent on the video mode.  The dithering matrix is a four byte array in
  677. all video modes except the 256 color graphics modes (modes 19 through 23),
  678. where it is an eight byte array.  This array contains a pixel pattern that
  679. fg_drect or fg_drectw replicates across the rectangle's area.  The structure
  680. of the dithering matrix closely mimics the structure of video memory in each
  681. graphics mode.
  682.  
  683.      The remainder of this section will present some simple mode-specific
  684. examples to illustrate the structure of the dithering matrix in the different
  685. graphics modes.  Suppose we would like to produce a "checkerboard" of light
  686. blue and bright white pixels.  That is, in a given row of a rectangle,
  687. consecutive pixels will alternate between these two colors.  Additionally,
  688. the pattern for adjacent rows will be shifted such that there will always be
  689. a bright white pixel above and below a light blue pixel, and vice versa.
  690. Hence this pixel pattern would look something like
  691.  
  692.                                    B W B W
  693.                                    W B W B
  694.                                    B W B W
  695.                                    W B W B
  696.  
  697. where each B represents a light blue pixel, and each W represents a bright
  698. white pixel.  The following examples describe the dithering matrix that could
  699. be used to produce such a pixel pattern in each graphics mode.
  700.  
  701. CGA Four-Color Graphics Modes
  702.  
  703.      The CGA four-color graphics modes (modes 4 and 5) use a four-byte
  704. dithering matrix that Fastgraph treats as a four-row by one-column array.
  705. Since each pixel in these modes requires two bits of video memory, each byte
  706. of the dithering matrix holds four pixels.  Thus, the pixel representation of
  707. the dithering matrix would appear as shown below on the left; its translation
  708. to numeric values appears on the right.
  709.  
  710.                    [3]   B W B W       [3]   01 11 01 11
  711.  
  712.                    [2]   W B W B       [2]   11 01 11 01
  713.  
  714.                    [1]   B W B W       [1]   01 11 01 11
  715.  
  716.                    [0]   W B W B       [0]   11 01 11 01
  717.  
  718. 90  Fastgraph User's Guide
  719.  
  720. Because these modes do not offer a light blue color, we've used light cyan
  721. (color value 1 in palette 1) to approximate light blue.  The B pixels thus
  722. translate to color value 1, or 01 binary.  Bright white is available as color
  723. value 3 in palette 1, so the W pixels translate to color value 3, or 11
  724. binary.  The hexadecimal equivalent of the binary value 11011101 (for array
  725. elements [0] and [2]) is DD, and the hexadecimal equivalent of the binary
  726. value 01110111 (for array elements [1] and [3]) is 77.  As shown in example
  727. 6-12, these are precisely the values assigned to the elements of the
  728. dithering matrix.
  729.  
  730.      Example 6-12 uses mode 4 to display a 50-pixel by 50-pixel dithered
  731. rectangle in the upper left corner of the screen.  The dithering matrix
  732. represents the blue and white checkerboard pattern discussed in the preceding
  733. paragraph.
  734.  
  735.                                 Example 6-12.
  736.  
  737.                        #include <fastgraf.h>
  738.                        void main(void);
  739.  
  740.                        void main()
  741.                        {
  742.                           char matrix[4];
  743.                           int old_mode;
  744.  
  745.                           old_mode = fg_getmode();
  746.                           fg_setmode(4);
  747.  
  748.                           matrix[0] = matrix[2] = 0xDD;
  749.                           matrix[1] = matrix[3] = 0x77;
  750.                           fg_drect(0,49,0,49,matrix);
  751.                           fg_waitkey();
  752.  
  753.                           fg_setmode(old_mode);
  754.                           fg_reset();
  755.                        }
  756.  
  757.  
  758. CGA Two-Color Graphics Mode
  759.  
  760.      The CGA two-color graphics mode (mode 6) uses a four-byte dithering
  761. matrix that Fastgraph treats as a four-row by one-column array, as in the
  762. other four-color CGA modes.  However, each pixel in this mode only requires
  763. one bit of video memory, so each byte of the dithering matrix holds eight
  764. pixels.  Thus, the pixel representation of the dithering matrix would appear
  765. as shown below on the left; its translation to numeric values appears on the
  766. right.
  767.  
  768.              [3]   B W B W B W B W       [3]   0 1 0 1 0 1 0 1
  769.  
  770.              [2]   W B W B W B W B       [2]   1 0 1 0 1 0 1 0
  771.  
  772.              [1]   B W B W B W B W       [1]   0 1 0 1 0 1 0 1
  773.  
  774.              [0]   W B W B W B W B       [0]   1 0 1 0 1 0 1 0
  775.  
  776.                                          Chapter 6:  Graphics Fundamentals  91
  777.  
  778. Mode 6 obviously does not offer a light blue color, so we've used black
  779. (color value 0) in its place.  The B pixels thus translate to color value 0.
  780. Bright white is available as color value 1, so the W pixels translate to
  781. color value 1.  The hexadecimal equivalent of the binary value 10101010 (for
  782. array elements [0] and [2]) is AA, and the hexadecimal equivalent of the
  783. binary value 01010101 (for array elements [1] and [3]) is 55.  Thus, to make
  784. example 6-12 run in mode 6, we only need to change the fg_setmode argument
  785. from 4 to 6 and change the dithering matrix values as shown below.
  786.  
  787.                         matrix[0] = matrix[2] = 0xAA;
  788.                         matrix[1] = matrix[3] = 0x55;
  789.  
  790.  
  791. Tandy/PCjr 16-Color Graphics Mode
  792.  
  793.      The Tandy/PCjr 16-color graphics mode (mode 9) also uses a four-byte
  794. dithering matrix that Fastgraph treats as a four-row by one-column array.
  795. Each pixel in this mode requires four bits of video memory, so each byte of
  796. the dithering matrix only holds two pixels.  Thus, the pixel representation
  797. of the dithering matrix would appear as shown below on the left; its
  798. translation to numeric values appears on the right.
  799.  
  800.                       [3]   B W       [3]   1001 1111
  801.  
  802.                       [2]   W B       [2]   1111 1001
  803.  
  804.                       [1]   B W       [1]   1001 1111
  805.  
  806.                       [0]   W B       [0]   1111 1001
  807.  
  808. The B pixels translate to color value 9 (light blue), or 1001 binary, and the
  809. W pixels translate to color value 15 (bright white), or 1111 binary.  The
  810. hexadecimal equivalent of the binary value 11111001 (for array elements [0]
  811. and [2]) is F9, and the hexadecimal equivalent of the binary value 10011111
  812. (for array elements [1] and [3]) is 9F.  Thus, to make example 6-12 run in
  813. mode 9, we only need to change the fg_setmode argument from 4 to 9 and change
  814. the dithering matrix values as shown below.
  815.  
  816.                         matrix[0] = matrix[2] = 0xF9;
  817.                         matrix[1] = matrix[3] = 0x9F;
  818.  
  819.  
  820. Hercules Graphics Mode
  821.  
  822.      The size and format of the dithering matrix in the Hercules graphics
  823. mode (mode 11) are the same as in the CGA two-color mode (mode 6).  Please
  824. refer to page 90 for a discussion of mode 6 dithering.
  825.  
  826. Hercules Low-Resolution Graphics Mode
  827.  
  828.      The size and format of the dithering matrix in the Hercules low-
  829. resolution graphics mode (mode 12) are the same as in the CGA four-color
  830. modes (modes 4 and 5).  As far as our checkerboard example goes, we'll use
  831. black (color value 0) in place of light blue, and bold (color value 3)
  832. 92  Fastgraph User's Guide
  833.  
  834. instead of bright white.  Thus, the B pixels translate to 00 binary, while
  835. the W pixels translate to 11 binary.  The hexadecimal equivalent of the
  836. binary value 11001100 (for array elements [0] and [2]) is CC, and the
  837. hexadecimal equivalent of the binary value 00110011 (for array elements [1]
  838. and [3]) is 33.  Thus, to make example 6-12 run in mode 12, we only need to
  839. change the fg_setmode argument from 4 to 12 and change the dithering matrix
  840. values as shown below.
  841.  
  842.                         matrix[0] = matrix[2] = 0xCC;
  843.                         matrix[1] = matrix[3] = 0x33;
  844.  
  845.  
  846. EGA and VGA Graphics Modes
  847.  
  848.      The native EGA and VGA graphics modes (modes 13 through 18) use a four-
  849. byte dithering matrix that Fastgraph treats as a four-row by one-column
  850. array.  Unlike the other graphics modes, which allow you to store pixels of
  851. several colors in the dithering matrix, the EGA and VGA modes treat the
  852. dithering matrix as a bit map for a specific color.  Since each color in the
  853. dither pattern must be stored in a separate bit map (that is, in a separate
  854. dithering matrix), you must call fg_drect once for each color.  Furthermore,
  855. you must use the fg_setcolor routine before each call to fg_drect to define
  856. the color used with the dithering matrix.
  857.  
  858.      In all EGA and VGA graphics modes, each byte of the dithering matrix is
  859. a bit map that represents eight pixels.  Using our familiar checkerboard
  860. example, the pixel representation of the dithering matrix would appear as
  861. shown below.
  862.  
  863.                            [3]   B W B W B W B W
  864.  
  865.                            [2]   W B W B W B W B
  866.  
  867.                            [1]   B W B W B W B W
  868.  
  869.                            [0]   W B W B W B W B
  870.  
  871. Translating this pattern to numeric values is simple.  Just construct one
  872. dithering matrix for each color in the pattern (there are two colors in this
  873. example), where pixels of the current color translate to 1, and other pixels
  874. translate to 0.  Following our example, the translation for the B pixels
  875. appears below on the left, while the translation for the W pixels appears on
  876. the right.
  877.  
  878.              [3]   1 0 1 0 1 0 1 0       [3]   0 1 0 1 0 1 0 1
  879.  
  880.              [2]   0 1 0 1 0 1 0 1       [2]   1 0 1 0 1 0 1 0
  881.  
  882.              [1]   1 0 1 0 1 0 1 0       [1]   0 1 0 1 0 1 0 1
  883.  
  884.              [0]   0 1 0 1 0 1 0 1       [0]   1 0 1 0 1 0 1 0
  885.  
  886.                                          Chapter 6:  Graphics Fundamentals  93
  887.  
  888. The hexadecimal equivalent of the binary value 01010101 is 55, and the
  889. hexadecimal equivalent of the binary value 10101010 is AA.  As shown in
  890. example 6-13, these are precisely the values assigned to the elements of the
  891. dithering matrices.
  892.  
  893.      Example 6-13 uses mode 13 to display our light blue and bright white
  894. checkerboard pattern.  Note you must call fg_drect twice -- once for the
  895. light blue pixels (color value 9), and again for the bright white pixels
  896. (color value 15).  Note also how fg_setcolor is used before each call to
  897. fg_drect to define the color of the pixels fg_drect will display.
  898.  
  899.                                 Example 6-13.
  900.  
  901.                        #include <fastgraf.h>
  902.                        void main(void);
  903.  
  904.                        void main()
  905.                        {
  906.                           char matrix[4];
  907.                           int old_mode;
  908.  
  909.                           old_mode = fg_getmode();
  910.                           fg_setmode(13);
  911.  
  912.                           matrix[0] = matrix[2] = 0x55;
  913.                           matrix[1] = matrix[3] = 0xAA;
  914.                           fg_setcolor(9);
  915.                           fg_drect(0,49,0,49,matrix);
  916.  
  917.                           matrix[0] = matrix[2] = 0xAA;
  918.                           matrix[1] = matrix[3] = 0x55;
  919.                           fg_setcolor(15);
  920.                           fg_drect(0,49,0,49,matrix);
  921.                           fg_waitkey();
  922.  
  923.                           fg_setmode(old_mode);
  924.                           fg_reset();
  925.                        }
  926.  
  927. MCGA and VGA 256-Color Graphics Modes
  928.  
  929.      The MCGA and VGA 256-color graphics modes (modes 19 through 23) use an
  930. eight-byte dithering matrix that Fastgraph treats as a four-row by two-column
  931. array.  Each pixel in these modes requires eight bits of video memory, so
  932. each byte of the dithering matrix only holds a single pixel.  We therefore
  933. need the two column dithering matrix to produce any type of dither pattern.
  934. The pixel representation of the dithering matrix would appear as shown below
  935. on the left; its translation to numeric values appears on the right.
  936.  
  937.                     [6]   B   W   [7]     [6]    9   15   [7]
  938.  
  939.                     [4]   W   B   [5]     [4]   15    9   [5]
  940.  
  941.                     [2]   B   W   [3]     [2]    9   15   [3]
  942.  
  943.                     [0]   W   B   [1]     [0]   15    9   [1]
  944. 94  Fastgraph User's Guide
  945.  
  946.  
  947. The B pixels translate to color value 9 (light blue), and the W pixels
  948. translate to color value 15 (bright white).  Example 6-14 uses mode 19 to
  949. draw our light blue and bright white checkerboard pattern.
  950.  
  951.                                 Example 6-14.
  952.  
  953.             #include <fastgraf.h>
  954.             void main(void);
  955.  
  956.             void main()
  957.             {
  958.                char matrix[8];
  959.                int old_mode;
  960.  
  961.                old_mode = fg_getmode();
  962.                fg_setmode(19);
  963.  
  964.                matrix[0] = matrix[3] = matrix[4] = matrix[7] = 15;
  965.                matrix[1] = matrix[2] = matrix[5] = matrix[6] =  9;
  966.                fg_drect(0,49,0,49,matrix);
  967.                fg_waitkey();
  968.  
  969.                fg_setmode(old_mode);
  970.                fg_reset();
  971.             }
  972.  
  973.  
  974. Closing Remarks
  975.  
  976.      There are two other important items pertaining to the fg_drect and
  977. fg_drectw routines.  These items apply regardless of which graphics video
  978. mode is being used.
  979.  
  980.      First, the dithering matrix may not contain virtual color values.  That
  981. is, the pixel color values stored in the dithering matrix must be between 0
  982. and the maximum color value for the current video mode.  If any color value
  983. is redefined using the fg_defcolor routine, Fastgraph always ignores the
  984. redefinition and instead uses the actual color value.  Note this does not
  985. apply to palette registers or video DAC registers, because in these cases we
  986. are redefining the color associated with a color value and not the color
  987. value itself.
  988.  
  989.      Second, Fastgraph aligns the dithering matrix to specific pixel rows.
  990. Fastgraph draws the dithered rectangle starting with the pixel row specified
  991. by the rectangle's lower limit (the maximum y coordinate for fg_drect, or the
  992. minimum y coordinate for fg_drectw) and proceeds upward until reaching the
  993. rectangle's upper limit.  In all cases the dithering matrix used by fg_drect
  994. and fg_drectw contains four rows.  If we let r represent the pixel row
  995. corresponding to the rectangle's lower limit, then the first row used in the
  996. dithering matrix is r modulo 4 (assuming the dithering matrix rows are
  997. numbered 0 to 3).  This alignment enables you to use the same dithering
  998. matrix in multiple calls to fg_drect and fg_drectw for building an object of
  999. adjacent dithered rectangles (for example, an L-shaped area) and still have
  1000. the dither pattern match where the rectangles intersect.
  1001.                                          Chapter 6:  Graphics Fundamentals  95
  1002.  
  1003. Region Fill
  1004.  
  1005.      Fastgraph includes routines for filling arbitrary regions.  The fg_paint
  1006. routine fills a region with the current color value by specifying a screen
  1007. space point in the region's interior.  The fg_paintw routine also fills a
  1008. region, but it requires the interior point to be expressed in world space.
  1009. Neither routine changes the graphics cursor position.
  1010.  
  1011.      Each of these routines has two arguments that specify the (x,y)
  1012. coordinates of the interior point.  For the fg_paint routine, the arguments
  1013. are integer quantities.  For the fg_paintw routine, they are floating point
  1014. quantities.
  1015.  
  1016.      The region being filled must be a closed polygon whose boundary color is
  1017. different from that of the specified interior point.  The region may contain
  1018. holes (interior areas that will not be filled).  Fastgraph fills the region
  1019. by changing every interior pixel whose color is the same as the specified
  1020. interior point, to the current color.  If the interior point is already the
  1021. current color, the region fill routines do nothing.  It is important to note
  1022. the screen edges are not considered polygon boundaries, and filling an open
  1023. polygon will cause the fg_paint and fg_paintw routines to behave
  1024. unpredictably.
  1025.  
  1026.      Example 6-15 illustrates a simple use of the fg_paint routine in a 320
  1027. by 200 graphics mode.  The program uses fg_bestmode to select an available
  1028. video mode (if no 320 by 200 graphics mode is available, the program exits).
  1029. After establishing the selected video mode, the program uses the fg_move and
  1030. fg_drawrel routines to draw a hollow rectangle in color 10 and a hollow
  1031. diamond in color 9.  The diamond is drawn in the middle of the rectangle,
  1032. thus making it a hole with respect to the rectangle.  The program leaves
  1033. these shapes on the screen until a key is pressed.  At that time, it calls
  1034. the fg_paint routine to fill that part of the rectangle outside the diamond
  1035. with color 10.  After waiting for another keystroke, the program again uses
  1036. fg_paint to fill the interior of the diamond with color 15.  Finally, the
  1037. program waits for another keystroke, restores the original video mode and
  1038. screen attributes, and returns to DOS.
  1039.  
  1040.                                 Example 6-15.
  1041.  
  1042.              #include <fastgraf.h>
  1043.              #include <stdio.h>
  1044.              #include <stdlib.h>
  1045.              void main(void);
  1046.  
  1047.              void main()
  1048.              {
  1049.                 int old_mode, new_mode;
  1050.  
  1051.                 new_mode = fg_bestmode(320,200,1);
  1052.                 if (new_mode < 0) {
  1053.                    printf("This program requires a 320 x 200 ");
  1054.                    printf("graphics mode.\n");
  1055.                    exit(1);
  1056.                    }
  1057.  
  1058.                 old_mode = fg_getmode();
  1059.  
  1060. 96  Fastgraph User's Guide
  1061.  
  1062.                 fg_setmode(new_mode);
  1063.  
  1064.                 fg_setcolor(10);
  1065.                 fg_move(100,50);
  1066.                 fg_drawrel(120,0);
  1067.                 fg_drawrel(0,100);
  1068.                 fg_drawrel(-120,0);
  1069.                 fg_drawrel(0,-100);
  1070.  
  1071.                 fg_setcolor(9);
  1072.                 fg_move(160,80);
  1073.                 fg_drawrel(30,20);
  1074.                 fg_drawrel(-30,20);
  1075.                 fg_drawrel(-30,-20);
  1076.                 fg_drawrel(30,-20);
  1077.                 fg_waitkey();
  1078.  
  1079.                 fg_setcolor(10);
  1080.                 fg_paint(160,70);
  1081.                 fg_waitkey();
  1082.  
  1083.                 fg_setcolor(15);
  1084.                 fg_paint(160,100);
  1085.                 fg_waitkey();
  1086.  
  1087.                 fg_setmode(old_mode);
  1088.                 fg_reset();
  1089.              }
  1090.  
  1091.  
  1092.  
  1093. Summary of Fundamental Graphics Routines
  1094.  
  1095.      This section summarizes the functional descriptions of the Fastgraph
  1096. routines presented in this chapter.  More detailed information about these
  1097. routines, including their arguments and return values, may be found in the
  1098. Fastgraph Reference Manual.
  1099.  
  1100.      FG_BOX draws an unfilled rectangle in screen space, with respect to the
  1101. clipping region.  The width of the rectangle's edges is one pixel unless
  1102. changed with the fg_boxdepth routine.
  1103.  
  1104.      FG_BOXDEPTH defines the depth of rectangles drawn with the fg_box
  1105. routine.  The fg_setmode routine initializes the box depth to one pixel.
  1106.  
  1107.      FG_CIRCLE draws an unfilled circle in screen space.  The circle is
  1108. centered at the graphics cursor position.
  1109.  
  1110.      FG_CIRCLEW draws an unfilled circle in world space.  The circle is
  1111. centered at the graphics cursor position.
  1112.  
  1113.      FG_CLPRECT draws a solid (filled) rectangle in screen space, with
  1114. respect to the clipping region.
  1115.  
  1116.      FG_CLPRECTW draws a solid (filled) rectangle in world space, with
  1117. respect to the clipping region.
  1118.                                          Chapter 6:  Graphics Fundamentals  97
  1119.  
  1120.      FG_DASH draws a dashed line from the graphics cursor position to an
  1121. absolute screen space position.  It also makes the destination position the
  1122. new graphics cursor position.
  1123.  
  1124.      FG_DASHREL draws a dashed line from the graphics cursor position to a
  1125. screen space position relative to it.  It also makes the destination position
  1126. the new graphics cursor position.
  1127.  
  1128.      FG_DASHRW draws a dashed line from the graphics cursor position to a
  1129. world space position relative to it.  It also makes the destination position
  1130. the new graphics cursor position.
  1131.  
  1132.      FG_DASHW draws a dashed line from the graphics cursor position to an
  1133. absolute world space position.  It also makes the destination position the
  1134. new graphics cursor position.
  1135.  
  1136.      FG_DRAW draws a solid line from the graphics cursor position to an
  1137. absolute screen space position.  It also makes the destination position the
  1138. new graphics cursor position.
  1139.  
  1140.      FG_DRAWREL draws a solid line from the graphics cursor position to a
  1141. screen space position relative to it.  It also makes the destination position
  1142. the new graphics cursor position.
  1143.  
  1144.      FG_DRAWRW draws a solid line from the graphics cursor position to a
  1145. world space position relative to it.  It also makes the destination position
  1146. the new graphics cursor position.
  1147.  
  1148.      FG_DRAWW draws a solid line from the graphics cursor position to an
  1149. absolute world space position.  It also makes the destination position the
  1150. new graphics cursor position.
  1151.  
  1152.      FG_DRECT draws a dithered rectangle in screen space, without regard to
  1153. the clipping region.  The rectangle's dither pattern is defined through a
  1154. dithering matrix whose format is dependent on the video mode being used.
  1155.  
  1156.      FG_DRECTW draws a dithered rectangle in world space, without regard to
  1157. the clipping region.  The rectangle's dither pattern is defined through a
  1158. dithering matrix whose format is dependent on the video mode being used.
  1159.  
  1160.      FG_ELLIPSE draws an unfilled ellipse in screen space.  The ellipse is
  1161. centered at the graphics cursor position, and its size is determined by the
  1162. specified lengths of the semi-axes.
  1163.  
  1164.      FG_ELLIPSEW draws an unfilled ellipse in world space.  The ellipse is
  1165. centered at the graphics cursor position, and its size is determined by the
  1166. specified lengths of the semi-axes.
  1167.  
  1168.      FG_ERASE clears the screen in either text or graphics modes.
  1169.  
  1170.      FG_GETPIXEL returns the color value of a specified pixel.
  1171.  
  1172.      FG_GETXPOS returns the screen space x coordinate of the graphics cursor
  1173. position.
  1174.  
  1175.      FG_GETYPOS returns the screen space y coordinate of the graphics cursor
  1176. position.
  1177. 98  Fastgraph User's Guide
  1178.  
  1179.      FG_MOVE establishes the graphics cursor position at an absolute screen
  1180. space point.
  1181.  
  1182.      FG_MOVEREL establishes the graphics cursor position at a screen space
  1183. point relative to the current position.
  1184.  
  1185.      FG_MOVERW establishes the graphics cursor position at a world space
  1186. point relative to the current position.
  1187.  
  1188.      FG_MOVEW establishes the graphics cursor position at an absolute world
  1189. space point.
  1190.  
  1191.      FG_PAINT fills an arbitrary closed region with the current color value.
  1192. The region is defined by specifying a screen space point within its interior.
  1193.  
  1194.      FG_PAINTW fills an arbitrary closed region with the current color value.
  1195. The region is defined by specifying a world space point within its interior.
  1196.  
  1197.      FG_POINT draws a point (that is, displays a pixel) in screen space.
  1198.  
  1199.      FG_POINTW draws a point in world space.
  1200.  
  1201.      FG_POLYGON draws an unfilled polygon in screen space, using two
  1202. coordinate arrays to define the polygon vertices.  The drawing of the polygon
  1203. begins at the graphics cursor position, through the vertices defined by the
  1204. coordinate arrays, and finally back to the original cursor position if
  1205. necessary.
  1206.  
  1207.      FG_POLYGONW draws an unfilled polygon in world space.  It is the same as
  1208. the fg_polygon routine, except the coordinate arrays contain world space
  1209. values.
  1210.  
  1211.      FG_RECT draws a solid (filled) rectangle in screen space or character
  1212. space, without regard to the clipping region.
  1213.  
  1214.      FG_RECTW draws a solid (filled) rectangle in world space, without regard
  1215. to the clipping region.
  1216.  
  1217.      FG_SETCLIP defines the clipping region in screen space.  The clipping
  1218. region is a rectangular area outside of which graphics are suppressed.
  1219.  
  1220.      FG_SETCLIPW defines the clipping region in world space.
  1221.