home *** CD-ROM | disk | FTP | other *** search
/ Graphics Programming Black Book (Special Edition) / BlackBook.bin / disk1 / source / chapterf / lf-3.c < prev    next >
C/C++ Source or Header  |  1997-06-18  |  2KB  |  60 lines

  1. /* Draws pixels from the list of horizontal lines passed in; drawing
  2.    takes place only for scan lines between ScanBandStart and
  3.    ScanBandEnd, inclusive; drawing goes to ScanLineBuffer, with
  4.    the scan line at ScanBandStart mapping to the first scan line in
  5.    ScanLineBuffer. Intended for use in unweighted antialiasing,
  6.    whereby a polygon is scanned out into a buffer at a multiple of the
  7.    screen's resolution, and then the scanned-out info in the buffer is
  8.    grouped into megapixels that are mapped to the closest
  9.    approximation the screen supports and drawn. 
  10.    Tested with Borland 4.02 in small model by Jim Mischel 12/16/94.
  11. */
  12. #include <string.h>
  13. #include <dos.h>
  14. #include "polygon.h"
  15.  
  16. extern unsigned char *ScanLineBuffer;  /* drawing goes here */
  17. extern int ScanBandStart, ScanBandEnd; /* limits of band to draw */
  18. extern int ScanBandWidth;  /* # of pixels across scan band */
  19.    
  20. void DrawBandedList(struct HLineList * HLineListPtr, int Color)
  21. {
  22.    struct HLine *HLinePtr;
  23.    int Length, Width, YStart = HLineListPtr->YStart;
  24.    unsigned char *BufferPtr;
  25.  
  26.    /* Done if fully off the bottom or top of the band */
  27.    if (YStart > ScanBandEnd) return;
  28.    Length = HLineListPtr->Length;
  29.    if ((YStart + Length) <= ScanBandStart) return;
  30.  
  31.    /* Point to the XStart/XEnd descriptor for the first (top)
  32.       horizontal line */
  33.    HLinePtr = HLineListPtr->HLinePtr;
  34.  
  35.    /* Confine drawing to the specified band */
  36.    if (YStart < ScanBandStart) {
  37.       /* Skip ahead to the start of the band */
  38.       Length -= ScanBandStart - YStart;
  39.       HLinePtr += ScanBandStart - YStart;
  40.       YStart = ScanBandStart;
  41.    }
  42.    if (Length > (ScanBandEnd - YStart + 1))
  43.       Length = ScanBandEnd - YStart + 1;
  44.  
  45.    /* Point to the start of the first scan line on which to draw */
  46.    BufferPtr = ScanLineBuffer + (YStart - ScanBandStart) *
  47.          ScanBandWidth;
  48.  
  49.    /* Draw each horizontal line within the band in turn, starting with
  50.       the top one and advancing one line each time */
  51.    while (Length-- > 0) {
  52.       /* Draw the whole horizontal line if it has a positive width */
  53.       if ((Width = HLinePtr->XEnd - HLinePtr->XStart + 1) > 0)
  54.          memset(BufferPtr + HLinePtr->XStart, Color, Width);
  55.       HLinePtr++;                /* point to next scan line X info */
  56.       BufferPtr += ScanBandWidth; /* point to next scan line start */
  57.    }
  58. }
  59.  
  60.