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

  1. /* Draws all pixels in the horizontal line segment passed in, from
  2.    (LeftX,Y) to (RightX,Y), in the specified color in mode 13h, the
  3.    VGA's 320x200 256-color mode. Both LeftX and RightX are drawn. No
  4.    drawing will take place if LeftX > RightX.
  5.  
  6.    Link with L23-4.C and L23-1.C in small model.
  7.    Tested with Borland C++ 4.02 by Jim Mischel 12/16/94.
  8. */
  9.  
  10. #include <dos.h>
  11. #include "polygon.h"
  12.  
  13. #define SCREEN_WIDTH    320
  14. #define SCREEN_SEGMENT  0xA000
  15.  
  16. static void DrawPixel(int, int, int);
  17.  
  18. void DrawHorizontalLineSeg(Y, LeftX, RightX, Color) {
  19.    int X;
  20.  
  21.    /* Draw each pixel in the horizontal line segment, starting with
  22.       the leftmost one */
  23.    for (X = LeftX; X <= RightX; X++)
  24.       DrawPixel(X, Y, Color);
  25. }
  26.  
  27. /* Draws the pixel at (X, Y) in color Color in VGA mode 13h */
  28. static void DrawPixel(int X, int Y, int Color) {
  29.    unsigned char far *ScreenPtr;
  30.  
  31. #ifdef __TURBOC__
  32.    ScreenPtr = MK_FP(SCREEN_SEGMENT, Y * SCREEN_WIDTH + X);
  33. #else    /* MSC 5.0 */
  34.    FP_SEG(ScreenPtr) = SCREEN_SEGMENT;
  35.    FP_OFF(ScreenPtr) = Y * SCREEN_WIDTH + X;
  36. #endif
  37.    *ScreenPtr = (unsigned char) Color;
  38. }
  39.  
  40.