The Fastgraph functions fg_point() and fg_putpixel() provide the most basic graphics operation -- setting one pixel to a specified color. Both functions have two integer parameters. The first specifies the pixel's x coordinate, and the second its y coordinate. They draw the pixel using the current color value, as specified in the most recent call to fg_setcolor() or fg_setcolorrgb(). The difference between these functions is that fg_point() does not draw the pixel if it lies outside the current clipping region, while fg_putpixel() always draws the pixel. There is also a world space pixel display function, fg_pointw(), that uses floating point parameters; it draws the pixel only if it falls within the clipping region.

We could use fg_putpixel() to write a much slower version of fg_fillpage():


int x, y;
for (y = 0; y <= fg_getmaxy(); y++)
   for (x = 0; x <= fg_getmaxx(); x++)


  x, y : integer;
  for y := 0 to fg_getmaxy do
    for x := 0 to fg_getmaxx do

Visual Basic:

Dim X As Long, Y As Long
For Y = 0 To fg_getmaxy()
   For X = 0 To fg_getmaxx()
      Call fg_putpixel(X, Y)
   Next X
Next Y

If we instead used fg_point() in the above code snippet, it would only display those pixels within the clipping region.

Another function is available for reading a pixel's color value. The fg_getpixel() function has two integer parameters that specify the (x,y) coordinates for the pixel of interest. There is no world space version of fg_getpixel(), but you can read a pixel's color value in world space by applying the fg_xscreen() and fg_yscreen() functions to the world space coordinates and passing the resulting values to fg_getpixel().

Sometimes you may want to display a pixel using an "exclusive or" operation (usually called XOR) to guarantee its visibility. The color of a pixel drawn in XOR mode will be c XOR p, where c is the current color and p is the color of the pixel already at that position. This means the pixel's new color will be different from the background as long as the current color is not zero. The fg_pointx() function displays a screen space pixel in XOR mode, while fg_pointxw() does the same thing in world space. Their respective parameters are the same as for fg_point() and fg_pointw().

<< Prev

Next >>

Fastgraph Home Page


copyright 2001 Ted Gruber Software, Inc.