home *** CD-ROM | disk | FTP | other *** search
/ Cutting-Edge 3D Game Programming with C++ / CE3DC++.ISO / BOOK / CHAP03 / PALSHOW.CPP < prev    next >
C/C++ Source or Header  |  1996-04-15  |  2KB  |  85 lines

  1. //
  2. // File name: PalShow.CPP
  3. //
  4. // Description: A simple program designed to display the palette
  5. //
  6. //
  7. // Author: John De Goes
  8. //
  9. // Project: Cutting Edge 3D Game Programming
  10. //
  11.  
  12. // ------------------------------------------------------------
  13. // | Global headers:                                          |
  14. // ------------------------------------------------------------
  15.  
  16. #include <Dos.H>
  17. #include <Time.H>
  18. #include <Math.H>
  19. #include <Stdio.H>
  20. #include <Assert.H>
  21. #include <Conio.H>
  22. #include <Stdlib.H>
  23. #include <Iostream.H>
  24.  
  25. // ------------------------------------------------------------
  26. // | Local headers:                                           |
  27. // ------------------------------------------------------------
  28.  
  29. #include "32bit.HPP"
  30.  
  31. void SetPalReg ( long Index, char Red, char Green, char Blue )
  32.    {
  33.    // Sets the palette index Index to the specified RGB value:
  34.    REGS Regs;
  35.    Regs.w.ax  = 0x1010;
  36.    Regs.x.ebx = Index;
  37.    Regs.h.ch  = Red;
  38.    Regs.h.cl  = Green;
  39.    Regs.h.dh  = Blue;
  40.    int386 ( 0x10, &Regs, &Regs );
  41.    }
  42.  
  43. // Sets the palette to shades of gray
  44. void SetPalette ()
  45.    {
  46.    short unsigned int Color1, Color2, Color3;
  47.    for (short unsigned int Index = 0; Index < 256; Index++)
  48.        {
  49.        // Update three colors:
  50.        Color1 = ( unsigned short ) ( Index >> 2 );
  51.        Color2 = ( unsigned short ) ( Index >> 2 );
  52.        Color3 = ( unsigned short ) ( Index >> 2 );
  53.        SetPalReg ( Index, Color1, Color2, Color3 );
  54.        }
  55.    }
  56.    
  57. // Program entry:
  58. void main ()
  59.    {
  60.    // Create a pointer to video memory:
  61.    unsigned char *ScreenPtr = VideoAddress ();
  62.    long X, Y, Color, Cy, YIndex;
  63.    
  64.    // Set the video mode to 13h:
  65.    SetVideo ( 0x13 );
  66.    
  67.    // Set the palette:
  68.    SetPalette ();
  69.  
  70.    for ( Y = 0; Y < 200; Y++ )
  71.        {
  72.        YIndex = Y * 320;
  73.        Cy = long ( ( float ( Y ) / ( 200.0F / 16.0F ) ) ) * 16;
  74.        for ( X = 0; X < 320; X++ )
  75.            {
  76.            Color = Cy + long ( ( float ( X ) / ( 320.0F / 16.0F ) ) );
  77.            ScreenPtr [ YIndex + X ] = ( unsigned char ) Color;
  78.            }
  79.        }
  80.  
  81.    getch ();
  82.  
  83.    // Set the video mode to 03h:
  84.    SetVideo ( 0x03 );
  85.    }