home *** CD-ROM | disk | FTP | other *** search
/ Black Art of 3D Game Programming / Black_Art_of_3D_Game_Programming.iso / source / msc / chap_3 / mode13.c < prev    next >
Text File  |  1994-10-05  |  3KB  |  124 lines

  1.  
  2. // MODE13.C - A demo of all the mode 13h functions for this chapter
  3.  
  4. // I N C L U D E S ///////////////////////////////////////////////////////////
  5.  
  6. #include <io.h>
  7. #include <conio.h>
  8. #include <stdio.h>
  9. #include <stdlib.h>
  10. #include <dos.h>
  11. #include <bios.h>
  12. #include <fcntl.h>
  13. #include <memory.h>
  14. #include <malloc.h>
  15. #include <math.h>
  16. #include <string.h>
  17.  
  18. #include "black3.h"   // the header file for this module
  19.  
  20. // M A I N ////////////////////////////////////////////////////////////////////
  21.  
  22. void main(int argc, char **argv)
  23. {
  24.  
  25. RGB_color color;  // used as temporary color variable
  26. int index;        // used for looping
  27.  
  28. RGB_palette save_palette;  // used to save the palette
  29.  
  30. printf("\nHit any key to switch to mode 13h");
  31. getch();
  32.  
  33. // set the graphics mode to mode 13h
  34.  
  35. Set_Graphics_Mode(GRAPHICS_MODE13);
  36.  
  37. // show some text
  38.  
  39. Print_String(0,0,15,"Hit a key to see text printing         ",0);
  40. getch();
  41.  
  42. // print a few hundred strings on the screen
  43.  
  44. for (index=0; index<1000; index++)
  45.     Print_String(rand()%(320-256),rand()%190,rand()%256,
  46.                  "This is a demo of text printing",1);
  47.  
  48. Print_String(0,0,15,"Hit a key to see screen filling        ",0);
  49. getch();
  50.  
  51. // fill the screen dark grey
  52.  
  53. Fill_Screen(8);
  54.  
  55. Print_String(0,0,15,"Hit a key to see pixel plotting        ",0);
  56. getch();
  57.  
  58. // plot 10000 random pixels
  59.  
  60. for (index=0; index<10000; index++)
  61.     Write_Pixel(rand()%320,rand()%200,12);
  62.  
  63. Print_String(0,0,15,"Hit a key to see lines                 ",0);
  64. getch();
  65.  
  66. // draw 1000 randomly positioned horizontal and vertical lines
  67.  
  68. for (index=0; index<1000; index++)
  69.     {
  70.     Line_H(rand()%320,rand()%320,rand()%200,rand()%256);
  71.     Line_V(rand()%200,rand()%200,rand()%320,rand()%256);
  72.     } // end for index
  73.  
  74. Print_String(0,0,15,"Hit a key to change color registers    ",0);
  75. getch();
  76.  
  77. // save the palette
  78.  
  79. Read_Palette(0,255,(RGB_palette_ptr)&save_palette);
  80.  
  81. // change the palette
  82.  
  83. for (index=0; index<256; index++)
  84.     {
  85.     // set the color to bright green
  86.  
  87.     color.red   = 0;
  88.     color.green = 63;
  89.     color.blue  = 0;
  90.  
  91.     // change the currently indexed color register
  92.  
  93.     Write_Color_Reg(index,(RGB_color_ptr)&color);
  94.  
  95.     // let user see it happen
  96.  
  97.     Time_Delay(1);
  98.  
  99.     } // end for index
  100.  
  101. // make color 15 visible so user can read text
  102.  
  103. color.red   = 63;
  104. color.green = 63;
  105. color.blue  = 63;
  106.  
  107. Write_Color_Reg(15,(RGB_color_ptr)&color);
  108.  
  109. Print_String(0,0,15,"Hit a key to restore palette           ",0);
  110. getch();
  111.  
  112. // restore the palette
  113.  
  114. Write_Palette(0,255,(RGB_palette_ptr)&save_palette);
  115.  
  116. Print_String(0,0,15,"Hit a key to switch back to text mode  ",0);
  117. getch();
  118.  
  119. // restore graphics mode to text
  120.  
  121. Set_Graphics_Mode(TEXT_MODE);
  122.  
  123. } // end main
  124.