home *** CD-ROM | disk | FTP | other *** search
/ Black Art of 3D Game Programming / Black_Art_of_3D_Game_Programming.iso / source / borland / chap_12 / textdemo.c < prev    next >
Encoding:
C/C++ Source or Header  |  1995-01-31  |  2.8 KB  |  130 lines

  1.  
  2. // I N C L U D E S ///////////////////////////////////////////////////////////
  3.  
  4. #include <io.h>
  5. #include <conio.h>
  6. #include <stdio.h>
  7. #include <stdlib.h>
  8. #include <dos.h>
  9. #include <bios.h>
  10. #include <fcntl.h>
  11. #include <memory.h>
  12. #include <malloc.h>
  13. #include <math.h>
  14. #include <string.h>
  15.  
  16. // include all of our stuff
  17.  
  18. #include "black3.h"
  19. #include "black4.h"
  20. #include "black5.h"
  21. #include "black6.h"
  22. #include "black8.h"
  23. #include "black9.h"
  24. #include "black11.h"
  25.  
  26. // G L O B A L S /////////////////////////////////////////////////////////////
  27.  
  28. pcx_picture image_pcx;  // general PCX image used to load background and imagery
  29.  
  30. ////////////////////////////////////////////////////////////////////////////////
  31.  
  32. void main(void)
  33. {
  34.  
  35. int done=0,          // exit flag
  36.     index,           // looping variable
  37.     x=140,y=100,     // position of triangle
  38.     curr_texture=0;  // current texture
  39.  
  40. // set graphics mode to 13h
  41.  
  42. Set_Graphics_Mode(GRAPHICS_MODE13);
  43.  
  44. // load in the text textures 64x64
  45.  
  46. PCX_Init((pcx_picture_ptr)&image_pcx);
  47. PCX_Load("textures.pcx", (pcx_picture_ptr)&image_pcx,1);
  48.  
  49. // intialize the texture sprite
  50.  
  51. Sprite_Init((sprite_ptr)&textures,0,0,64,64,0,0,0,0,0,0);
  52.  
  53. // extract the bitmaps for the textures(four of them:stone, wood, slime, lava)
  54.  
  55. for (index=0; index<4; index++)
  56.     PCX_Get_Sprite((pcx_picture_ptr)&image_pcx,(sprite_ptr)&textures,index,index,0);
  57.  
  58. // done with this PCX file so delete memory associated with it
  59.  
  60. PCX_Delete((pcx_picture_ptr)&image_pcx);
  61.  
  62. // draw textures on screen so user can see what is going on
  63.  
  64. Sprite_Draw((sprite_ptr)&textures,video_buffer,1);
  65. textures.x+=64;
  66. textures.curr_frame++;
  67.  
  68. Sprite_Draw((sprite_ptr)&textures,video_buffer,1);
  69. textures.x+=64;
  70. textures.curr_frame++;
  71.  
  72. Sprite_Draw((sprite_ptr)&textures,video_buffer,1);
  73. textures.x+=64;
  74. textures.curr_frame++;
  75.  
  76. Sprite_Draw((sprite_ptr)&textures,video_buffer,1);
  77. textures.x+=64;
  78. textures.curr_frame++;
  79.  
  80. // draw textured triangle
  81.  
  82. Draw_Triangle_2D_Text(x,y,x-50,y+60,x+30,y+80,video_buffer,curr_texture);
  83.  
  84. // main loop
  85.  
  86. while(!done)
  87.      {
  88.      // test for key
  89.  
  90.      if (kbhit())
  91.         {
  92.  
  93.         // get the key
  94.  
  95.         switch(getch())
  96.               {
  97.               case ' ': // space bar to select next texture
  98.                  {
  99.  
  100.                  if (++curr_texture>3)
  101.                     curr_texture=0;
  102.  
  103.                  } break;
  104.  
  105.               case 27: // escape key
  106.                  {
  107.                  // exit system
  108.                  done=1;
  109.  
  110.                  } break;
  111.  
  112.               default:break;
  113.  
  114.               } // end switch
  115.  
  116.         // draw textured triangle
  117.  
  118.         Draw_Triangle_2D_Text(x,y,x-50,y+60,x+30,y+80,video_buffer,curr_texture);
  119.  
  120.         } // end kbhit
  121.  
  122.      } // end while
  123.  
  124. // restore text mode
  125.  
  126. Set_Graphics_Mode(TEXT_MODE);
  127.  
  128. } // end main
  129.  
  130.