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

游戏

开发平台:

Visual C++

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