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

游戏

开发平台:

Visual C++

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