demoII14_6b.cpp
上传用户:husern
上传日期:2018-01-20
资源大小:42486k
文件大小:40k
源码类别:

游戏

开发平台:

Visual C++

  1. // DEMOII14_6b.CPP - shadow demo with lightmapping and fan model
  2. // READ THIS!
  3. // using dark map and lightsource for opposite effect
  4. // To compile make sure to include DDRAW.LIB, DSOUND.LIB,
  5. // DINPUT.LIB, DINPUT8.LIB, WINMM.LIB in the project link list, and of course 
  6. // the C++ source modules T3DLIB1-12.CPP and the headers T3DLIB1-12.H
  7. // be in the working directory of the compiler
  8. // INCLUDES ///////////////////////////////////////////////
  9. #define DEBUG_ON
  10. #define INITGUID       // make sure al the COM interfaces are available
  11.                        // instead of this you can include the .LIB file
  12.                        // DXGUID.LIB
  13. #define WIN32_LEAN_AND_MEAN  
  14. #include <windows.h>   // include important windows stuff
  15. #include <windowsx.h> 
  16. #include <mmsystem.h> 
  17. #include <iostream.h>  // include important C/C++ stuff
  18. #include <conio.h>  
  19. #include <stdlib.h> 
  20. #include <malloc.h> 
  21. #include <memory.h>  
  22. #include <string.h>   
  23. #include <stdarg.h>
  24. #include <stdio.h>     
  25. #include <math.h>
  26. #include <io.h>
  27. #include <fcntl.h>
  28. #include <ddraw.h>     // directX includes 
  29. #include <dsound.h> 
  30. #include <dmksctrl.h>
  31. #include <dmusici.h>
  32. #include <dmusicc.h>
  33. #include <dmusicf.h>
  34. #include <dinput.h>
  35. #include "T3DLIB1.h"   // game library includes
  36. #include "T3DLIB2.h"
  37. #include "T3DLIB3.h"
  38. #include "T3DLIB4.h"
  39. #include "T3DLIB5.h"
  40. #include "T3DLIB6.h"
  41. #include "T3DLIB7.h"
  42. #include "T3DLIB8.h"
  43. #include "T3DLIB9.h"
  44. #include "T3DLIB10.h"
  45. #include "T3DLIB11.h"
  46. #include "T3DLIB12.h"
  47.                                  
  48. // DEFINES ////////////////////////////////////////////////
  49. // defines for windows interface
  50. #define WINDOW_CLASS_NAME "WIN3DCLASS"  // class name
  51. #define WINDOW_TITLE      "T3D Graphics Console Ver 2.0"
  52. #define WINDOW_WIDTH      800  // size of window
  53. #define WINDOW_HEIGHT     600
  54. #define WINDOW_BPP        16    // bitdepth of window (8,16,24 etc.)
  55.                                 // note: if windowed and not
  56.                                 // fullscreen then bitdepth must
  57.                                 // be same as system bitdepth
  58.                                 // also if 8-bit the a pallete
  59.                                 // is created and attached
  60.    
  61. #define WINDOWED_APP       0 // 0 not windowed, 1 windowed
  62. // create some constants for ease of access
  63. #define AMBIENT_LIGHT_INDEX   0 // ambient light index 
  64. #define INFINITE_LIGHT_INDEX  1 // infinite light index
  65. #define POINT_LIGHT_INDEX     2 // point light index
  66. #define POINT_LIGHT2_INDEX    3 // point light index
  67. // terrain defines
  68. #define TERRAIN_WIDTH         1000
  69. #define TERRAIN_HEIGHT        1000 
  70. #define TERRAIN_SCALE         700
  71. #define MAX_SPEED             20
  72. #define PITCH_RETURN_RATE (.33) // how fast the pitch straightens out
  73. #define PITCH_CHANGE_RATE (.02) // the rate that pitch changes relative to height
  74. #define CAM_HEIGHT_SCALER (.3)  // percentage cam height changes relative to height
  75. #define VELOCITY_SCALER (.025)  // rate velocity changes with height
  76. #define CAM_DECEL       (.25)   // deceleration/friction
  77. #define NUM_OBJECTS          3 // number of objects per class
  78. #define NUM_LIGHT_OBJECTS    5 // number of light models
  79. // PROTOTYPES /////////////////////////////////////////////
  80. // game console
  81. int Game_Init(void *parms=NULL);
  82. int Game_Shutdown(void *parms=NULL);
  83. int Game_Main(void *parms=NULL);
  84. // GLOBALS ////////////////////////////////////////////////
  85. HWND main_window_handle           = NULL; // save the window handle
  86. HINSTANCE main_instance           = NULL; // save the instance
  87. char buffer[2048];                        // used to print text
  88. // initialize camera position and direction
  89. POINT4D  cam_pos    = {0,500,-400,1};
  90. POINT4D  cam_target = {0,0,0,1};
  91. VECTOR4D cam_dir    = {0,0,0,1};
  92. // all your initialization code goes here...
  93. VECTOR4D vscale={1.0,1.0,1.0,1}, 
  94.          vpos = {0,0,150,1}, 
  95.          vrot = {0,0,0,1};
  96. CAM4DV1         cam;            // the single camera
  97. OBJECT4DV2      obj_terrain;    // the terrain object
  98. OBJECT4DV2_PTR  obj_work;
  99. OBJECT4DV2      obj_array[NUM_OBJECTS]; 
  100. OBJECT4DV2_PTR  obj_light;
  101. OBJECT4DV2      obj_light_array[NUM_LIGHT_OBJECTS];
  102. OBJECT4DV2      shadow_obj; 
  103. // filenames of objects to load
  104. char *object_filenames[NUM_OBJECTS] = {
  105.                                         "fan_01c.cob",
  106.                                         "sphere_gouraud_textured_02.cob",  
  107.                                         "fire_constant_cube01.cob",
  108.                                       };
  109. int curr_object  = 0;
  110. #define INDEX_RED_LIGHT_INDEX       0
  111. #define INDEX_GREEN_LIGHT_INDEX     1
  112. #define INDEX_BLUE_LIGHT_INDEX      2
  113. #define INDEX_YELLOW_LIGHT_INDEX    3
  114. #define INDEX_WHITE_LIGHT_INDEX     4
  115. // filenames of objects to load
  116. char *object_light_filenames[NUM_LIGHT_OBJECTS] = {
  117.                                             "cube_constant_red_01.cob",
  118.                                             "cube_constant_green_01.cob",  
  119.                                             "cube_constant_blue_01.cob",
  120.                                             "cube_constant_yellow_01.cob",
  121.                                             "cube_constant_white_01.cob",
  122.                                             };
  123. int curr_light_object  = 0;
  124. RENDERLIST4DV2  rend_list;      // the render list
  125. RGBAV1          white,          // general colors 
  126.                 gray, 
  127.                 black, 
  128.                 red, 
  129.                 green, 
  130.                 blue,
  131.                 yellow,
  132.                 orange; 
  133. ZBUFFERV1 zbuffer;   // our little z buffer!
  134. RENDERCONTEXTV1  rc; // the rendering context;
  135. // physical model defines play with these to change the feel of the vehicle
  136. float gravity       = -.40;    // general gravity
  137. float vel_y         = 0;       // the y velocity of camera/jeep
  138. float cam_speed     = 0;       // speed of the camera/jeep
  139. float sea_level     = 50;      // sea level of the simulation
  140. float gclearance    = 125;      // clearance from the camera to the ground
  141. float neutral_pitch = 10;   // the neutral pitch of the camera
  142. // sounds
  143. int wind_sound_id = -1;
  144. // game imagery assets
  145. BOB cockpit;               // the cockpit image
  146. #define NUM_LIGHTMAPS   9  // 
  147. BITMAP_IMAGE lightmaps[NUM_LIGHTMAPS];   // the light maps
  148. int curr_lightmap = 0;
  149. BITMAP_IMAGE texture_copy;               // copy of the texture
  150. // FUNCTIONS //////////////////////////////////////////////
  151. LRESULT CALLBACK WindowProc(HWND hwnd, 
  152.     UINT msg, 
  153.                             WPARAM wparam, 
  154.                             LPARAM lparam)
  155. {
  156. // this is the main message handler of the system
  157. PAINTSTRUCT ps;    // used in WM_PAINT
  158. HDC hdc;    // handle to a device context
  159. // what is the message 
  160. switch(msg)
  161. {
  162. case WM_CREATE: 
  163.         {
  164. // do initialization stuff here
  165. return(0);
  166. } break;
  167.     case WM_PAINT:
  168.          {
  169.          // start painting
  170.          hdc = BeginPaint(hwnd,&ps);
  171.          // end painting
  172.          EndPaint(hwnd,&ps);
  173.          return(0);
  174.         } break;
  175. case WM_DESTROY: 
  176. {
  177. // kill the application
  178. PostQuitMessage(0);
  179. return(0);
  180. } break;
  181. default:break;
  182.     } // end switch
  183. // process any messages that we didn't take care of 
  184. return (DefWindowProc(hwnd, msg, wparam, lparam));
  185. } // end WinProc
  186. // WINMAIN ////////////////////////////////////////////////
  187. int WINAPI WinMain( HINSTANCE hinstance,
  188. HINSTANCE hprevinstance,
  189. LPSTR lpcmdline,
  190. int ncmdshow)
  191. {
  192. // this is the winmain function
  193. WNDCLASS winclass; // this will hold the class we create
  194. HWND  hwnd; // generic window handle
  195. MSG  msg; // generic message
  196. HDC      hdc;       // generic dc
  197. PAINTSTRUCT ps;     // generic paintstruct
  198. // first fill in the window class stucture
  199. winclass.style = CS_DBLCLKS | CS_OWNDC | 
  200.                           CS_HREDRAW | CS_VREDRAW;
  201. winclass.lpfnWndProc = WindowProc;
  202. winclass.cbClsExtra = 0;
  203. winclass.cbWndExtra = 0;
  204. winclass.hInstance = hinstance;
  205. winclass.hIcon = LoadIcon(NULL, IDI_APPLICATION);
  206. winclass.hCursor = LoadCursor(NULL, IDC_ARROW);
  207. winclass.hbrBackground = (HBRUSH)GetStockObject(BLACK_BRUSH);
  208. winclass.lpszMenuName = NULL; 
  209. winclass.lpszClassName = WINDOW_CLASS_NAME;
  210. // register the window class
  211. if (!RegisterClass(&winclass))
  212. return(0);
  213. // create the window, note the test to see if WINDOWED_APP is
  214. // true to select the appropriate window flags
  215. if (!(hwnd = CreateWindow(WINDOW_CLASS_NAME, // class
  216.   WINDOW_TITLE,  // title
  217.   (WINDOWED_APP ? (WS_OVERLAPPED | WS_SYSMENU | WS_CAPTION) : (WS_POPUP | WS_VISIBLE)),
  218.     0,0,    // x,y
  219.   WINDOW_WIDTH,  // width
  220.                           WINDOW_HEIGHT, // height
  221.   NULL,    // handle to parent 
  222.   NULL,    // handle to menu
  223.   hinstance,// instance
  224.   NULL))) // creation parms
  225. return(0);
  226. // save the window handle and instance in a global
  227. main_window_handle = hwnd;
  228. main_instance      = hinstance;
  229. // resize the window so that client is really width x height
  230. if (WINDOWED_APP)
  231. {
  232. // now resize the window, so the client area is the actual size requested
  233. // since there may be borders and controls if this is going to be a windowed app
  234. // if the app is not windowed then it won't matter
  235. RECT window_rect = {0,0,WINDOW_WIDTH-1,WINDOW_HEIGHT-1};
  236. // make the call to adjust window_rect
  237. AdjustWindowRectEx(&window_rect,
  238.      GetWindowStyle(main_window_handle),
  239.      GetMenu(main_window_handle) != NULL,  
  240.      GetWindowExStyle(main_window_handle));
  241. // save the global client offsets, they are needed in DDraw_Flip()
  242. window_client_x0 = -window_rect.left;
  243. window_client_y0 = -window_rect.top;
  244. // now resize the window with a call to MoveWindow()
  245. MoveWindow(main_window_handle,
  246.            0,                                    // x position
  247.            0,                                    // y position
  248.            window_rect.right - window_rect.left, // width
  249.            window_rect.bottom - window_rect.top, // height
  250.            FALSE);
  251. // show the window, so there's no garbage on first render
  252. ShowWindow(main_window_handle, SW_SHOW);
  253. } // end if windowed
  254. // perform all game console specific initialization
  255. Game_Init();
  256. // disable CTRL-ALT_DEL, ALT_TAB, comment this line out 
  257. // if it causes your system to crash
  258. SystemParametersInfo(SPI_SCREENSAVERRUNNING, TRUE, NULL, 0);
  259. // enter main event loop
  260. while(1)
  261. {
  262. if (PeekMessage(&msg,NULL,0,0,PM_REMOVE))
  263. // test if this is a quit
  264.         if (msg.message == WM_QUIT)
  265.            break;
  266. // translate any accelerator keys
  267. TranslateMessage(&msg);
  268. // send the message to the window proc
  269. DispatchMessage(&msg);
  270. } // end if
  271.     
  272.     // main game processing goes here
  273.     Game_Main();
  274. } // end while
  275. // shutdown game and release all resources
  276. Game_Shutdown();
  277. // enable CTRL-ALT_DEL, ALT_TAB, comment this line out 
  278. // if it causes your system to crash
  279. SystemParametersInfo(SPI_SCREENSAVERRUNNING, FALSE, NULL, 0);
  280. // return to Windows like this
  281. return(msg.wParam);
  282. } // end WinMain
  283. // T3D II GAME PROGRAMMING CONSOLE FUNCTIONS ////////////////
  284. int Game_Init(void *parms)
  285. {
  286. // this function is where you do all the initialization 
  287. // for your game
  288. int index; // looping var
  289. // start up DirectDraw (replace the parms as you desire)
  290. DDraw_Init2(WINDOW_WIDTH, WINDOW_HEIGHT, WINDOW_BPP, WINDOWED_APP,0);
  291. // initialize directinput
  292. DInput_Init();
  293. // acquire the keyboard 
  294. DInput_Init_Keyboard();
  295. // add calls to acquire other directinput devices here...
  296. // initialize directsound and directmusic
  297. DSound_Init();
  298. DMusic_Init();
  299. // hide the mouse
  300. if (!WINDOWED_APP)
  301.     ShowCursor(FALSE);
  302. // seed random number generator
  303. srand(Start_Clock()); 
  304. Open_Error_File("ERROR.TXT");
  305. // initialize math engine
  306. Build_Sin_Cos_Tables();
  307. // initialize the camera with 90 FOV, normalized coordinates
  308. Init_CAM4DV1(&cam,            // the camera object
  309.              CAM_MODEL_EULER, // the euler model
  310.              &cam_pos,        // initial camera position
  311.              &cam_dir,        // initial camera angles
  312.              &cam_target,     // no target
  313.              10.0,            // near and far clipping planes
  314.              12000.0,
  315.              90.0,            // field of view in degrees
  316.              WINDOW_WIDTH,    // size of final screen viewport
  317.              WINDOW_HEIGHT);
  318. VECTOR4D terrain_pos = {0,0,0,0}; 
  319. Generate_Terrain_OBJECT4DV2(&obj_terrain,            // pointer to object
  320.                             TERRAIN_WIDTH,           // width in world coords on x-axis
  321.                             TERRAIN_HEIGHT,          // height (length) in world coords on z-axis
  322.                             TERRAIN_SCALE,           // vertical scale of terrain
  323.                             "heighlightmap_01.bmp",  // filename of height bitmap encoded in 256 colors
  324.                             "sandstone256_256_01.bmp", // "grass256_256_01.bmp", //"checker2562562.bmp",   // filename of texture map
  325.                              RGB16Bit(255,255,255),  // color of terrain if no texture        
  326.                              &terrain_pos,           // initial position
  327.                              NULL,                   // initial rotations
  328.                              POLY4DV2_ATTR_RGB16  
  329.                              //| POLY4DV2_ATTR_SHADE_MODE_FLAT 
  330.                              | POLY4DV2_ATTR_SHADE_MODE_GOURAUD
  331.                              | POLY4DV2_ATTR_SHADE_MODE_TEXTURE);
  332. // now make a copy of the texture bitmap to use as texture source for the 
  333. // lightmapping along with the light map
  334. Create_Bitmap(&texture_copy, 0, 0, 256, 256, 16);
  335. Copy_Bitmap(&texture_copy, 0,0, 
  336.              obj_terrain.texture,0,0,
  337.              256,256);
  338. // set a scaling vector 
  339. VECTOR4D_INITXYZ(&vscale, 20, 20, 20);  
  340. // load all the objects in
  341. for (int index_obj=0; index_obj < NUM_OBJECTS; index_obj++)
  342.     {
  343.     Load_OBJECT4DV2_COB2(&obj_array[index_obj], object_filenames[index_obj],  
  344.                         &vscale, &vpos, &vrot, VERTEX_FLAGS_SWAP_YZ // | VERTEX_FLAGS_INVERT_WINDING_ORDER 
  345.                                                | VERTEX_FLAGS_TRANSFORM_LOCAL 
  346.                                                | VERTEX_FLAGS_TRANSFORM_LOCAL_WORLD
  347.                                                ,0 );
  348.     // angle for circular rotation
  349.     obj_array[index_obj].ivar1 = 0;
  350.     // set initial position
  351.     obj_array[index_obj].world_pos.x = 0;
  352.     obj_array[index_obj].world_pos.y = 200;
  353.     obj_array[index_obj].world_pos.z = 0;
  354.     
  355.     } // end for index_obj
  356. // set current object
  357. curr_object = 0;
  358. obj_work    = &obj_array[curr_object];
  359. // set a scaling vector
  360. VECTOR4D_INITXYZ(&vscale, 20, 20, 20); 
  361. // load all the light objects in
  362. for (index_obj=0; index_obj < NUM_LIGHT_OBJECTS; index_obj++)
  363.     {
  364.     Load_OBJECT4DV2_COB2(&obj_light_array[index_obj], object_light_filenames[index_obj],  
  365.                         &vscale, &vpos, &vrot, VERTEX_FLAGS_INVERT_WINDING_ORDER 
  366.                                                | VERTEX_FLAGS_TRANSFORM_LOCAL 
  367.                                                | VERTEX_FLAGS_TRANSFORM_LOCAL_WORLD
  368.                                               ,0 );
  369.     } // end for index
  370.    
  371. // set current object
  372. curr_light_object = 0;
  373. obj_light    = &obj_light_array[curr_light_object];
  374. // load the shadow object in
  375. VECTOR4D_INITXYZ(&vscale, 1, 1, 1); 
  376. Load_OBJECT4DV2_COB2(&shadow_obj,"shadow_poly_01.cob",  
  377.                     &vscale, &vpos, &vrot, VERTEX_FLAGS_INVERT_WINDING_ORDER | VERTEX_FLAGS_SWAP_YZ 
  378.                                           | VERTEX_FLAGS_TRANSFORM_LOCAL 
  379.                                           | VERTEX_FLAGS_TRANSFORM_LOCAL_WORLD
  380.                                           ,0 );
  381. // set up lights
  382. Reset_Lights_LIGHTV2(lights2, MAX_LIGHTS);
  383. // create some working colors
  384. white.rgba = _RGBA32BIT(255,255,255,0);
  385. gray.rgba  = _RGBA32BIT(100,100,100,0);
  386. black.rgba = _RGBA32BIT(0,0,0,0);
  387. red.rgba   = _RGBA32BIT(255,0,0,0);
  388. green.rgba = _RGBA32BIT(0,255,0,0);
  389. blue.rgba  = _RGBA32BIT(0,0,255,0);
  390. orange.rgba = _RGBA32BIT(255,128,0,0);
  391. yellow.rgba  = _RGBA32BIT(255,255,0,0);
  392. // ambient light
  393. Init_Light_LIGHTV2(lights2,
  394.                    AMBIENT_LIGHT_INDEX,   
  395.                    LIGHTV2_STATE_ON,      // turn the light on
  396.                    LIGHTV2_ATTR_AMBIENT,  // ambient light type
  397.                    gray, black, black,    // color for ambient term only
  398.                    NULL, NULL,            // no need for pos or dir
  399.                    0,0,0,                 // no need for attenuation
  400.                    0,0,0);                // spotlight info NA
  401. VECTOR4D dlight_dir = {-1,1,-1,1};
  402. // directional light
  403. Init_Light_LIGHTV2(lights2,
  404.                    INFINITE_LIGHT_INDEX,  
  405.                    LIGHTV2_STATE_ON,      // turn the light on
  406.                    LIGHTV2_ATTR_INFINITE, // infinite light type
  407.                    black, gray, black,    // color for diffuse term only
  408.                    NULL, &dlight_dir,     // need direction only
  409.                    0,0,0,                 // no need for attenuation
  410.                    0,0,0);                // spotlight info NA
  411. VECTOR4D plight_pos = {0,500,0,1};
  412. // point light
  413. Init_Light_LIGHTV2(lights2,
  414.                    POINT_LIGHT_INDEX,
  415.                    LIGHTV2_STATE_ON,      // turn the light on
  416.                    LIGHTV2_ATTR_POINT,    // pointlight type
  417.                    black, green, black,   // color for diffuse term only
  418.                    &plight_pos, NULL,     // need pos only
  419.                    0,.001,0,              // linear attenuation only
  420.                    0,0,1);                // spotlight info NA
  421. // point light
  422. Init_Light_LIGHTV2(lights2,
  423.                    POINT_LIGHT2_INDEX,
  424.                    LIGHTV2_STATE_ON,     // turn the light on
  425.                    LIGHTV2_ATTR_POINT,   // pointlight type
  426.                    black, red, black,  // color for diffuse term only
  427.                    &plight_pos, NULL,    // need pos only
  428.                    0,.002,0,             // linear attenuation only
  429.                    0,0,1);               // spotlight info NA
  430. VECTOR4D slight2_pos = {0,200,0,1};
  431. VECTOR4D slight2_dir = {-1,1,-1,1};
  432. // create lookup for lighting engine
  433. RGB_16_8_IndexedRGB_Table_Builder(DD_PIXEL_FORMAT565,  // format we want to build table for
  434.                                   palette,             // source palette
  435.                                   rgblookup);          // lookup table
  436. // create the z buffer
  437. Create_Zbuffer(&zbuffer,
  438.                WINDOW_WIDTH,
  439.                WINDOW_HEIGHT,
  440.                ZBUFFER_ATTR_32BIT);
  441.  
  442. // build alpha lookup table
  443. RGB_Alpha_Table_Builder(NUM_ALPHA_LEVELS, rgb_alpha_table);
  444. // load background sounds
  445. wind_sound_id = DSound_Load_WAV("STATIONTHROB.WAV");
  446. // start the sounds
  447. DSound_Play(wind_sound_id, DSBPLAY_LOOPING);
  448. DSound_Set_Volume(wind_sound_id, 100);
  449. #if 0
  450. // load in the cockpit image
  451. Create_BOB(&cockpit, 0,0,800,600,2, BOB_ATTR_VISIBLE | BOB_ATTR_SINGLE_FRAME, DDSCAPS_SYSTEMMEMORY, 0, 16); 
  452. Load_Bitmap_File(&bitmap16bit, "lego02.BMP");
  453. Load_Frame_BOB16(&cockpit, &bitmap16bit,0,0,0,BITMAP_EXTRACT_MODE_ABS);
  454. Unload_Bitmap_File(&bitmap16bit);
  455. Load_Bitmap_File(&bitmap16bit, "lego02b.BMP");
  456. Load_Frame_BOB16(&cockpit, &bitmap16bit,1,0,0,BITMAP_EXTRACT_MODE_ABS);
  457. Unload_Bitmap_File(&bitmap16bit);
  458. #endif
  459. // load in the bitmaps for the lightmaps
  460. for (index=0; index < NUM_LIGHTMAPS; index++)
  461.     {
  462.     sprintf(buffer,"fanlightmaps_0%dc.bmp",index+1);
  463.     Load_Bitmap_File(&bitmap16bit, buffer);
  464.     Create_Bitmap(&lightmaps[index],0,0,256,256, 16);
  465.     Load_Image_Bitmap16(&lightmaps[index], &bitmap16bit,0,0,BITMAP_EXTRACT_MODE_ABS);
  466.     Unload_Bitmap_File(&bitmap16bit);                                    
  467.     } // end for index
  468. // set single precission
  469. //_control87( _PC_24, MCW_PC );
  470. // return success
  471. return(1);
  472. } // end Game_Init
  473. ///////////////////////////////////////////////////////////
  474. int Game_Shutdown(void *parms)
  475. {
  476. // this function is where you shutdown your game and
  477. // release all resources that you allocated
  478. // shut everything down
  479. // release all your resources created for the game here....
  480. // now directsound
  481. DSound_Stop_All_Sounds();
  482. DSound_Delete_All_Sounds();
  483. DSound_Shutdown();
  484. // directmusic
  485. DMusic_Delete_All_MIDI();
  486. DMusic_Shutdown();
  487. // shut down directinput
  488. DInput_Release_Keyboard();
  489. // shutdown directinput
  490. DInput_Shutdown();
  491. // shutdown directdraw last
  492. DDraw_Shutdown();
  493. Close_Error_File();
  494. // return success
  495. return(1);
  496. } // end Game_Shutdown
  497. //////////////////////////////////////////////////////////
  498. int Game_Main(void *parms)
  499. {
  500. // this is the workhorse of your game it will be called
  501. // continuously in real-time this is like main() in C
  502. // all the calls for you game go here!
  503. static MATRIX4X4 mrot;   // general rotation matrix
  504. static float plight_ang = 0, 
  505.              slight_ang = 0; // angles for light motion
  506. // use these to rotate objects
  507. static float x_ang = 0, y_ang = 0, z_ang = 0;
  508. // state variables for different rendering modes and help
  509. static int wireframe_mode   = 1;
  510. static int backface_mode    = 1;
  511. static int lighting_mode    = 1;
  512. static int help_mode        = 1;
  513. static int zsort_mode       = 1;
  514. static int x_clip_mode      = 1;
  515. static int y_clip_mode      = 1;
  516. static int z_clip_mode      = 1;
  517. static float hl = 300, // artificial light height
  518.              ks = 1.25; // generic scaling factor to make things look good
  519. char work_string[256]; // temp string
  520. int index; // looping var
  521. // start the timing clock
  522. Start_Clock();
  523. // clear the drawing surface 
  524. DDraw_Fill_Surface(lpddsback, 0);
  525. // draw the sky
  526. Draw_Rectangle(0,0, WINDOW_WIDTH-1, WINDOW_HEIGHT-1, RGB16Bit(50,50,200), lpddsback);
  527. // draw the ground
  528. //Draw_Rectangle(0,WINDOW_HEIGHT*.38, WINDOW_WIDTH, WINDOW_HEIGHT, RGB16Bit(25,50,110), lpddsback);
  529. // read keyboard and other devices here
  530. DInput_Read_Keyboard();
  531. // game logic here...
  532. // reset the render list
  533. Reset_RENDERLIST4DV2(&rend_list);
  534. // modes and lights
  535. // wireframe mode
  536. if (keyboard_state[DIK_W]) 
  537.    {
  538.    // toggle wireframe mode
  539.    if (++wireframe_mode > 1)
  540.        wireframe_mode=0;
  541.    Wait_Clock(100); // wait, so keyboard doesn't bounce
  542.    } // end if
  543. // backface removal
  544. if (keyboard_state[DIK_B])
  545.    {
  546.    // toggle backface removal
  547.    backface_mode = -backface_mode;
  548.    Wait_Clock(100); // wait, so keyboard doesn't bounce
  549.    } // end if
  550. // lighting
  551. if (keyboard_state[DIK_L])
  552.    {
  553.    // toggle lighting engine completely
  554.    lighting_mode = -lighting_mode;
  555.    Wait_Clock(100); // wait, so keyboard doesn't bounce
  556.    } // end if
  557. // toggle ambient light
  558. if (keyboard_state[DIK_A])
  559.    {
  560.    // toggle ambient light
  561.    if (lights2[AMBIENT_LIGHT_INDEX].state == LIGHTV2_STATE_ON)
  562.       lights2[AMBIENT_LIGHT_INDEX].state = LIGHTV2_STATE_OFF;
  563.    else
  564.       lights2[AMBIENT_LIGHT_INDEX].state = LIGHTV2_STATE_ON;
  565.    Wait_Clock(100); // wait, so keyboard doesn't bounce
  566.    } // end if
  567. // toggle infinite light
  568. if (keyboard_state[DIK_I])
  569.    {
  570.    // toggle ambient light
  571.    if (lights2[INFINITE_LIGHT_INDEX].state == LIGHTV2_STATE_ON)
  572.       lights2[INFINITE_LIGHT_INDEX].state = LIGHTV2_STATE_OFF;
  573.    else
  574.       lights2[INFINITE_LIGHT_INDEX].state = LIGHTV2_STATE_ON;
  575.    Wait_Clock(100); // wait, so keyboard doesn't bounce
  576.    } // end if
  577. // toggle point light
  578. if (keyboard_state[DIK_P])
  579.    {
  580.    // toggle point light
  581.    if (lights2[POINT_LIGHT_INDEX].state == LIGHTV2_STATE_ON)
  582.       lights2[POINT_LIGHT_INDEX].state = LIGHTV2_STATE_OFF;
  583.    else
  584.       lights2[POINT_LIGHT_INDEX].state = LIGHTV2_STATE_ON;
  585.    // toggle point light
  586.    if (lights2[POINT_LIGHT2_INDEX].state == LIGHTV2_STATE_ON)
  587.       lights2[POINT_LIGHT2_INDEX].state = LIGHTV2_STATE_OFF;
  588.    else
  589.       lights2[POINT_LIGHT2_INDEX].state = LIGHTV2_STATE_ON;
  590.    Wait_Clock(100); // wait, so keyboard doesn't bounce
  591.    } // end if
  592. // help menu
  593. if (keyboard_state[DIK_H])
  594.    {
  595.    // toggle help menu 
  596.    help_mode = -help_mode;
  597.    Wait_Clock(100); // wait, so keyboard doesn't bounce
  598.    } // end if
  599. // z-sorting
  600. if (keyboard_state[DIK_Z])
  601.    {
  602.    // toggle z sorting
  603.    zsort_mode = -zsort_mode;
  604.    Wait_Clock(100); // wait, so keyboard doesn't bounce
  605.    } // end if
  606. // move to next object
  607. if (keyboard_state[DIK_O])
  608.    {
  609.    VECTOR4D old_pos;
  610.    old_pos = obj_work->world_pos;
  611.    if (++curr_object >= NUM_OBJECTS)
  612.       curr_object = 0;
  613.    // update pointer
  614.    obj_work = &obj_array[curr_object];
  615.    obj_work->world_pos = old_pos;
  616.    Wait_Clock(100); // wait, so keyboard doesn't bounce
  617.    } // end if
  618. // forward/backward
  619. if (keyboard_state[DIK_UP])
  620.    {
  621.    // move forward
  622.    if ( (cam_speed+=1) > MAX_SPEED) cam_speed = MAX_SPEED;
  623.    } // end if
  624. else
  625. if (keyboard_state[DIK_DOWN])
  626.    {
  627.    // move backward
  628.    if ((cam_speed-=1) < -MAX_SPEED) cam_speed = -MAX_SPEED;
  629.    } // end if
  630. // rotate around y axis or yaw
  631. if (keyboard_state[DIK_RIGHT])
  632.    {
  633.    cam.dir.y+=5;
  634.    } // end if
  635. if (keyboard_state[DIK_LEFT])
  636.    {
  637.    cam.dir.y-=5;
  638.    } // end if
  639. // change height of point light source 1
  640. if (keyboard_state[DIK_1])
  641.    {
  642.    lights2[POINT_LIGHT_INDEX].pos.y-=10;
  643.    } // end if
  644. if (keyboard_state[DIK_2])
  645.    {
  646.    lights2[POINT_LIGHT_INDEX].pos.y+=10;
  647.    } // end if
  648. // change height of point light source 2
  649. if (keyboard_state[DIK_3])
  650.    {
  651.    lights2[POINT_LIGHT2_INDEX].pos.y-=10;
  652.    } // end if
  653. if (keyboard_state[DIK_4])
  654.    {
  655.    lights2[POINT_LIGHT2_INDEX].pos.y+=10;
  656.    } // end if
  657. // perform lightmapping here //////////////////////////////////////////////
  658. // the idea is to take the source lightmap and use it to modulate the texture
  659. // that is being mapped onto the target polygons and then write the results
  660. // into the texture for rendering
  661. ///////////////////////////////////////////
  662. // our little image processing algorithm :)
  663. // Pixel_dest[x,y]rgb = pixel_source[x,y]rgb * light_map[x,y]rgb
  664. USHORT *sbuffer = (USHORT *)texture_copy.buffer;
  665. USHORT *lbuffer = (USHORT *)lightmaps[curr_lightmap].buffer;
  666. USHORT *dbuffer = (USHORT *)obj_terrain.texture->buffer;
  667. // perform RGB transformation on bitmap
  668. for (int iy = 0; iy < texture_copy.height; iy++)
  669.     for (int ix = 0; ix < texture_copy.width; ix++)
  670.          {
  671.          int rs,gs,bs;   // used to extract the source rgb values
  672.          int rl, gl, bl; // light map rgb values
  673.          int rf,gf,bf;   // the final rgb terms
  674.          // extract pixel from source bitmap
  675.          USHORT spixel = sbuffer[iy*texture_copy.width + ix];
  676.          // extract RGB values
  677.          _RGB565FROM16BIT(spixel, &rs,&gs,&bs);
  678.          // extract pixel from lightmap bitmap
  679.          USHORT lpixel = lbuffer[iy*texture_copy.width + ix];
  680.          // extract RGB values
  681.          _RGB565FROM16BIT(lpixel, &rl,&gl,&bl);
  682.          // compute modulation term
  683.          //rf = ( (float)rs*(float)rl/(float)32 );
  684.          //gf = ( (float)gs*(float)gl/(float)64 );
  685.          //bf = ( (float)bs*(float)bl/(float)32 );
  686.          rf = ( (rs*rl) >> 5 );
  687.          gf = ( (gs*gl) >> 6 );
  688.          bf = ( (bs*bl) >> 5 );
  689.          // test for overflow
  690.          //if (rf > 255) rf=255;
  691.          //if (gf > 255) gf=255;
  692.          //if (bf > 255) bf=255;
  693.          // rebuild RGB and test for overflow
  694.          // and write back to buffer
  695.          dbuffer[iy*texture_copy.width + ix] = _RGB16BIT565(rf,gf,bf);
  696.          
  697.          } // end for ix     
  698. if (++curr_lightmap >=9 )
  699.    curr_lightmap = 0;
  700. // motion section /////////////////////////////////////////////////////////
  701. // terrain following, simply find the current cell we are over and then
  702. // index into the vertex list and find the 4 vertices that make up the 
  703. // quad cell we are hovering over and then average the values, and based
  704. // on the current height and the height of the terrain push the player upward
  705. // the terrain generates and stores some results to help with terrain following
  706. //ivar1 = columns;
  707. //ivar2 = rows;
  708. //fvar1 = col_vstep;
  709. //fvar2 = row_vstep;
  710. int cell_x = (cam.pos.x  + TERRAIN_WIDTH/2) / obj_terrain.fvar1;
  711. int cell_y = (cam.pos.z  + TERRAIN_HEIGHT/2) / obj_terrain.fvar1;
  712. static float terrain_height, delta;
  713. // test if we are on terrain
  714. if ( (cell_x >=0) && (cell_x < obj_terrain.ivar1) && (cell_y >=0) && (cell_y < obj_terrain.ivar2) )
  715.    {
  716.    // compute vertex indices into vertex list of the current quad
  717.    int v0 = cell_x + cell_y*obj_terrain.ivar2;
  718.    int v1 = v0 + 1;
  719.    int v2 = v1 + obj_terrain.ivar2;
  720.    int v3 = v0 + obj_terrain.ivar2;   
  721.    // now simply index into table 
  722.    terrain_height = 0.25 * (obj_terrain.vlist_trans[v0].y + obj_terrain.vlist_trans[v1].y +
  723.                             obj_terrain.vlist_trans[v2].y + obj_terrain.vlist_trans[v3].y);
  724.    // compute height difference
  725.    delta = terrain_height - (cam.pos.y - gclearance);
  726.    // test for penetration
  727.    if (delta > 0)
  728.       {
  729.       // apply force immediately to camera (this will give it a springy feel)
  730.       vel_y+=(delta * (VELOCITY_SCALER));
  731.       // test for pentration, if so move up immediately so we don't penetrate geometry
  732.       cam.pos.y+=(delta*CAM_HEIGHT_SCALER);
  733.       // now this is more of a hack than the physics model :) let move the front
  734.       // up and down a bit based on the forward velocity and the gradient of the 
  735.       // hill
  736.       cam.dir.x -= (delta*PITCH_CHANGE_RATE);
  737.  
  738.       } // end if
  739.    } // end if
  740. // decelerate camera
  741. if (cam_speed > (CAM_DECEL) ) cam_speed-=CAM_DECEL;
  742. else
  743. if (cam_speed < (-CAM_DECEL) ) cam_speed+=CAM_DECEL;
  744. else
  745.    cam_speed = 0;
  746. // force camera to seek a stable orientation
  747. if (cam.dir.x > (neutral_pitch+PITCH_RETURN_RATE)) cam.dir.x -= (PITCH_RETURN_RATE);
  748. else
  749. if (cam.dir.x < (neutral_pitch-PITCH_RETURN_RATE)) cam.dir.x += (PITCH_RETURN_RATE);
  750.  else 
  751.    cam.dir.x = neutral_pitch;
  752. // apply gravity
  753. vel_y+=gravity;
  754. // test for absolute sea level and push upward..
  755. if (cam.pos.y < sea_level)
  756.    { 
  757.    vel_y = 0; 
  758.    cam.pos.y = sea_level;
  759.    } // end if
  760. // move camera
  761. cam.pos.x += cam_speed*Fast_Sin(cam.dir.y);
  762. cam.pos.z += cam_speed*Fast_Cos(cam.dir.y);
  763. cam.pos.y += vel_y;
  764. // move point light source in ellipse around game world
  765. lights2[POINT_LIGHT_INDEX].pos.x = 500*Fast_Cos(plight_ang);
  766. //lights2[POINT_LIGHT_INDEX].pos.y = 200;
  767. lights2[POINT_LIGHT_INDEX].pos.z = 500*Fast_Sin(plight_ang);
  768. // move point light source in ellipse around game world
  769. lights2[POINT_LIGHT2_INDEX].pos.x = 200*Fast_Cos(-2*plight_ang);
  770. //lights2[POINT_LIGHT2_INDEX].pos.y = 400;
  771. lights2[POINT_LIGHT2_INDEX].pos.z = 200*Fast_Sin(-2*plight_ang);
  772. if ((plight_ang+=1) > 360)
  773.     plight_ang = 0;
  774. // generate camera matrix
  775. Build_CAM4DV1_Matrix_Euler(&cam, CAM_ROT_SEQ_ZYX);
  776. //////////////////////////////////////////////////////////////////////////
  777. // the terrain
  778. // reset the object (this only matters for backface and object removal)
  779. Reset_OBJECT4DV2(&obj_terrain);
  780. // generate rotation matrix around y axis
  781. //Build_XYZ_Rotation_MATRIX4X4(x_ang, y_ang, z_ang, &mrot);
  782. MAT_IDENTITY_4X4(&mrot); 
  783. // rotate the local coords of the object
  784. Transform_OBJECT4DV2(&obj_terrain, &mrot, TRANSFORM_LOCAL_TO_TRANS,1);
  785. // perform world transform
  786. Model_To_World_OBJECT4DV2(&obj_terrain, TRANSFORM_TRANS_ONLY);
  787. // insert the object into render list
  788. Insert_OBJECT4DV2_RENDERLIST4DV2(&rend_list, &obj_terrain,0);
  789. //////////////////////////////////////////////////////////////////////////
  790. int v0, v1, v2, v3; // used to track vertices
  791. VECTOR4D pl,  // position of the light
  792.          po,  // position of the occluder object/vertex
  793.          vlo, // vector from light to object
  794.          ps;  // position of the shadow
  795. float    rs,  // radius of shadow 
  796.          t;   // parameter t
  797. //////////////////////////////////////////////////////////////////////////
  798. // render shaded object that projects shadow
  799. // update rotation angle of object
  800. obj_work->ivar1+=1.0;
  801. if (obj_work->ivar1 >= 360)
  802.     obj_work->ivar1 = 0;
  803. // set position of object 
  804. //obj_work->world_pos.x = 150*Fast_Cos(obj_work->ivar1);
  805. //obj_work->world_pos.y = 200+75*Fast_Sin(obj_work->ivar1);
  806. //obj_work->world_pos.z = 150*Fast_Sin(obj_work->ivar1);
  807. // reset the object (this only matters for backface and object removal)
  808. Reset_OBJECT4DV2(obj_work);
  809. // generate rotation matrix around y axis
  810. Build_XYZ_Rotation_MATRIX4X4(0, -10.0f, 0, &mrot);
  811. Transform_OBJECT4DV2(obj_work, &mrot, TRANSFORM_LOCAL_ONLY,1);
  812. // create identity matrix
  813. MAT_IDENTITY_4X4(&mrot);
  814. // rotate the local coords of the object
  815. Transform_OBJECT4DV2(obj_work, &mrot, TRANSFORM_LOCAL_TO_TRANS,1);
  816. // perform world transform
  817. Model_To_World_OBJECT4DV2(obj_work, TRANSFORM_TRANS_ONLY);
  818. // insert the object into render list
  819. Insert_OBJECT4DV2_RENDERLIST4DV2(&rend_list, obj_work,0);
  820. //////////////////////////////////////////////////////////////////////////
  821. //////////////////////////////////////////////////////////////////////////
  822. // draw all the light objects to represent the position of light sources
  823. // reset the object (this only matters for backface and object removal)
  824. Reset_OBJECT4DV2(&obj_light_array[INDEX_GREEN_LIGHT_INDEX]);
  825. // set position of object to light
  826. obj_light_array[INDEX_GREEN_LIGHT_INDEX].world_pos = lights2[POINT_LIGHT_INDEX].pos;
  827. // create identity matrix
  828. MAT_IDENTITY_4X4(&mrot);
  829. // transform the local coords of the object
  830. Transform_OBJECT4DV2(&obj_light_array[INDEX_GREEN_LIGHT_INDEX], &mrot, TRANSFORM_LOCAL_TO_TRANS,1);
  831. // perform world transform
  832. Model_To_World_OBJECT4DV2(&obj_light_array[INDEX_GREEN_LIGHT_INDEX], TRANSFORM_TRANS_ONLY);
  833. // insert the object into render list
  834. Insert_OBJECT4DV2_RENDERLIST4DV2(&rend_list, &obj_light_array[INDEX_GREEN_LIGHT_INDEX],0);
  835. // reset the object (this only matters for backface and object removal)
  836. Reset_OBJECT4DV2(&obj_light_array[INDEX_RED_LIGHT_INDEX]);
  837. // set position of object to light
  838. obj_light_array[INDEX_RED_LIGHT_INDEX].world_pos = lights2[POINT_LIGHT2_INDEX].pos;
  839. // create identity matrix
  840. MAT_IDENTITY_4X4(&mrot);
  841. // transform the local coords of the object
  842. Transform_OBJECT4DV2(&obj_light_array[INDEX_RED_LIGHT_INDEX], &mrot, TRANSFORM_LOCAL_TO_TRANS,1);
  843. // perform world transform
  844. Model_To_World_OBJECT4DV2(&obj_light_array[INDEX_RED_LIGHT_INDEX], TRANSFORM_TRANS_ONLY);
  845. // insert the object into render list
  846. Insert_OBJECT4DV2_RENDERLIST4DV2(&rend_list, &obj_light_array[INDEX_RED_LIGHT_INDEX],0);
  847. ////////////////////////////////////////////////////////////////////////////////////
  848. // reset number of polys rendered
  849. debug_polys_rendered_per_frame = 0;
  850. debug_polys_lit_per_frame = 0;
  851. // perform rendering pass one
  852. // remove backfaces
  853. if (backface_mode==1)
  854.    Remove_Backfaces_RENDERLIST4DV2(&rend_list, &cam);
  855. // apply world to camera transform
  856. World_To_Camera_RENDERLIST4DV2(&rend_list, &cam);
  857. // clip the polygons themselves now
  858. Clip_Polys_RENDERLIST4DV2(&rend_list, &cam, CLIP_POLY_X_PLANE | CLIP_POLY_Y_PLANE | CLIP_POLY_Z_PLANE );
  859. // light scene all at once 
  860. if (lighting_mode==1)
  861.    {
  862.    Transform_LIGHTSV2(lights2, 4, &cam.mcam, TRANSFORM_LOCAL_TO_TRANS);
  863.    Light_RENDERLIST4DV2_World2_16(&rend_list, &cam, lights2, 4);
  864.    } // end if
  865. // sort the polygon list (hurry up!)
  866. if (zsort_mode == 1)
  867.    Sort_RENDERLIST4DV2(&rend_list,  SORT_POLYLIST_AVGZ);
  868. // apply camera to perspective transformation
  869. Camera_To_Perspective_RENDERLIST4DV2(&rend_list, &cam);
  870. // apply screen transform
  871. Perspective_To_Screen_RENDERLIST4DV2(&rend_list, &cam);
  872. // lock the back buffer
  873. DDraw_Lock_Back_Surface();
  874. // reset number of polys rendered
  875. debug_polys_rendered_per_frame = 0;
  876. // render the object
  877. if (wireframe_mode  == 0)
  878.    Draw_RENDERLIST4DV2_Wire16(&rend_list, back_buffer, back_lpitch);
  879. else
  880. if (wireframe_mode  == 1)
  881.    {
  882.    // perspective mode affine texturing
  883.       // set up rendering context
  884.       rc.attr =    RENDER_ATTR_ZBUFFER  
  885.               // | RENDER_ATTR_ALPHA  
  886.               // | RENDER_ATTR_MIPMAP  
  887.               // | RENDER_ATTR_BILERP
  888.                  | RENDER_ATTR_TEXTURE_PERSPECTIVE_AFFINE;
  889.    // initialize zbuffer to 0 fixed point
  890.    Clear_Zbuffer(&zbuffer, (16000 << FIXP16_SHIFT));
  891.    // set up remainder of rendering context
  892.    rc.video_buffer   = back_buffer;
  893.    rc.lpitch         = back_lpitch;
  894.    rc.mip_dist       = 0;
  895.    rc.zbuffer        = (UCHAR *)zbuffer.zbuffer;
  896.    rc.zpitch         = WINDOW_WIDTH*4;
  897.    rc.rend_list      = &rend_list;
  898.    rc.texture_dist   = 0;
  899.    rc.alpha_override = -1;
  900.    // render scene
  901.    Draw_RENDERLIST4DV2_RENDERCONTEXTV1_16_2(&rc);
  902.    } // end if
  903. // unlock the back buffer
  904. DDraw_Unlock_Back_Surface();
  905. // draw cockpit
  906. //Draw_BOB16(&cockpit, lpddsback);
  907. sprintf(work_string,"Lighting [%s]: Ambient=%d, Infinite=%d, Point=%d, BckFceRM [%s], Green Light y=%f, Red Light y=%f", 
  908.                                                                                  ((lighting_mode == 1) ? "ON" : "OFF"),
  909.                                                                                  lights2[AMBIENT_LIGHT_INDEX].state,
  910.                                                                                  lights2[INFINITE_LIGHT_INDEX].state, 
  911.                                                                                  lights2[POINT_LIGHT_INDEX].state,
  912.                                                                                  ((backface_mode == 1) ? "ON" : "OFF"), 
  913.                                                                                  lights2[POINT_LIGHT_INDEX].pos.y, lights2[POINT_LIGHT2_INDEX].pos.y);
  914. Draw_Text_GDI(work_string, 0, WINDOW_HEIGHT-34, RGB(0,255,0), lpddsback);
  915. // draw instructions
  916. Draw_Text_GDI("Press ESC to exit. Press <H> for Help.", 0, 0, RGB(0,255,0), lpddsback);
  917. // should we display help
  918. int text_y = 16;
  919. if (help_mode==1)
  920.     {
  921.     // draw help menu
  922.     Draw_Text_GDI("<A>..............Toggle ambient light source.", 0, text_y+=12, RGB(255,255,255), lpddsback);
  923.     Draw_Text_GDI("<I>..............Toggle infinite light source.", 0, text_y+=12, RGB(255,255,255), lpddsback);
  924.     Draw_Text_GDI("<P>..............Toggle point light source.", 0, text_y+=12, RGB(255,255,255), lpddsback);
  925.     Draw_Text_GDI("<W>..............Toggle wire frame/solid mode.", 0, text_y+=12, RGB(255,255,255), lpddsback);
  926.     Draw_Text_GDI("<B>..............Toggle backface removal.", 0, text_y+=12, RGB(255,255,255), lpddsback);
  927.     Draw_Text_GDI("<O>..............Select different objects.", 0, text_y+=12, RGB(255,255,255), lpddsback);
  928.     Draw_Text_GDI("<1>,<2>..........Change height of green point light.", 0, text_y+=12, RGB(255,255,255), lpddsback);
  929.     Draw_Text_GDI("<3>,<4>..........Change height of red point light.", 0, text_y+=12, RGB(255,255,255), lpddsback);
  930.     Draw_Text_GDI("<H>..............Toggle Help.", 0, text_y+=12, RGB(255,255,255), lpddsback);
  931.     Draw_Text_GDI("<ESC>............Exit demo.", 0, text_y+=12, RGB(255,255,255), lpddsback);
  932.     } // end help
  933. sprintf(work_string,"Polys Rendered: %d, Polys lit: %d", debug_polys_rendered_per_frame, debug_polys_lit_per_frame);
  934. Draw_Text_GDI(work_string, 0, WINDOW_HEIGHT-34-16-16, RGB(0,255,0), lpddsback);
  935. sprintf(work_string,"CAM [%5.2f, %5.2f, %5.2f], CELL [%d, %d]",  cam.pos.x, cam.pos.y, cam.pos.z, cell_x, cell_y);
  936. Draw_Text_GDI(work_string, 0, WINDOW_HEIGHT-34-16-16-16, RGB(0,255,0), lpddsback);
  937. // flip the surfaces
  938. DDraw_Flip2();
  939. // sync to 30ish fps
  940. Wait_Clock(30);
  941. // check of user is trying to exit
  942. if (KEY_DOWN(VK_ESCAPE) || keyboard_state[DIK_ESCAPE])
  943.     {
  944.     PostMessage(main_window_handle, WM_DESTROY,0,0);
  945.     } // end if
  946. // return success
  947. return(1);
  948.   
  949. } // end Game_Main
  950. //////////////////////////////////////////////////////////