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

游戏

开发平台:

Visual C++

  1. // DEMOII14_1.CPP - simple shadow 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-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,-300,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_02.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 alpha shadow texture
  364. VECTOR4D_INITXYZ(&vscale, 80, 80, 80); 
  365. Load_OBJECT4DV2_COB2(&shadow_obj,"shadow_poly_01.cob",  
  366.                     &vscale, &vpos, &vrot, VERTEX_FLAGS_INVERT_WINDING_ORDER | VERTEX_FLAGS_SWAP_YZ 
  367.                                           | VERTEX_FLAGS_TRANSFORM_LOCAL 
  368.                                           | VERTEX_FLAGS_TRANSFORM_LOCAL_WORLD
  369.                                           ,0 );
  370. // set up lights
  371. Reset_Lights_LIGHTV2(lights2, MAX_LIGHTS);
  372. // create some working colors
  373. white.rgba = _RGBA32BIT(255,255,255,0);
  374. gray.rgba  = _RGBA32BIT(100,100,100,0);
  375. black.rgba = _RGBA32BIT(0,0,0,0);
  376. red.rgba   = _RGBA32BIT(255,0,0,0);
  377. green.rgba = _RGBA32BIT(0,255,0,0);
  378. blue.rgba  = _RGBA32BIT(0,0,255,0);
  379. orange.rgba = _RGBA32BIT(255,128,0,0);
  380. yellow.rgba  = _RGBA32BIT(255,255,0,0);
  381. // ambient light
  382. Init_Light_LIGHTV2(lights2,
  383.                    AMBIENT_LIGHT_INDEX,   
  384.                    LIGHTV2_STATE_ON,      // turn the light on
  385.                    LIGHTV2_ATTR_AMBIENT,  // ambient light type
  386.                    gray, black, black,    // color for ambient term only
  387.                    NULL, NULL,            // no need for pos or dir
  388.                    0,0,0,                 // no need for attenuation
  389.                    0,0,0);                // spotlight info NA
  390. VECTOR4D dlight_dir = {-1,1,-1,1};
  391. // directional light
  392. Init_Light_LIGHTV2(lights2,
  393.                    INFINITE_LIGHT_INDEX,  
  394.                    LIGHTV2_STATE_ON,      // turn the light on
  395.                    LIGHTV2_ATTR_INFINITE, // infinite light type
  396.                    black, gray, black,    // color for diffuse term only
  397.                    NULL, &dlight_dir,     // need direction only
  398.                    0,0,0,                 // no need for attenuation
  399.                    0,0,0);                // spotlight info NA
  400. VECTOR4D plight_pos = {0,200,0,1};
  401. // point light
  402. Init_Light_LIGHTV2(lights2,
  403.                    POINT_LIGHT_INDEX,
  404.                    LIGHTV2_STATE_ON,      // turn the light on
  405.                    LIGHTV2_ATTR_POINT,    // pointlight type
  406.                    black, green, black,   // color for diffuse term only
  407.                    &plight_pos, NULL,     // need pos only
  408.                    0,.001,0,              // linear attenuation only
  409.                    0,0,1);                // spotlight info NA
  410. // point light
  411. Init_Light_LIGHTV2(lights2,
  412.                    POINT_LIGHT2_INDEX,
  413.                    LIGHTV2_STATE_ON,     // turn the light on
  414.                    LIGHTV2_ATTR_POINT,   // pointlight type
  415.                    black, white, black,  // color for diffuse term only
  416.                    &plight_pos, NULL,    // need pos only
  417.                    0,.002,0,             // linear attenuation only
  418.                    0,0,1);               // spotlight info NA
  419. VECTOR4D slight2_pos = {0,200,0,1};
  420. VECTOR4D slight2_dir = {-1,1,-1,1};
  421. // create lookup for lighting engine
  422. RGB_16_8_IndexedRGB_Table_Builder(DD_PIXEL_FORMAT565,  // format we want to build table for
  423.                                   palette,             // source palette
  424.                                   rgblookup);          // lookup table
  425. // create the z buffer
  426. Create_Zbuffer(&zbuffer,
  427.                WINDOW_WIDTH,
  428.                WINDOW_HEIGHT,
  429.                ZBUFFER_ATTR_32BIT);
  430.  
  431. // build alpha lookup table
  432. RGB_Alpha_Table_Builder(NUM_ALPHA_LEVELS, rgb_alpha_table);
  433. // load background sounds
  434. wind_sound_id = DSound_Load_WAV("STATIONTHROB.WAV");
  435. // start the sounds
  436. DSound_Play(wind_sound_id, DSBPLAY_LOOPING);
  437. DSound_Set_Volume(wind_sound_id, 100);
  438. #if 0
  439. // load in the cockpit image
  440. Load_Bitmap_File(&bitmap16bit, "lego01.BMP");
  441. Create_BOB(&cockpit, 0,0,800,600,1, BOB_ATTR_VISIBLE | BOB_ATTR_SINGLE_FRAME, DDSCAPS_SYSTEMMEMORY, 0, 16); 
  442. Load_Frame_BOB16(&cockpit, &bitmap16bit,0,0,0,BITMAP_EXTRACT_MODE_ABS);
  443. Unload_Bitmap_File(&bitmap16bit);
  444. #endif
  445. // set single precission
  446. //_control87( _PC_24, MCW_PC );
  447. // return success
  448. return(1);
  449. } // end Game_Init
  450. ///////////////////////////////////////////////////////////
  451. int Game_Shutdown(void *parms)
  452. {
  453. // this function is where you shutdown your game and
  454. // release all resources that you allocated
  455. // shut everything down
  456. // release all your resources created for the game here....
  457. // now directsound
  458. DSound_Stop_All_Sounds();
  459. DSound_Delete_All_Sounds();
  460. DSound_Shutdown();
  461. // directmusic
  462. DMusic_Delete_All_MIDI();
  463. DMusic_Shutdown();
  464. // shut down directinput
  465. DInput_Release_Keyboard();
  466. // shutdown directinput
  467. DInput_Shutdown();
  468. // shutdown directdraw last
  469. DDraw_Shutdown();
  470. Close_Error_File();
  471. // return success
  472. return(1);
  473. } // end Game_Shutdown
  474. //////////////////////////////////////////////////////////
  475. int Game_Main(void *parms)
  476. {
  477. // this is the workhorse of your game it will be called
  478. // continuously in real-time this is like main() in C
  479. // all the calls for you game go here!
  480. static MATRIX4X4 mrot;   // general rotation matrix
  481. static float plight_ang = 0, 
  482.              slight_ang = 0; // angles for light motion
  483. // use these to rotate objects
  484. static float x_ang = 0, y_ang = 0, z_ang = 0;
  485. // state variables for different rendering modes and help
  486. static int wireframe_mode   = 1;
  487. static int backface_mode    = 1;
  488. static int lighting_mode    = 1;
  489. static int help_mode        = 1;
  490. static int zsort_mode       = 1;
  491. static int x_clip_mode      = 1;
  492. static int y_clip_mode      = 1;
  493. static int z_clip_mode      = 1;
  494. char work_string[256]; // temp string
  495. int index; // looping var
  496. // start the timing clock
  497. Start_Clock();
  498. // clear the drawing surface 
  499. DDraw_Fill_Surface(lpddsback, 0);
  500. // draw the sky
  501. Draw_Rectangle(0,0, WINDOW_WIDTH, WINDOW_HEIGHT, RGB16Bit(255,120,255), lpddsback);
  502. // draw the ground
  503. //Draw_Rectangle(0,WINDOW_HEIGHT*.38, WINDOW_WIDTH, WINDOW_HEIGHT, RGB16Bit(25,50,110), lpddsback);
  504. // read keyboard and other devices here
  505. DInput_Read_Keyboard();
  506. // game logic here...
  507. // reset the render list
  508. Reset_RENDERLIST4DV2(&rend_list);
  509. // modes and lights
  510. // wireframe mode
  511. if (keyboard_state[DIK_W]) 
  512.    {
  513.    // toggle wireframe mode
  514.    if (++wireframe_mode > 1)
  515.        wireframe_mode=0;
  516.    Wait_Clock(100); // wait, so keyboard doesn't bounce
  517.    } // end if
  518. // backface removal
  519. if (keyboard_state[DIK_B])
  520.    {
  521.    // toggle backface removal
  522.    backface_mode = -backface_mode;
  523.    Wait_Clock(100); // wait, so keyboard doesn't bounce
  524.    } // end if
  525. // lighting
  526. if (keyboard_state[DIK_L])
  527.    {
  528.    // toggle lighting engine completely
  529.    lighting_mode = -lighting_mode;
  530.    Wait_Clock(100); // wait, so keyboard doesn't bounce
  531.    } // end if
  532. // toggle ambient light
  533. if (keyboard_state[DIK_A])
  534.    {
  535.    // toggle ambient light
  536.    if (lights2[AMBIENT_LIGHT_INDEX].state == LIGHTV2_STATE_ON)
  537.       lights2[AMBIENT_LIGHT_INDEX].state = LIGHTV2_STATE_OFF;
  538.    else
  539.       lights2[AMBIENT_LIGHT_INDEX].state = LIGHTV2_STATE_ON;
  540.    Wait_Clock(100); // wait, so keyboard doesn't bounce
  541.    } // end if
  542. // toggle infinite light
  543. if (keyboard_state[DIK_I])
  544.    {
  545.    // toggle ambient light
  546.    if (lights2[INFINITE_LIGHT_INDEX].state == LIGHTV2_STATE_ON)
  547.       lights2[INFINITE_LIGHT_INDEX].state = LIGHTV2_STATE_OFF;
  548.    else
  549.       lights2[INFINITE_LIGHT_INDEX].state = LIGHTV2_STATE_ON;
  550.    Wait_Clock(100); // wait, so keyboard doesn't bounce
  551.    } // end if
  552. // toggle point light
  553. if (keyboard_state[DIK_P])
  554.    {
  555.    // toggle point light
  556.    if (lights2[POINT_LIGHT_INDEX].state == LIGHTV2_STATE_ON)
  557.       lights2[POINT_LIGHT_INDEX].state = LIGHTV2_STATE_OFF;
  558.    else
  559.       lights2[POINT_LIGHT_INDEX].state = LIGHTV2_STATE_ON;
  560.    // toggle point light
  561.    if (lights2[POINT_LIGHT2_INDEX].state == LIGHTV2_STATE_ON)
  562.       lights2[POINT_LIGHT2_INDEX].state = LIGHTV2_STATE_OFF;
  563.    else
  564.       lights2[POINT_LIGHT2_INDEX].state = LIGHTV2_STATE_ON;
  565.    Wait_Clock(100); // wait, so keyboard doesn't bounce
  566.    } // end if
  567. // help menu
  568. if (keyboard_state[DIK_H])
  569.    {
  570.    // toggle help menu 
  571.    help_mode = -help_mode;
  572.    Wait_Clock(100); // wait, so keyboard doesn't bounce
  573.    } // end if
  574. // z-sorting
  575. if (keyboard_state[DIK_Z])
  576.    {
  577.    // toggle z sorting
  578.    zsort_mode = -zsort_mode;
  579.    Wait_Clock(100); // wait, so keyboard doesn't bounce
  580.    } // end if
  581. // move to next object
  582. if (keyboard_state[DIK_O])
  583.    {
  584.    VECTOR4D old_pos;
  585.    old_pos = obj_work->world_pos;
  586.    if (++curr_object >= NUM_OBJECTS)
  587.       curr_object = 0;
  588.    // update pointer
  589.    obj_work = &obj_array[curr_object];
  590.    obj_work->world_pos = old_pos;
  591.    Wait_Clock(100); // wait, so keyboard doesn't bounce
  592.    } // end if
  593. // forward/backward
  594. if (keyboard_state[DIK_UP])
  595.    {
  596.    // move forward
  597.    if ( (cam_speed+=1) > MAX_SPEED) cam_speed = MAX_SPEED;
  598.    } // end if
  599. else
  600. if (keyboard_state[DIK_DOWN])
  601.    {
  602.    // move backward
  603.    if ((cam_speed-=1) < -MAX_SPEED) cam_speed = -MAX_SPEED;
  604.    } // end if
  605. // rotate around y axis or yaw
  606. if (keyboard_state[DIK_RIGHT])
  607.    {
  608.    cam.dir.y+=5;
  609.    } // end if
  610. if (keyboard_state[DIK_LEFT])
  611.    {
  612.    cam.dir.y-=5;
  613.    } // end if
  614. // motion section /////////////////////////////////////////////////////////
  615. // terrain following, simply find the current cell we are over and then
  616. // index into the vertex list and find the 4 vertices that make up the 
  617. // quad cell we are hovering over and then average the values, and based
  618. // on the current height and the height of the terrain push the player upward
  619. // the terrain generates and stores some results to help with terrain following
  620. //ivar1 = columns;
  621. //ivar2 = rows;
  622. //fvar1 = col_vstep;
  623. //fvar2 = row_vstep;
  624. int cell_x = (cam.pos.x  + TERRAIN_WIDTH/2) / obj_terrain.fvar1;
  625. int cell_y = (cam.pos.z  + TERRAIN_HEIGHT/2) / obj_terrain.fvar1;
  626. static float terrain_height, delta;
  627. // test if we are on terrain
  628. if ( (cell_x >=0) && (cell_x < obj_terrain.ivar1) && (cell_y >=0) && (cell_y < obj_terrain.ivar2) )
  629.    {
  630.    // compute vertex indices into vertex list of the current quad
  631.    int v0 = cell_x + cell_y*obj_terrain.ivar2;
  632.    int v1 = v0 + 1;
  633.    int v2 = v1 + obj_terrain.ivar2;
  634.    int v3 = v0 + obj_terrain.ivar2;   
  635.    // now simply index into table 
  636.    terrain_height = 0.25 * (obj_terrain.vlist_trans[v0].y + obj_terrain.vlist_trans[v1].y +
  637.                             obj_terrain.vlist_trans[v2].y + obj_terrain.vlist_trans[v3].y);
  638.    // compute height difference
  639.    delta = terrain_height - (cam.pos.y - gclearance);
  640.    // test for penetration
  641.    if (delta > 0)
  642.       {
  643.       // apply force immediately to camera (this will give it a springy feel)
  644.       vel_y+=(delta * (VELOCITY_SCALER));
  645.       // test for pentration, if so move up immediately so we don't penetrate geometry
  646.       cam.pos.y+=(delta*CAM_HEIGHT_SCALER);
  647.       // now this is more of a hack than the physics model :) let move the front
  648.       // up and down a bit based on the forward velocity and the gradient of the 
  649.       // hill
  650.       cam.dir.x -= (delta*PITCH_CHANGE_RATE);
  651.  
  652.       } // end if
  653.    } // end if
  654. // decelerate camera
  655. if (cam_speed > (CAM_DECEL) ) cam_speed-=CAM_DECEL;
  656. else
  657. if (cam_speed < (-CAM_DECEL) ) cam_speed+=CAM_DECEL;
  658. else
  659.    cam_speed = 0;
  660. // force camera to seek a stable orientation
  661. if (cam.dir.x > (neutral_pitch+PITCH_RETURN_RATE)) cam.dir.x -= (PITCH_RETURN_RATE);
  662. else
  663. if (cam.dir.x < (neutral_pitch-PITCH_RETURN_RATE)) cam.dir.x += (PITCH_RETURN_RATE);
  664.  else 
  665.    cam.dir.x = neutral_pitch;
  666. // apply gravity
  667. vel_y+=gravity;
  668. // test for absolute sea level and push upward..
  669. if (cam.pos.y < sea_level)
  670.    { 
  671.    vel_y = 0; 
  672.    cam.pos.y = sea_level;
  673.    } // end if
  674. // move camera
  675. cam.pos.x += cam_speed*Fast_Sin(cam.dir.y);
  676. cam.pos.z += cam_speed*Fast_Cos(cam.dir.y);
  677. cam.pos.y += vel_y;
  678. // move point light source in ellipse around game world
  679. lights2[POINT_LIGHT_INDEX].pos.x = 1000*Fast_Cos(plight_ang);
  680. lights2[POINT_LIGHT_INDEX].pos.y = 200;
  681. lights2[POINT_LIGHT_INDEX].pos.z = 1000*Fast_Sin(plight_ang);
  682. // move point light source in ellipse around game world
  683. lights2[POINT_LIGHT2_INDEX].pos.x = 500*Fast_Cos(-2*plight_ang);
  684. lights2[POINT_LIGHT2_INDEX].pos.y = 400;
  685. lights2[POINT_LIGHT2_INDEX].pos.z = 1000*Fast_Sin(-2*plight_ang);
  686. if ((plight_ang+=3) > 360)
  687.     plight_ang = 0;
  688. // generate camera matrix
  689. Build_CAM4DV1_Matrix_Euler(&cam, CAM_ROT_SEQ_ZYX);
  690. //////////////////////////////////////////////////////////////////////////
  691. // the terrain
  692. // reset the object (this only matters for backface and object removal)
  693. Reset_OBJECT4DV2(&obj_terrain);
  694. // generate rotation matrix around y axis
  695. //Build_XYZ_Rotation_MATRIX4X4(x_ang, y_ang, z_ang, &mrot);
  696. MAT_IDENTITY_4X4(&mrot); 
  697. // rotate the local coords of the object
  698. Transform_OBJECT4DV2(&obj_terrain, &mrot, TRANSFORM_LOCAL_TO_TRANS,1);
  699. // perform world transform
  700. Model_To_World_OBJECT4DV2(&obj_terrain, TRANSFORM_TRANS_ONLY);
  701. // insert the object into render list
  702. Insert_OBJECT4DV2_RENDERLIST4DV2(&rend_list, &obj_terrain,0);
  703. //////////////////////////////////////////////////////////////////////////
  704. //////////////////////////////////////////////////////////////////////////
  705. // render the shaded object that projects the shadow
  706. // reset the object (this only matters for backface and object removal)
  707. Reset_OBJECT4DV2(obj_work);
  708. // update rotation angle of object
  709. obj_work->ivar1+=3.0;
  710. if (obj_work->ivar1 >= 360)
  711.     obj_work->ivar1 = 0;
  712. // set position of object 
  713. obj_work->world_pos.x = 200*Fast_Cos(obj_work->ivar1);
  714. obj_work->world_pos.y = 200+50*Fast_Sin(3*obj_work->ivar1);
  715. obj_work->world_pos.z = 200*Fast_Sin(obj_work->ivar1);
  716. // generate rotation matrix around y axis
  717. Build_XYZ_Rotation_MATRIX4X4(x_ang, y_ang, z_ang, &mrot);
  718. // rotate the local coords of the object
  719. Transform_OBJECT4DV2(obj_work, &mrot, TRANSFORM_LOCAL_TO_TRANS,1);
  720. // perform world transform
  721. Model_To_World_OBJECT4DV2(obj_work, TRANSFORM_TRANS_ONLY);
  722. // insert the object into render list
  723. Insert_OBJECT4DV2_RENDERLIST4DV2(&rend_list, obj_work,0);
  724. //////////////////////////////////////////////////////////////////////////
  725. //////////////////////////////////////////////////////////////////////////
  726. // draw all the light objects to represent the position of light sources
  727. // reset the object (this only matters for backface and object removal)
  728. Reset_OBJECT4DV2(&obj_light_array[INDEX_GREEN_LIGHT_INDEX]);
  729. // set position of object to light
  730. obj_light_array[INDEX_GREEN_LIGHT_INDEX].world_pos = lights2[POINT_LIGHT_INDEX].pos;
  731. // create identity matrix
  732. MAT_IDENTITY_4X4(&mrot);
  733. // rotate the local coords of the object
  734. Transform_OBJECT4DV2(&obj_light_array[INDEX_GREEN_LIGHT_INDEX], &mrot, TRANSFORM_LOCAL_TO_TRANS,1);
  735. // perform world transform
  736. Model_To_World_OBJECT4DV2(&obj_light_array[INDEX_GREEN_LIGHT_INDEX], TRANSFORM_TRANS_ONLY);
  737. // insert the object into render list
  738. Insert_OBJECT4DV2_RENDERLIST4DV2(&rend_list, &obj_light_array[INDEX_GREEN_LIGHT_INDEX],0);
  739. // reset the object (this only matters for backface and object removal)
  740. Reset_OBJECT4DV2(&obj_light_array[INDEX_WHITE_LIGHT_INDEX]);
  741. // set position of object to light
  742. obj_light_array[INDEX_WHITE_LIGHT_INDEX].world_pos = lights2[POINT_LIGHT2_INDEX].pos;
  743. // create identity matrix
  744. MAT_IDENTITY_4X4(&mrot);
  745. // rotate the local coords of the object
  746. Transform_OBJECT4DV2(&obj_light_array[INDEX_WHITE_LIGHT_INDEX], &mrot, TRANSFORM_LOCAL_TO_TRANS,1);
  747.  
  748. // perform world transform
  749. Model_To_World_OBJECT4DV2(&obj_light_array[INDEX_WHITE_LIGHT_INDEX], TRANSFORM_TRANS_ONLY);
  750. // insert the object into render list
  751. Insert_OBJECT4DV2_RENDERLIST4DV2(&rend_list, &obj_light_array[INDEX_WHITE_LIGHT_INDEX],0);
  752. ////////////////////////////////////////////////////////////////////////////////////
  753. // reset number of polys rendered
  754. debug_polys_rendered_per_frame = 0;
  755. debug_polys_lit_per_frame = 0;
  756. // prepare to make first pass at rendering target, so we can alpha blend in the shadows
  757. // on the next pass
  758. // remove backfaces
  759. if (backface_mode==1)
  760.    Remove_Backfaces_RENDERLIST4DV2(&rend_list, &cam);
  761. // apply world to camera transform
  762. World_To_Camera_RENDERLIST4DV2(&rend_list, &cam);
  763. // clip the polygons themselves now
  764. Clip_Polys_RENDERLIST4DV2(&rend_list, &cam, CLIP_POLY_X_PLANE | CLIP_POLY_Y_PLANE | CLIP_POLY_Z_PLANE );
  765. // light scene all at once 
  766. if (lighting_mode==1)
  767.    {
  768.    Transform_LIGHTSV2(lights2, 4, &cam.mcam, TRANSFORM_LOCAL_TO_TRANS);
  769.    Light_RENDERLIST4DV2_World2_16(&rend_list, &cam, lights2, 4);
  770.    } // end if
  771. // sort the polygon list (hurry up!)
  772. if (zsort_mode == 1)
  773.    Sort_RENDERLIST4DV2(&rend_list,  SORT_POLYLIST_AVGZ);
  774. // apply camera to perspective transformation
  775. Camera_To_Perspective_RENDERLIST4DV2(&rend_list, &cam);
  776. // apply screen transform
  777. Perspective_To_Screen_RENDERLIST4DV2(&rend_list, &cam);
  778. // lock the back buffer
  779. DDraw_Lock_Back_Surface();
  780. // reset number of polys rendered
  781. debug_polys_rendered_per_frame = 0;
  782. // render the object
  783. if (wireframe_mode  == 0)
  784.    Draw_RENDERLIST4DV2_Wire16(&rend_list, back_buffer, back_lpitch);
  785. else
  786. if (wireframe_mode  == 1)
  787.    {
  788.    // perspective mode affine texturing
  789.       // set up rendering context
  790.       rc.attr =    RENDER_ATTR_ZBUFFER  
  791.               // | RENDER_ATTR_ALPHA  
  792.               // | RENDER_ATTR_MIPMAP  
  793.               // | RENDER_ATTR_BILERP
  794.                  | RENDER_ATTR_TEXTURE_PERSPECTIVE_AFFINE;
  795.    // initialize zbuffer to 0 fixed point
  796.    Clear_Zbuffer(&zbuffer, (16000 << FIXP16_SHIFT));
  797.    // set up remainder of rendering context
  798.    rc.video_buffer   = back_buffer;
  799.    rc.lpitch         = back_lpitch;
  800.    rc.mip_dist       = 0;
  801.    rc.zbuffer        = (UCHAR *)zbuffer.zbuffer;
  802.    rc.zpitch         = WINDOW_WIDTH*4;
  803.    rc.rend_list      = &rend_list;
  804.    rc.texture_dist   = 0;
  805.    rc.alpha_override = -1;
  806.    // render scene
  807.    Draw_RENDERLIST4DV2_RENDERCONTEXTV1_16_2(&rc);
  808.    } // end if
  809. // now make second rendering pass and draw shadow(s)
  810. // reset the render list
  811. Reset_RENDERLIST4DV2(&rend_list);
  812. //////////////////////////////////////////////////////////////////////////
  813. // shadow object
  814. // reset the object (this only matters for backface and object removal)
  815. Reset_OBJECT4DV2(&shadow_obj);
  816. // compute terrain cell shadow is over
  817. cell_x = (obj_work->world_pos.x  + TERRAIN_WIDTH/2) / obj_terrain.fvar1;
  818. cell_y = (obj_work->world_pos.z  + TERRAIN_HEIGHT/2) / obj_terrain.fvar1;
  819. // compute vertex indices into vertex list of the current quad
  820. int v0 = cell_x + cell_y*obj_terrain.ivar2;
  821. int v1 = v0 + 1;
  822. int v2 = v1 + obj_terrain.ivar2; 
  823. int v3 = v0 + obj_terrain.ivar2;   
  824. // now simply index into table 
  825. terrain_height = MAX(    MAX(obj_terrain.vlist_trans[v0].y, obj_terrain.vlist_trans[v1].y), 
  826.                          MAX(obj_terrain.vlist_trans[v2].y, obj_terrain.vlist_trans[v3].y) );
  827. // update position
  828. shadow_obj.world_pos   = obj_work->world_pos;
  829. shadow_obj.world_pos.y = terrain_height+10;
  830. // create identity matrix
  831. MAT_IDENTITY_4X4(&mrot);
  832. // transform the local coords of the object
  833. Transform_OBJECT4DV2(&shadow_obj, &mrot, TRANSFORM_LOCAL_TO_TRANS,1);
  834. // perform world transform
  835. Model_To_World_OBJECT4DV2(&shadow_obj, TRANSFORM_TRANS_ONLY);
  836. // insert the object into render list
  837. Insert_OBJECT4DV2_RENDERLIST4DV2(&rend_list, &shadow_obj,0);
  838. //////////////////////////////////////////////////////////////////////////
  839. // remove backfaces
  840. if (backface_mode==1)
  841.    Remove_Backfaces_RENDERLIST4DV2(&rend_list, &cam);
  842. // apply world to camera transform
  843. World_To_Camera_RENDERLIST4DV2(&rend_list, &cam);
  844. // clip the polygons themselves now
  845. Clip_Polys_RENDERLIST4DV2(&rend_list, &cam, CLIP_POLY_X_PLANE | CLIP_POLY_Y_PLANE | CLIP_POLY_Z_PLANE );
  846. // light scene all at once 
  847. if (lighting_mode==1)
  848.    {
  849.    Transform_LIGHTSV2(lights2, 4, &cam.mcam, TRANSFORM_LOCAL_TO_TRANS);
  850.    Light_RENDERLIST4DV2_World2_16(&rend_list, &cam, lights2, 4);
  851.    } // end if
  852. // sort the polygon list (hurry up!)
  853. if (zsort_mode == 1)
  854.    Sort_RENDERLIST4DV2(&rend_list,  SORT_POLYLIST_AVGZ);
  855. // apply camera to perspective transformation
  856. Camera_To_Perspective_RENDERLIST4DV2(&rend_list, &cam);
  857. // apply screen transform
  858. Perspective_To_Screen_RENDERLIST4DV2(&rend_list, &cam);
  859. // render the object
  860. if (wireframe_mode  == 0)
  861.    Draw_RENDERLIST4DV2_Wire16(&rend_list, back_buffer, back_lpitch);
  862. else
  863. if (wireframe_mode  == 1)
  864.    {
  865.    // perspective mode affine texturing
  866.       // set up rendering context
  867.       rc.attr =    RENDER_ATTR_ZBUFFER  
  868.                  | RENDER_ATTR_ALPHA  
  869.               // | RENDER_ATTR_MIPMAP  
  870.               // | RENDER_ATTR_BILERP
  871.                  | RENDER_ATTR_TEXTURE_PERSPECTIVE_AFFINE;
  872.    // initialize zbuffer to 0 fixed point
  873.    //Clear_Zbuffer(&zbuffer, (16000 << FIXP16_SHIFT));
  874.    // set up remainder of rendering context
  875.    rc.video_buffer   = back_buffer;
  876.    rc.lpitch         = back_lpitch;
  877.    rc.mip_dist       = 0;
  878.    rc.zbuffer        = (UCHAR *)zbuffer.zbuffer;
  879.    rc.zpitch         = WINDOW_WIDTH*4;
  880.    rc.rend_list      = &rend_list;
  881.    rc.texture_dist   = 0;
  882.    rc.alpha_override = -1;
  883.    // render scene
  884.    Draw_RENDERLIST4DV2_RENDERCONTEXTV1_16_3(&rc);
  885.    } // end if
  886. // unlock the back buffer
  887. DDraw_Unlock_Back_Surface();
  888. // draw cockpit
  889. //Draw_BOB16(&cockpit, lpddsback);
  890. #if 1
  891. sprintf(work_string,"Lighting [%s]: Ambient=%d, Infinite=%d, Point=%d, BckFceRM [%s]", 
  892.                                                                                  ((lighting_mode == 1) ? "ON" : "OFF"),
  893.                                                                                  lights2[AMBIENT_LIGHT_INDEX].state,
  894.                                                                                  lights2[INFINITE_LIGHT_INDEX].state, 
  895.                                                                                  lights2[POINT_LIGHT_INDEX].state,
  896.                                                                                  ((backface_mode == 1) ? "ON" : "OFF"));
  897. Draw_Text_GDI(work_string, 0, WINDOW_HEIGHT-34, RGB(0,255,0), lpddsback);
  898. // draw instructions
  899. Draw_Text_GDI("Press ESC to exit. Press <H> for Help.", 0, 0, RGB(0,255,0), lpddsback);
  900. // should we display help
  901. int text_y = 16;
  902. if (help_mode==1)
  903.     {
  904.     // draw help menu
  905.     Draw_Text_GDI("<A>..............Toggle ambient light source.", 0, text_y+=12, RGB(255,255,255), lpddsback);
  906.     Draw_Text_GDI("<I>..............Toggle infinite light source.", 0, text_y+=12, RGB(255,255,255), lpddsback);
  907.     Draw_Text_GDI("<P>..............Toggle point light source.", 0, text_y+=12, RGB(255,255,255), lpddsback);
  908.     Draw_Text_GDI("<W>..............Toggle wire frame/solid mode.", 0, text_y+=12, RGB(255,255,255), lpddsback);
  909.     Draw_Text_GDI("<B>..............Toggle backface removal.", 0, text_y+=12, RGB(255,255,255), lpddsback);
  910.     Draw_Text_GDI("<O>..............Select different objects.", 0, text_y+=12, RGB(255,255,255), lpddsback);
  911.     Draw_Text_GDI("<H>..............Toggle Help.", 0, text_y+=12, RGB(255,255,255), lpddsback);
  912.     Draw_Text_GDI("<ESC>............Exit demo.", 0, text_y+=12, RGB(255,255,255), lpddsback);
  913.     } // end help
  914. sprintf(work_string,"Polys Rendered: %d, Polys lit: %d", debug_polys_rendered_per_frame, debug_polys_lit_per_frame);
  915. Draw_Text_GDI(work_string, 0, WINDOW_HEIGHT-34-16-16, RGB(0,255,0), lpddsback);
  916. 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);
  917. Draw_Text_GDI(work_string, 0, WINDOW_HEIGHT-34-16-16-16, RGB(0,255,0), lpddsback);
  918. #endif
  919. // flip the surfaces
  920. DDraw_Flip2();
  921. // sync to 30ish fps
  922. Wait_Clock(30);
  923. // check of user is trying to exit
  924. if (KEY_DOWN(VK_ESCAPE) || keyboard_state[DIK_ESCAPE])
  925.     {
  926.     PostMessage(main_window_handle, WM_DESTROY,0,0);
  927.     } // end if
  928. // return success
  929. return(1);
  930.  
  931. } // end Game_Main
  932. //////////////////////////////////////////////////////////