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

游戏

开发平台:

Visual C++

  1. // DEMOII12_12.CPP - multipass Alpha Blending/reflection demo
  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-10.CPP and the headers T3DLIB1-10.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. // DEFINES ////////////////////////////////////////////////
  45. // defines for windows interface
  46. #define WINDOW_CLASS_NAME "WIN3DCLASS"  // class name
  47. #define WINDOW_TITLE      "T3D Graphics Console Ver 2.0"
  48. #define WINDOW_WIDTH      800  // size of window
  49. #define WINDOW_HEIGHT     600
  50. #define WINDOW_BPP        16    // bitdepth of window (8,16,24 etc.)
  51.                                 // note: if windowed and not
  52.                                 // fullscreen then bitdepth must
  53.                                 // be same as system bitdepth
  54.                                 // also if 8-bit the a pallete
  55.                                 // is created and attached
  56.    
  57. #define WINDOWED_APP      0    // 0 not windowed, 1 windowed 
  58. // create some constants for ease of access
  59. #define AMBIENT_LIGHT_INDEX   0 // ambient light index
  60. #define INFINITE_LIGHT_INDEX  1 // infinite light index
  61. #define POINT_LIGHT_INDEX     2 // point light index
  62. #define SPOT_LIGHT1_INDEX     4 // point light index
  63. #define SPOT_LIGHT2_INDEX     3 // spot light index
  64. // terrain defines
  65. #define TERRAIN_WIDTH         2000
  66. #define TERRAIN_HEIGHT        2000
  67. #define TERRAIN_SCALE         700
  68. #define CAM_DECEL            (.25)  // deceleration/friction
  69. #define MAX_SPEED             20
  70. #define NUM_OBJECTS           7     // number of objects system loads
  71. #define NUM_SCENE_OBJECTS     25    // number of scenery objects 
  72. #define UNIVERSE_RADIUS       1750  // size of universe
  73. #define MAX_VEL               10   // maxium velocity of objects
  74. // PROTOTYPES /////////////////////////////////////////////
  75. // game console
  76. int Game_Init(void *parms=NULL);
  77. int Game_Shutdown(void *parms=NULL);
  78. int Game_Main(void *parms=NULL);
  79. // GLOBALS ////////////////////////////////////////////////
  80. HWND main_window_handle           = NULL; // save the window handle
  81. HINSTANCE main_instance           = NULL; // save the instance
  82. char buffer[2048];                        // used to print text
  83. // initialize camera position and direction
  84. POINT4D  cam_pos    = {0,0,0,1};
  85. POINT4D  cam_target = {0,0,0,1};
  86. VECTOR4D cam_dir    = {0,0,0,1};
  87. // all your initialization code goes here...
  88. VECTOR4D vscale={1.0,1.0,1.0,1},  
  89.          vpos = {0,0,150,1}, 
  90.          vrot = {0,0,0,1};
  91. CAM4DV1         cam;                    // the single camera
  92. OBJECT4DV2_PTR  obj_work;               // pointer to active working object
  93. OBJECT4DV2      obj_array[NUM_OBJECTS], // array of objects 
  94.                 obj_scene,              // general scenery object
  95.                 obj_terrain;            // the terrain object
  96.                
  97. // filenames of objects to load
  98. char *object_filenames[NUM_OBJECTS] = { "sphere_bw01.cob",
  99.                                         "cube_constant_textured_01.cob",
  100.                                         "cube_constant_textured_02.cob",
  101.                                         "fire_constant_cube01.cob",
  102.                                          "borg_cube_constant01.cob",
  103.                                          "sphere_constant_textured_02.cob",
  104.                                          "earth01.cob",
  105.                                       };
  106. POINT4D         scene_objects[NUM_SCENE_OBJECTS];     // positions of scenery objects
  107. VECTOR4D        scene_objects_vel[NUM_SCENE_OBJECTS]; // velocities of scenery objects
  108. RENDERLIST4DV2  rend_list;      // the render list
  109. RGBAV1 white, gray, black, red, green, blue; // general colors
  110. // physical model defines
  111. float cam_speed  = 0;       // speed of the camera/jeep
  112. ZBUFFERV1 zbuffer;          // out little z buffer!
  113. RENDERCONTEXTV1 rc;         // the rendering context
  114. BOB background;             // the background image
  115. // FUNCTIONS //////////////////////////////////////////////
  116. LRESULT CALLBACK WindowProc(HWND hwnd, 
  117.     UINT msg, 
  118.                             WPARAM wparam, 
  119.                             LPARAM lparam)
  120. {
  121. // this is the main message handler of the system
  122. PAINTSTRUCT ps;    // used in WM_PAINT
  123. HDC hdc;    // handle to a device context
  124. // what is the message 
  125. switch(msg)
  126. {
  127. case WM_CREATE: 
  128.         {
  129. // do initialization stuff here
  130. return(0);
  131. } break;
  132.     case WM_PAINT:
  133.          {
  134.          // start painting
  135.          hdc = BeginPaint(hwnd,&ps);
  136.          // end painting
  137.          EndPaint(hwnd,&ps);
  138.          return(0);
  139.         } break;
  140. case WM_DESTROY: 
  141. {
  142. // kill the application
  143. PostQuitMessage(0);
  144. return(0);
  145. } break;
  146. default:break;
  147.     } // end switch
  148. // process any messages that we didn't take care of 
  149. return (DefWindowProc(hwnd, msg, wparam, lparam));
  150. } // end WinProc
  151. // WINMAIN ////////////////////////////////////////////////
  152. int WINAPI WinMain( HINSTANCE hinstance,
  153. HINSTANCE hprevinstance,
  154. LPSTR lpcmdline,
  155. int ncmdshow)
  156. {
  157. // this is the winmain function
  158. WNDCLASS winclass; // this will hold the class we create
  159. HWND  hwnd; // generic window handle
  160. MSG  msg; // generic message
  161. HDC      hdc;       // generic dc
  162. PAINTSTRUCT ps;     // generic paintstruct
  163. // first fill in the window class stucture
  164. winclass.style = CS_DBLCLKS | CS_OWNDC | 
  165.                           CS_HREDRAW | CS_VREDRAW;
  166. winclass.lpfnWndProc = WindowProc;
  167. winclass.cbClsExtra = 0;
  168. winclass.cbWndExtra = 0;
  169. winclass.hInstance = hinstance;
  170. winclass.hIcon = LoadIcon(NULL, IDI_APPLICATION);
  171. winclass.hCursor = LoadCursor(NULL, IDC_ARROW);
  172. winclass.hbrBackground = (HBRUSH)GetStockObject(BLACK_BRUSH);
  173. winclass.lpszMenuName = NULL; 
  174. winclass.lpszClassName = WINDOW_CLASS_NAME;
  175. // register the window class
  176. if (!RegisterClass(&winclass))
  177. return(0);
  178. // create the window, note the test to see if WINDOWED_APP is
  179. // true to select the appropriate window flags
  180. if (!(hwnd = CreateWindow(WINDOW_CLASS_NAME, // class
  181.   WINDOW_TITLE,  // title
  182.   (WINDOWED_APP ? (WS_OVERLAPPED | WS_SYSMENU | WS_CAPTION) : (WS_POPUP | WS_VISIBLE)),
  183.     0,0,    // x,y
  184.   WINDOW_WIDTH,  // width
  185.                           WINDOW_HEIGHT, // height
  186.   NULL,    // handle to parent 
  187.   NULL,    // handle to menu
  188.   hinstance,// instance
  189.   NULL))) // creation parms
  190. return(0);
  191. // save the window handle and instance in a global
  192. main_window_handle = hwnd;
  193. main_instance      = hinstance;
  194. // resize the window so that client is really width x height
  195. if (WINDOWED_APP)
  196. {
  197. // now resize the window, so the client area is the actual size requested
  198. // since there may be borders and controls if this is going to be a windowed app
  199. // if the app is not windowed then it won't matter
  200. RECT window_rect = {0,0,WINDOW_WIDTH-1,WINDOW_HEIGHT-1};
  201. // make the call to adjust window_rect
  202. AdjustWindowRectEx(&window_rect,
  203.      GetWindowStyle(main_window_handle),
  204.      GetMenu(main_window_handle) != NULL,  
  205.      GetWindowExStyle(main_window_handle));
  206. // save the global client offsets, they are needed in DDraw_Flip()
  207. window_client_x0 = -window_rect.left;
  208. window_client_y0 = -window_rect.top;
  209. // now resize the window with a call to MoveWindow()
  210. MoveWindow(main_window_handle,
  211.            0,                                    // x position
  212.            0,                                    // y position
  213.            window_rect.right - window_rect.left, // width
  214.            window_rect.bottom - window_rect.top, // height
  215.            FALSE);
  216. // show the window, so there's no garbage on first render
  217. ShowWindow(main_window_handle, SW_SHOW);
  218. } // end if windowed
  219. // perform all game console specific initialization
  220. Game_Init();
  221. // disable CTRL-ALT_DEL, ALT_TAB, comment this line out 
  222. // if it causes your system to crash
  223. SystemParametersInfo(SPI_SCREENSAVERRUNNING, TRUE, NULL, 0);
  224. // enter main event loop
  225. while(1)
  226. {
  227. if (PeekMessage(&msg,NULL,0,0,PM_REMOVE))
  228. // test if this is a quit
  229.         if (msg.message == WM_QUIT)
  230.            break;
  231. // translate any accelerator keys
  232. TranslateMessage(&msg);
  233. // send the message to the window proc
  234. DispatchMessage(&msg);
  235. } // end if
  236.     
  237.     // main game processing goes here
  238.     Game_Main();
  239. } // end while
  240. // shutdown game and release all resources
  241. Game_Shutdown();
  242. // enable CTRL-ALT_DEL, ALT_TAB, comment this line out 
  243. // if it causes your system to crash
  244. SystemParametersInfo(SPI_SCREENSAVERRUNNING, FALSE, NULL, 0);
  245. // return to Windows like this
  246. return(msg.wParam);
  247. } // end WinMain
  248. // T3D II GAME PROGRAMMING CONSOLE FUNCTIONS ////////////////
  249. int Game_Init(void *parms)
  250. {
  251. // this function is where you do all the initialization 
  252. // for your game
  253. int index; // looping var
  254. // start up DirectDraw (replace the parms as you desire)
  255. DDraw_Init2(WINDOW_WIDTH, WINDOW_HEIGHT, WINDOW_BPP, WINDOWED_APP,0);
  256. // initialize directinput
  257. DInput_Init();
  258. // acquire the keyboard 
  259. DInput_Init_Keyboard();
  260. // add calls to acquire other directinput devices here...
  261. // initialize directsound and directmusic
  262. DSound_Init();
  263. DMusic_Init();
  264. // hide the mouse
  265. if (!WINDOWED_APP)
  266.     ShowCursor(FALSE);
  267. // seed random number generator
  268. srand(Start_Clock()); 
  269. Open_Error_File("ERROR.TXT");
  270. // initialize math engine
  271. Build_Sin_Cos_Tables();
  272. // initialize the camera with 90 FOV, normalized coordinates
  273. Init_CAM4DV1(&cam,      // the camera object
  274.              CAM_MODEL_EULER, // the euler model
  275.              &cam_pos,  // initial camera position
  276.              &cam_dir,  // initial camera angles
  277.              &cam_target,      // no target
  278.              10.0,        // near and far clipping planes
  279.              12000.0,
  280.              120.0,      // field of view in degrees
  281.              WINDOW_WIDTH,   // size of final screen viewport
  282.              WINDOW_HEIGHT);
  283.  
  284. #if 0
  285. VECTOR4D terrain_pos = {0,0,0,0}; 
  286. Generate_Terrain_OBJECT4DV2(&obj_terrain,            // pointer to object
  287.                             TERRAIN_WIDTH,           // width in world coords on x-axis
  288.                             TERRAIN_HEIGHT,          // height (length) in world coords on z-axis
  289.                             TERRAIN_SCALE,           // vertical scale of terrain
  290.                             "checkerheight05.bmp",  // filename of height bitmap encoded in 256 colors
  291.                             "checker256256.bmp",   // filename of texture map
  292.                              RGB16Bit(255,255,255),  // color of terrain if no texture        
  293.                              &terrain_pos,           // initial position
  294.                              NULL,                   // initial rotations
  295.                              POLY4DV2_ATTR_RGB16  
  296.                              | POLY4DV2_ATTR_SHADE_MODE_CONSTANT
  297.                              // | POLY4DV2_ATTR_SHADE_MODE_FLAT 
  298.                              // | POLY4DV2_ATTR_SHADE_MODE_GOURAUD
  299.                              | POLY4DV2_ATTR_SHADE_MODE_TEXTURE);
  300. #endif
  301. // set a scaling vector
  302. VECTOR4D_INITXYZ(&vscale,TERRAIN_WIDTH,1.00,TERRAIN_HEIGHT); 
  303. // set position
  304. VECTOR4D_INITXYZ(&vpos, 0, 0, 0);
  305. Load_OBJECT4DV2_COB2(&obj_terrain, "plane01.cob",  
  306.                         &vscale, &vpos, &vrot, VERTEX_FLAGS_SWAP_YZ  | 
  307.                                                VERTEX_FLAGS_TRANSFORM_LOCAL 
  308.                                                /* VERTEX_FLAGS_TRANSFORM_LOCAL_WORLD*/,0 );
  309. // set a scaling vector
  310. VECTOR4D_INITXYZ(&vscale,60.00,60.00,60.00); 
  311. // load all the objects in
  312. for (int index_obj=0; index_obj < NUM_OBJECTS; index_obj++)
  313.     {
  314.     Load_OBJECT4DV2_COB2(&obj_array[index_obj], object_filenames[index_obj],  
  315.                         &vscale, &vpos, &vrot, VERTEX_FLAGS_SWAP_YZ  | 
  316.                                                VERTEX_FLAGS_TRANSFORM_LOCAL 
  317.                                                /* VERTEX_FLAGS_TRANSFORM_LOCAL_WORLD*/,0 );
  318.     } // end for index_obj
  319. // position the scenery objects randomly
  320. for (index = 0; index < NUM_SCENE_OBJECTS; index++)
  321.     {
  322.     // randomly position object
  323.     scene_objects[index].x = RAND_RANGE(-UNIVERSE_RADIUS, UNIVERSE_RADIUS);
  324.     scene_objects[index].y = 75; // RAND_RANGE(-(UNIVERSE_RADIUS/2), (UNIVERSE_RADIUS/2));
  325.     scene_objects[index].z = RAND_RANGE(-UNIVERSE_RADIUS, UNIVERSE_RADIUS);
  326.     // select random object, use w to store value
  327.     scene_objects[index].w = RAND_RANGE(0,NUM_OBJECTS-1);
  328.     } // end for
  329. // select random velocities
  330. for (index = 0; index < NUM_SCENE_OBJECTS; index++)
  331.     {
  332.     // randomly position object
  333.     scene_objects_vel[index].x = RAND_RANGE(-MAX_VEL, MAX_VEL);
  334.     scene_objects_vel[index].y = 0; // RAND_RANGE(-MAX_VEL, MAX_VEL);
  335.     scene_objects_vel[index].z = RAND_RANGE(-MAX_VEL, MAX_VEL);
  336.     } // end for
  337. // set up lights
  338. Reset_Lights_LIGHTV2(lights2, MAX_LIGHTS);
  339. // create some working colors
  340. white.rgba = _RGBA32BIT(255,255,255,0);
  341. gray.rgba  = _RGBA32BIT(150,150,150,0);
  342. black.rgba = _RGBA32BIT(0,0,0,0);
  343. red.rgba   = _RGBA32BIT(255,0,0,0);
  344. green.rgba = _RGBA32BIT(0,255,0,0);
  345. blue.rgba  = _RGBA32BIT(0,0,255,0);
  346. // ambient light
  347. Init_Light_LIGHTV2(lights2,               // array of lights to work with
  348.                    AMBIENT_LIGHT_INDEX,   
  349.                    LIGHTV2_STATE_ON,      // turn the light on
  350.                    LIGHTV2_ATTR_AMBIENT,  // ambient light type
  351.                    gray, black, black,    // color for ambient term only
  352.                    NULL, NULL,            // no need for pos or dir
  353.                    0,0,0,                 // no need for attenuation
  354.                    0,0,0);                // spotlight info NA
  355. VECTOR4D dlight_dir = {-1,0,-1,1}; 
  356. // directional light
  357. Init_Light_LIGHTV2(lights2,               // array of lights to work with
  358.                    INFINITE_LIGHT_INDEX,  
  359.                    LIGHTV2_STATE_ON,      // turn the light on
  360.                    LIGHTV2_ATTR_INFINITE, // infinite light type
  361.                    black, gray, black,    // color for diffuse term only
  362.                    NULL, &dlight_dir,     // need direction only
  363.                    0,0,0,                 // no need for attenuation
  364.                    0,0,0);                // spotlight info NA
  365. VECTOR4D plight_pos = {0,200,0,1};
  366. // point light
  367. Init_Light_LIGHTV2(lights2,               // array of lights to work with
  368.                    POINT_LIGHT_INDEX,
  369.                    LIGHTV2_STATE_ON,      // turn the light on
  370.                    LIGHTV2_ATTR_POINT,    // pointlight type
  371.                    black, green, black,    // color for diffuse term only
  372.                    &plight_pos, NULL,     // need pos only
  373.                    0,.002,0,              // linear attenuation only
  374.                    0,0,1);                // spotlight info NA
  375. VECTOR4D slight2_pos = {0,1000,0,1};
  376. VECTOR4D slight2_dir = {-1,0,-1,1};
  377. // spot light2
  378. Init_Light_LIGHTV2(lights2,                  // array of lights to work with
  379.                    SPOT_LIGHT2_INDEX,
  380.                    LIGHTV2_STATE_ON,         // turn the light on
  381.                    LIGHTV2_ATTR_SPOTLIGHT2,  // spot light type 2
  382.                    black, red, black,        // color for diffuse term only
  383.                    &slight2_pos, &slight2_dir, // need pos only
  384.                    0,.001,0,                 // linear attenuation only
  385.                    0,0,1);    
  386. // create lookup for lighting engine
  387. RGB_16_8_IndexedRGB_Table_Builder(DD_PIXEL_FORMAT565,  // format we want to build table for
  388.                                   palette,             // source palette
  389.                                   rgblookup);          // lookup table
  390. // create the z buffer
  391. Create_Zbuffer(&zbuffer,
  392.                WINDOW_WIDTH,
  393.                WINDOW_HEIGHT,
  394.                ZBUFFER_ATTR_32BIT);
  395. // build alpha lookup table
  396. RGB_Alpha_Table_Builder(NUM_ALPHA_LEVELS, rgb_alpha_table);
  397. // load in the background
  398. Create_BOB(&background, 0,0,800,600,1, BOB_ATTR_VISIBLE | BOB_ATTR_SINGLE_FRAME, DDSCAPS_SYSTEMMEMORY, 0, 16); 
  399. Load_Bitmap_File(&bitmap16bit, "cloud03.bmp");
  400. Load_Frame_BOB16(&background, &bitmap16bit,0,0,0,BITMAP_EXTRACT_MODE_ABS);
  401. Unload_Bitmap_File(&bitmap16bit);
  402. // return success
  403. return(1);
  404. } // end Game_Init
  405. ///////////////////////////////////////////////////////////
  406. int Game_Shutdown(void *parms)
  407. {
  408. // this function is where you shutdown your game and
  409. // release all resources that you allocated
  410. // shut everything down
  411. // release all your resources created for the game here....
  412. // now directsound
  413. DSound_Stop_All_Sounds();
  414. DSound_Delete_All_Sounds();
  415. DSound_Shutdown();
  416. // directmusic
  417. DMusic_Delete_All_MIDI();
  418. DMusic_Shutdown();
  419. // shut down directinput
  420. DInput_Release_Keyboard();
  421. // shutdown directinput
  422. DInput_Shutdown();
  423. // shutdown directdraw last
  424. DDraw_Shutdown();
  425. Close_Error_File();
  426. Delete_Zbuffer(&zbuffer);
  427. // return success
  428. return(1);
  429. } // end Game_Shutdown
  430. //////////////////////////////////////////////////////////
  431. int Game_Main(void *parms)
  432. {
  433. // this is the workhorse of your game it will be called
  434. // continuously in real-time this is like main() in C
  435. // all the calls for you game go here!
  436. static MATRIX4X4 mrot;   // general rotation matrix
  437. static float plight_ang = 0, 
  438.              slight_ang = 0; // angles for light motion
  439. static float alpha_override = 0,
  440.              alpha_inc = .25;
  441. // use these to rotate objects
  442. static float x_ang = 0, y_ang = 0, z_ang = 0;
  443. // state variables for different rendering modes and help
  444. static int wireframe_mode = 1;
  445. static int backface_mode  = 1;
  446. static int lighting_mode  = 1;
  447. static int help_mode      = 1;
  448. static int zsort_mode     = 1;
  449. static int x_clip_mode    = 1;
  450. static int y_clip_mode    = 1;
  451. static int z_clip_mode    = 1;
  452. static int z_buffer_mode  = 1;
  453. static int display_mode   = 1;
  454. static float turning      = 0;
  455. static int pass_mode      = 2;
  456. char work_string[256]; // temp string
  457. int index; // looping var
  458. // start the timing clock
  459. Start_Clock();
  460. // clear the drawing surface 
  461. //DDraw_Fill_Surface(lpddsback, 0);
  462. // draw the sky
  463. //Draw_Rectangle(0,0, WINDOW_WIDTH, WINDOW_HEIGHT, RGB16Bit(0,0,0), lpddsback);
  464. lpddsback->Blt(NULL, background.images[0], NULL, DDBLT_WAIT, NULL); 
  465. // draw the ground
  466. //Draw_Rectangle(0,WINDOW_HEIGHT*.5, WINDOW_WIDTH, WINDOW_HEIGHT, RGB16Bit(190,190,230), lpddsback);
  467. // read keyboard and other devices here
  468. DInput_Read_Keyboard();
  469. // game logic here...
  470. // modes and lights
  471. // wireframe mode
  472. if (keyboard_state[DIK_W]) 
  473.    {
  474.    // toggle wireframe mode
  475.    if (++wireframe_mode > 1)
  476.        wireframe_mode=0;
  477.    Wait_Clock(100); // wait, so keyboard doesn't bounce
  478.    } // end if
  479. // backface removal
  480. if (keyboard_state[DIK_B])
  481.    {
  482.    // toggle backface removal
  483.    backface_mode = -backface_mode;
  484.    Wait_Clock(100); // wait, so keyboard doesn't bounce
  485.    } // end if
  486. // lighting
  487. if (keyboard_state[DIK_L])
  488.    {
  489.    // toggle lighting engine completely
  490.    lighting_mode = -lighting_mode;
  491.    Wait_Clock(100); // wait, so keyboard doesn't bounce
  492.    } // end if
  493. // toggle ambient light
  494. if (keyboard_state[DIK_A])
  495.    {
  496.    // toggle ambient light
  497.    if (lights2[AMBIENT_LIGHT_INDEX].state == LIGHTV2_STATE_ON)
  498.       lights2[AMBIENT_LIGHT_INDEX].state = LIGHTV2_STATE_OFF;
  499.    else
  500.       lights2[AMBIENT_LIGHT_INDEX].state = LIGHTV2_STATE_ON;
  501.    Wait_Clock(100); // wait, so keyboard doesn't bounce
  502.    } // end if
  503. // toggle infinite light
  504. if (keyboard_state[DIK_I])
  505.    {
  506.    // toggle ambient light
  507.    if (lights2[INFINITE_LIGHT_INDEX].state == LIGHTV2_STATE_ON)
  508.       lights2[INFINITE_LIGHT_INDEX].state = LIGHTV2_STATE_OFF;
  509.    else
  510.       lights2[INFINITE_LIGHT_INDEX].state = LIGHTV2_STATE_ON;
  511.    Wait_Clock(100); // wait, so keyboard doesn't bounce
  512.    } // end if
  513. // toggle point light
  514. if (keyboard_state[DIK_P])
  515.    {
  516.    // toggle point light
  517.    if (lights2[POINT_LIGHT_INDEX].state == LIGHTV2_STATE_ON)
  518.       lights2[POINT_LIGHT_INDEX].state = LIGHTV2_STATE_OFF;
  519.    else
  520.       lights2[POINT_LIGHT_INDEX].state = LIGHTV2_STATE_ON;
  521.    Wait_Clock(100); // wait, so keyboard doesn't bounce
  522.    } // end if
  523. // toggle spot light
  524. if (keyboard_state[DIK_S])
  525.    {
  526.    // toggle spot light
  527.    if (lights2[SPOT_LIGHT2_INDEX].state == LIGHTV2_STATE_ON)
  528.       lights2[SPOT_LIGHT2_INDEX].state = LIGHTV2_STATE_OFF;
  529.    else
  530.       lights2[SPOT_LIGHT2_INDEX].state = LIGHTV2_STATE_ON;
  531.    Wait_Clock(100); // wait, so keyboard doesn't bounce
  532.    } // end if
  533. // help menu
  534. if (keyboard_state[DIK_H])
  535.    {
  536.    // toggle help menu 
  537.    help_mode = -help_mode;
  538.    Wait_Clock(100); // wait, so keyboard doesn't bounce
  539.    } // end if
  540. // reflection pass mode
  541. if (keyboard_state[DIK_N])
  542.    {
  543.    // toggle help menu 
  544.    if (++pass_mode > 2) pass_mode = 0;
  545.    Wait_Clock(100); // wait, so keyboard doesn't bounce
  546.    } // end if
  547. // z-sorting
  548. if (keyboard_state[DIK_S])
  549.    {
  550.    // toggle z sorting
  551.    zsort_mode = -zsort_mode;
  552.    Wait_Clock(100); // wait, so keyboard doesn't bounce
  553.    } // end if
  554. // forward/backward
  555. if (keyboard_state[DIK_UP])
  556.    {
  557.    // move forward
  558.    if ( (cam_speed+=1) > MAX_SPEED) cam_speed = MAX_SPEED;
  559.    } // end if
  560. else
  561. if (keyboard_state[DIK_DOWN])
  562.    {
  563.    // move backward
  564.    if ((cam_speed-=1) < -MAX_SPEED) cam_speed = -MAX_SPEED;
  565.    } // end if
  566. // rotate
  567. if (keyboard_state[DIK_RIGHT])
  568.    {
  569.    cam.dir.y+=3;
  570.    
  571.    // add a little turn to object
  572.    if ((turning+=2) > 25)
  573.       turning=25;
  574.    } // end if
  575. if (keyboard_state[DIK_LEFT])
  576.    {
  577.    cam.dir.y-=3;
  578.    // add a little turn to object
  579.    if ((turning-=2) < -25)
  580.       turning=-25;
  581.    } // end if
  582. else // center heading again
  583.    {
  584.    if (turning > 0)
  585.        turning-=1;
  586.    else
  587.    if (turning < 0)
  588.        turning+=1;
  589.    } // end else
  590. // decelerate camera
  591. if (cam_speed > (CAM_DECEL) ) cam_speed-=CAM_DECEL;
  592. else
  593. if (cam_speed < (-CAM_DECEL) ) cam_speed+=CAM_DECEL;
  594. else
  595.    cam_speed = 0;
  596. // move camera
  597. cam.pos.x += cam_speed*Fast_Sin(cam.dir.y);
  598. cam.pos.y = 200;
  599. cam.pos.z += cam_speed*Fast_Cos(cam.dir.y);
  600. // move point light source in ellipse around game world
  601. lights2[POINT_LIGHT_INDEX].pos.x = 1000*Fast_Cos(plight_ang);
  602. lights2[POINT_LIGHT_INDEX].pos.y = 100;
  603. lights2[POINT_LIGHT_INDEX].pos.z = 1000*Fast_Sin(plight_ang);
  604. if ((plight_ang+=3) > 360)
  605.     plight_ang = 0;
  606. // move spot light source in ellipse around game world
  607. lights2[SPOT_LIGHT2_INDEX].pos.x = 1000*Fast_Cos(slight_ang);
  608. lights2[SPOT_LIGHT2_INDEX].pos.y = 200;
  609. lights2[SPOT_LIGHT2_INDEX].pos.z = 1000*Fast_Sin(slight_ang);
  610. if ((slight_ang-=5) < 0)
  611.     slight_ang = 360;
  612. // update rotation angles
  613. if ((x_ang+=.2) > 360) x_ang = 0;
  614. if ((y_ang+=.4) > 360) y_ang = 0;
  615. if ((z_ang+=.8) > 360) z_ang = 0;
  616. // generate camera matrix
  617. Build_CAM4DV1_Matrix_Euler(&cam, CAM_ROT_SEQ_ZYX);
  618. // lock the back buffer
  619. DDraw_Lock_Back_Surface();
  620. // render the terrain first /////////////////////////////////
  621. if (pass_mode >= 0)
  622. {
  623. // reset the render list
  624. Reset_RENDERLIST4DV2(&rend_list);
  625. // rotate the local coords of the object
  626. MAT_IDENTITY_4X4(&mrot); 
  627. Transform_OBJECT4DV2(&obj_terrain, &mrot, TRANSFORM_LOCAL_TO_TRANS,1);
  628. // perform world transform
  629. Model_To_World_OBJECT4DV2(&obj_terrain, TRANSFORM_TRANS_ONLY);
  630. // insert the object into render list
  631. Insert_OBJECT4DV2_RENDERLIST4DV2(&rend_list, &obj_terrain,0);
  632. // remove backfaces
  633. if (backface_mode==1)
  634.    Remove_Backfaces_RENDERLIST4DV2(&rend_list, &cam);
  635. // apply world to camera transform
  636. World_To_Camera_RENDERLIST4DV2(&rend_list, &cam);
  637. // clip the polygons themselves now
  638. Clip_Polys_RENDERLIST4DV2(&rend_list, &cam, ((x_clip_mode == 1) ? CLIP_POLY_X_PLANE : 0) | 
  639.                                             ((y_clip_mode == 1) ? CLIP_POLY_Y_PLANE : 0) | 
  640.                                             ((z_clip_mode == 1) ? CLIP_POLY_Z_PLANE : 0) );
  641. // light scene all at once 
  642. if (lighting_mode==1)
  643.    {
  644.    Transform_LIGHTSV2(lights2, 4, &cam.mcam, TRANSFORM_LOCAL_TO_TRANS);
  645.    Light_RENDERLIST4DV2_World2_16(&rend_list, &cam, lights2, 4);
  646.    } // end if
  647. // sort the polygon list (hurry up!)
  648. if (zsort_mode == 1)
  649.    Sort_RENDERLIST4DV2(&rend_list,  SORT_POLYLIST_AVGZ);
  650. //   // get an identity matrix
  651. //   MAT_IDENTITY_4X4(&mrot); 
  652. //   mrot.M11 = -1;
  653.    // transform the rendering list by x-z plane reflection matrix
  654.    Transform_RENDERLIST4DV2(&rend_list, &mrot, TRANSFORM_TRANS_ONLY);  
  655. // apply camera to perspective transformation
  656. Camera_To_Perspective_RENDERLIST4DV2(&rend_list, &cam);
  657. // apply screen transform
  658. Perspective_To_Screen_RENDERLIST4DV2(&rend_list, &cam);
  659. // reset number of polys rendered
  660. debug_polys_rendered_per_frame = 0;
  661. // render the renderinglist
  662. if (wireframe_mode  == 0)
  663.    Draw_RENDERLIST4DV2_Wire16(&rend_list, back_buffer, back_lpitch);
  664. else
  665. if (wireframe_mode  == 1)
  666.    {
  667.    // initialize zbuffer to 16000 fixed point
  668.    Clear_Zbuffer(&zbuffer, (16000 << FIXP16_SHIFT));
  669.    // set up rendering context
  670.    rc.attr         = RENDER_ATTR_ZBUFFER  
  671.                      | RENDER_ATTR_ALPHA  
  672.                      //| RENDER_ATTR_MIPMAP  
  673.                      //| RENDER_ATTR_BILERP
  674.                      | RENDER_ATTR_TEXTURE_PERSPECTIVE_AFFINE;
  675.    
  676.    rc.video_buffer   = back_buffer;
  677.    rc.lpitch         = back_lpitch;
  678.    rc.mip_dist       = 3500;
  679.    rc.zbuffer        = (UCHAR *)zbuffer.zbuffer;
  680.    rc.zpitch         = WINDOW_WIDTH*4;
  681.    rc.rend_list      = &rend_list;
  682.    rc.texture_dist   = 0;
  683.    rc.alpha_override = -1;
  684.  
  685.    // render scene
  686.    Draw_RENDERLIST4DV2_RENDERCONTEXTV1_16(&rc);
  687.    } // end if
  688. } // end if
  689. //////////////////////////////////////////////////////////
  690. if (pass_mode >= 1)
  691. {
  692. // render the reflection of the objects
  693. // reset the render list
  694. Reset_RENDERLIST4DV2(&rend_list);
  695. // insert the scenery into universe
  696. for (index = 0; index < NUM_SCENE_OBJECTS; index++)
  697.     {
  698.     // select proper object first
  699.     obj_work = &obj_array[(int)scene_objects[index].w];
  700.     // reset the object (this only matters for backface and object removal)
  701.     Reset_OBJECT4DV2(obj_work);
  702.     // set position of tower
  703.     obj_work->world_pos.x = scene_objects[index].x;
  704.     obj_work->world_pos.y = scene_objects[index].y;
  705.     obj_work->world_pos.z = scene_objects[index].z;
  706.     // move objects
  707.     scene_objects[index].x+=scene_objects_vel[index].x;
  708.     scene_objects[index].y+=scene_objects_vel[index].y;
  709.     scene_objects[index].z+=scene_objects_vel[index].z;
  710.     // test for out of bounds
  711.     if (scene_objects[index].x >= UNIVERSE_RADIUS || scene_objects[index].x <= -UNIVERSE_RADIUS)
  712.        { 
  713.        scene_objects_vel[index].x=-scene_objects_vel[index].x;
  714.        scene_objects[index].x+=scene_objects_vel[index].x;
  715.        } // end if
  716.     if (scene_objects[index].y >= (UNIVERSE_RADIUS/2) || scene_objects[index].y <= -(UNIVERSE_RADIUS/2))
  717.        { 
  718.        scene_objects_vel[index].y=-scene_objects_vel[index].y;
  719.        scene_objects[index].y+=scene_objects_vel[index].y;
  720.        } // end if
  721.     if (scene_objects[index].z >= UNIVERSE_RADIUS  || scene_objects[index].z <= -UNIVERSE_RADIUS)
  722.        { 
  723.        scene_objects_vel[index].z=-scene_objects_vel[index].z;
  724.        scene_objects[index].z+=scene_objects_vel[index].z;
  725.        } // end if
  726.     // attempt to cull object   
  727.     if (!Cull_OBJECT4DV2(obj_work, &cam, CULL_OBJECT_XYZ_PLANES))
  728.        {
  729.        MAT_IDENTITY_4X4(&mrot);
  730.  
  731.        // rotate the local coords of the object
  732.        Transform_OBJECT4DV2(obj_work, &mrot, TRANSFORM_LOCAL_TO_TRANS,1);
  733.        // perform world transform
  734.        Model_To_World_OBJECT4DV2(obj_work, TRANSFORM_TRANS_ONLY);
  735.        // insert the object into render list
  736.        Insert_OBJECT4DV2_RENDERLIST4DV2(&rend_list, obj_work,0);
  737.        } // end if
  738.  
  739.     } // end for
  740. // apply world to camera transform
  741. World_To_Camera_RENDERLIST4DV2(&rend_list, &cam);
  742. // clip the polygons themselves now
  743. Clip_Polys_RENDERLIST4DV2(&rend_list, &cam, ((x_clip_mode == 1) ? CLIP_POLY_X_PLANE : 0) | 
  744.                                             ((y_clip_mode == 1) ? CLIP_POLY_Y_PLANE : 0) | 
  745.                                             ((z_clip_mode == 1) ? CLIP_POLY_Z_PLANE : 0) );
  746. // light scene all at once 
  747. if (lighting_mode==1)
  748.    {
  749.    Transform_LIGHTSV2(lights2, 4, &cam.mcam, TRANSFORM_LOCAL_TO_TRANS);
  750.    Light_RENDERLIST4DV2_World2_16(&rend_list, &cam, lights2, 4);
  751.    } // end if
  752. // sort the polygon list (hurry up!)
  753. if (zsort_mode == 1)
  754.    Sort_RENDERLIST4DV2(&rend_list,  SORT_POLYLIST_AVGZ);
  755. // get an identity matrix
  756. MAT_IDENTITY_4X4(&mrot); 
  757. mrot.M11 = -1; mrot.M31 = -450;
  758. // transform the rendering list by x-z plane reflection matrix
  759. Transform_RENDERLIST4DV2(&rend_list, &mrot, TRANSFORM_TRANS_ONLY);  
  760. // apply camera to perspective transformation
  761. Camera_To_Perspective_RENDERLIST4DV2(&rend_list, &cam);
  762. // apply screen transform
  763. Perspective_To_Screen_RENDERLIST4DV2(&rend_list, &cam);
  764. // reset number of polys rendered
  765. debug_polys_rendered_per_frame = 0;
  766. // render the renderinglist
  767. if (wireframe_mode  == 0)
  768.    Draw_RENDERLIST4DV2_Wire16(&rend_list, back_buffer, back_lpitch);
  769. else
  770. if (wireframe_mode  == 1)
  771.    {
  772.    // set up rendering context
  773.    rc.attr         = RENDER_ATTR_NOBUFFER  
  774.                      | RENDER_ATTR_ALPHA  
  775.                      //| RENDER_ATTR_MIPMAP  
  776.                      //| RENDER_ATTR_BILERP
  777.                      | RENDER_ATTR_TEXTURE_PERSPECTIVE_AFFINE;
  778.    
  779.    rc.video_buffer   = back_buffer;
  780.    rc.lpitch         = back_lpitch;
  781.    rc.mip_dist       = 3500;
  782.    rc.zbuffer        = (UCHAR *)zbuffer.zbuffer;
  783.    rc.zpitch         = WINDOW_WIDTH*4;
  784.    rc.rend_list      = &rend_list;
  785.    rc.texture_dist   = 0;
  786.    rc.alpha_override = 1;
  787.  
  788.    // render scene
  789.    Draw_RENDERLIST4DV2_RENDERCONTEXTV1_16(&rc);
  790.    } // end if
  791. } // end if
  792. //////////////////////////////////////////////////////////
  793. if (pass_mode >= 2)
  794. {
  795. // render the objects now
  796. // reset the render list
  797. Reset_RENDERLIST4DV2(&rend_list);
  798. // insert the scenery into universe
  799. for (index = 0; index < NUM_SCENE_OBJECTS; index++)
  800.     {
  801.     // select proper object first
  802.     obj_work = &obj_array[(int)scene_objects[index].w];
  803.     // reset the object (this only matters for backface and object removal)
  804.     Reset_OBJECT4DV2(obj_work);
  805.     // set position of tower
  806.     obj_work->world_pos.x = scene_objects[index].x;
  807.     obj_work->world_pos.y = scene_objects[index].y;
  808.     obj_work->world_pos.z = scene_objects[index].z;
  809.     // move objects
  810.     scene_objects[index].x+=scene_objects_vel[index].x;
  811.     scene_objects[index].y+=scene_objects_vel[index].y;
  812.     scene_objects[index].z+=scene_objects_vel[index].z;
  813.     // test for out of bounds
  814.     if (scene_objects[index].x >= UNIVERSE_RADIUS || scene_objects[index].x <= -UNIVERSE_RADIUS)
  815.        { 
  816.        scene_objects_vel[index].x=-scene_objects_vel[index].x;
  817.        scene_objects[index].x+=scene_objects_vel[index].x;
  818.        } // end if
  819.     if (scene_objects[index].y >= (UNIVERSE_RADIUS/2) || scene_objects[index].y <= -(UNIVERSE_RADIUS/2))
  820.        { 
  821.        scene_objects_vel[index].y=-scene_objects_vel[index].y;
  822.        scene_objects[index].y+=scene_objects_vel[index].y;
  823.        } // end if
  824.     if (scene_objects[index].z >= UNIVERSE_RADIUS  || scene_objects[index].z <= -UNIVERSE_RADIUS)
  825.        { 
  826.        scene_objects_vel[index].z=-scene_objects_vel[index].z;
  827.        scene_objects[index].z+=scene_objects_vel[index].z;
  828.        } // end if
  829.     // attempt to cull object   
  830.     if (!Cull_OBJECT4DV2(obj_work, &cam, CULL_OBJECT_XYZ_PLANES))
  831.        {
  832.        MAT_IDENTITY_4X4(&mrot);
  833.  
  834.        // rotate the local coords of the object
  835.        Transform_OBJECT4DV2(obj_work, &mrot, TRANSFORM_LOCAL_TO_TRANS,1);
  836.        // perform world transform
  837.        Model_To_World_OBJECT4DV2(obj_work, TRANSFORM_TRANS_ONLY);
  838.        // insert the object into render list
  839.        Insert_OBJECT4DV2_RENDERLIST4DV2(&rend_list, obj_work,0);
  840.        } // end if
  841.  
  842.     } // end for
  843. // remove backfaces
  844. if (backface_mode==1)
  845.    Remove_Backfaces_RENDERLIST4DV2(&rend_list, &cam);
  846. // apply world to camera transform
  847. World_To_Camera_RENDERLIST4DV2(&rend_list, &cam);
  848. // clip the polygons themselves now
  849. Clip_Polys_RENDERLIST4DV2(&rend_list, &cam, ((x_clip_mode == 1) ? CLIP_POLY_X_PLANE : 0) | 
  850.                                             ((y_clip_mode == 1) ? CLIP_POLY_Y_PLANE : 0) | 
  851.                                             ((z_clip_mode == 1) ? CLIP_POLY_Z_PLANE : 0) );
  852. // light scene all at once 
  853. if (lighting_mode==1)
  854.    {
  855.    Transform_LIGHTSV2(lights2, 4, &cam.mcam, TRANSFORM_LOCAL_TO_TRANS);
  856.    Light_RENDERLIST4DV2_World2_16(&rend_list, &cam, lights2, 4);
  857.    } // end if
  858. // sort the polygon list (hurry up!)
  859. if (zsort_mode == 1)
  860.    Sort_RENDERLIST4DV2(&rend_list,  SORT_POLYLIST_AVGZ);
  861. // get an identity matrix
  862. //MAT_IDENTITY_4X4(&mrot); 
  863. //mrot.M11 = -1; mrot.M31 = -400;
  864. // transform the rendering list by x-z plane reflection matrix
  865. Transform_RENDERLIST4DV2(&rend_list, &mrot, TRANSFORM_TRANS_ONLY);  
  866. // apply camera to perspective transformation
  867. Camera_To_Perspective_RENDERLIST4DV2(&rend_list, &cam);
  868. // apply screen transform
  869. Perspective_To_Screen_RENDERLIST4DV2(&rend_list, &cam);
  870. // reset number of polys rendered
  871. debug_polys_rendered_per_frame = 0;
  872. // render the renderinglist
  873. if (wireframe_mode  == 0)
  874.    Draw_RENDERLIST4DV2_Wire16(&rend_list, back_buffer, back_lpitch);
  875. else
  876. if (wireframe_mode  == 1)
  877.    {
  878.    // set up rendering context
  879.    rc.attr         = RENDER_ATTR_ZBUFFER  
  880.                      | RENDER_ATTR_ALPHA  
  881.                      //| RENDER_ATTR_MIPMAP  
  882.                      //| RENDER_ATTR_BILERP
  883.                      | RENDER_ATTR_TEXTURE_PERSPECTIVE_AFFINE;
  884.    
  885.    rc.video_buffer   = back_buffer;
  886.    rc.lpitch         = back_lpitch;
  887.    rc.mip_dist       = 3500;
  888.    rc.zbuffer        = (UCHAR *)zbuffer.zbuffer;
  889.    rc.zpitch         = WINDOW_WIDTH*4;
  890.    rc.rend_list      = &rend_list;
  891.    rc.texture_dist   = 0;
  892.    rc.alpha_override = -1;
  893.  
  894.    // render scene
  895.    Draw_RENDERLIST4DV2_RENDERCONTEXTV1_16(&rc);
  896.    } // end if
  897. } // end if
  898. // unlock the back buffer
  899. DDraw_Unlock_Back_Surface();
  900. sprintf(work_string,"Lighting [%s]: Ambient=%d, Infinite=%d, Point=%d, Spot=%d, BckFceRM [%s], Zsort [%s]", 
  901.                                                                                  ((lighting_mode == 1) ? "ON" : "OFF"),
  902.                                                                                  lights[AMBIENT_LIGHT_INDEX].state,
  903.                                                                                  lights[INFINITE_LIGHT_INDEX].state, 
  904.                                                                                  lights[POINT_LIGHT_INDEX].state,
  905.                                                                                  lights[SPOT_LIGHT2_INDEX].state,
  906.                                                                                  ((backface_mode == 1) ? "ON" : "OFF"),
  907.                                                                                  ((zsort_mode == 1) ? "ON" : "OFF"));
  908. Draw_Text_GDI(work_string, 0, WINDOW_HEIGHT-34-16, RGB(0,255,0), lpddsback);
  909. // draw instructions
  910. Draw_Text_GDI("Press ESC to exit. Press <H> for Help.", 0, 0, RGB(0,255,0), lpddsback);
  911. // should we display help
  912. int text_y = 16;
  913. if (help_mode==1)
  914.     {
  915.     // draw help menu
  916.     Draw_Text_GDI("<A>..............Toggle ambient light source.", 0, text_y+=12, RGB(255,255,255), lpddsback);
  917.     Draw_Text_GDI("<I>..............Toggle infinite light source.", 0, text_y+=12, RGB(255,255,255), lpddsback);
  918.     Draw_Text_GDI("<P>..............Toggle point light source.", 0, text_y+=12, RGB(255,255,255), lpddsback);
  919.     Draw_Text_GDI("<S>..............Toggle spot light source.", 0, text_y+=12, RGB(255,255,255), lpddsback);
  920.     Draw_Text_GDI("<N>..............Enable next rendering pass.", 0, text_y+=12, RGB(255,255,255), lpddsback);
  921.     Draw_Text_GDI("<W>..............Toggle wire frame/solid mode.", 0, text_y+=12, RGB(255,255,255), lpddsback);
  922.     Draw_Text_GDI("<B>..............Toggle backface removal.", 0, text_y+=12, RGB(255,255,255), lpddsback);
  923.     Draw_Text_GDI("<S>..............Toggle Z sorting.", 0, text_y+=12, RGB(255,255,255), lpddsback);
  924.     Draw_Text_GDI("<H>..............Toggle Help.", 0, text_y+=12, RGB(255,255,255), lpddsback);
  925.     Draw_Text_GDI("<ESC>............Exit demo.", 0, text_y+=12, RGB(255,255,255), lpddsback);
  926.     } // end help
  927. sprintf(work_string,"Polys Rendered: %d, Polys lit: %d", debug_polys_rendered_per_frame, debug_polys_lit_per_frame);
  928. Draw_Text_GDI(work_string, 0, WINDOW_HEIGHT-34-16-16, RGB(0,255,0), lpddsback);
  929. sprintf(work_string,"CAM [%5.2f, %5.2f, %5.2f]",  cam.pos.x, cam.pos.y, cam.pos.z);
  930. Draw_Text_GDI(work_string, 0, WINDOW_HEIGHT-34-16-16-16, RGB(0,255,0), lpddsback);
  931. // flip the surfaces
  932. DDraw_Flip2();
  933. // sync to 30ish fps 
  934. Wait_Clock(30);
  935. // check of user is trying to exit
  936. if (KEY_DOWN(VK_ESCAPE) || keyboard_state[DIK_ESCAPE])
  937.     {
  938.     PostMessage(main_window_handle, WM_DESTROY,0,0);
  939.     } // end if
  940. // return success
  941. return(1);
  942.  
  943. } // end Game_Main
  944. //////////////////////////////////////////////////////////