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

游戏

开发平台:

Visual C++

  1. // DEMOII9_3_8b.CPP - 3D textured cube rotating with flat shading and lights, 8-bit version
  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-7.CPP and the headers T3DLIB1-7.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. // DEFINES ////////////////////////////////////////////////
  42. // defines for windows interface
  43. #define WINDOW_CLASS_NAME "WIN3DCLASS"  // class name
  44. #define WINDOW_TITLE      "T3D Graphics Console Ver 2.0"
  45. #define WINDOW_WIDTH      800  // size of window
  46. #define WINDOW_HEIGHT     600
  47. #define WINDOW_BPP        8    // bitdepth of window (8,16,24 etc.)
  48.                                 // note: if windowed and not
  49.                                 // fullscreen then bitdepth must
  50.                                 // be same as system bitdepth
  51.                                 // also if 8-bit the a pallete
  52.                                 // is created and attached
  53.    
  54. #define WINDOWED_APP      0 // 0 not windowed, 1 windowed 
  55. // create some constants for ease of access
  56. #define AMBIENT_LIGHT_INDEX   0 // ambient light index
  57. #define INFINITE_LIGHT_INDEX  1 // infinite light index
  58. #define POINT_LIGHT_INDEX     2 // point light index
  59. #define SPOT_LIGHT1_INDEX     4 // point light index
  60. #define SPOT_LIGHT2_INDEX     3 // spot light index
  61. // PROTOTYPES /////////////////////////////////////////////
  62. // game console
  63. int Game_Init(void *parms=NULL); 
  64. int Game_Shutdown(void *parms=NULL);
  65. int Game_Main(void *parms=NULL);
  66. // GLOBALS ////////////////////////////////////////////////
  67. HWND main_window_handle           = NULL; // save the window handle
  68. HINSTANCE main_instance           = NULL; // save the instance
  69. char buffer[2048];                        // used to print text
  70. // initialize camera position and direction
  71. POINT4D  cam_pos    = {0,0,0,1};
  72. POINT4D  cam_target = {0,0,0,1};
  73. VECTOR4D cam_dir    = {0,0,0,1};
  74. // all your initialization code goes here...
  75. VECTOR4D vscale={1.0,1.0,1.0,1}, 
  76.          vpos = {0,0,0,1}, 
  77.          vrot = {0,0,0,1};
  78. CAM4DV1        cam;       // the single camera
  79. OBJECT4DV2     obj_flat_cube;
  80.                
  81. RENDERLIST4DV2 rend_list; // the render list
  82. RGBAV1 white, gray, black, red, green, blue;
  83. // FUNCTIONS //////////////////////////////////////////////
  84. LRESULT CALLBACK WindowProc(HWND hwnd, 
  85.     UINT msg, 
  86.                             WPARAM wparam, 
  87.                             LPARAM lparam)
  88. {
  89. // this is the main message handler of the system
  90. PAINTSTRUCT ps;    // used in WM_PAINT
  91. HDC hdc;    // handle to a device context
  92. // what is the message 
  93. switch(msg)
  94. {
  95. case WM_CREATE: 
  96.         {
  97. // do initialization stuff here
  98. return(0);
  99. } break;
  100.     case WM_PAINT:
  101.          {
  102.          // start painting
  103.          hdc = BeginPaint(hwnd,&ps);
  104.          // end painting
  105.          EndPaint(hwnd,&ps);
  106.          return(0);
  107.         } break;
  108. case WM_DESTROY: 
  109. {
  110. // kill the application
  111. PostQuitMessage(0);
  112. return(0);
  113. } break;
  114. default:break;
  115.     } // end switch
  116. // process any messages that we didn't take care of 
  117. return (DefWindowProc(hwnd, msg, wparam, lparam));
  118. } // end WinProc
  119. // WINMAIN ////////////////////////////////////////////////
  120. int WINAPI WinMain( HINSTANCE hinstance,
  121. HINSTANCE hprevinstance,
  122. LPSTR lpcmdline,
  123. int ncmdshow)
  124. {
  125. // this is the winmain function
  126. WNDCLASS winclass; // this will hold the class we create
  127. HWND  hwnd; // generic window handle
  128. MSG  msg; // generic message
  129. HDC      hdc;       // generic dc
  130. PAINTSTRUCT ps;     // generic paintstruct
  131. // first fill in the window class stucture
  132. winclass.style = CS_DBLCLKS | CS_OWNDC | 
  133.                           CS_HREDRAW | CS_VREDRAW;
  134. winclass.lpfnWndProc = WindowProc;
  135. winclass.cbClsExtra = 0;
  136. winclass.cbWndExtra = 0;
  137. winclass.hInstance = hinstance;
  138. winclass.hIcon = LoadIcon(NULL, IDI_APPLICATION);
  139. winclass.hCursor = LoadCursor(NULL, IDC_ARROW);
  140. winclass.hbrBackground = (HBRUSH)GetStockObject(BLACK_BRUSH);
  141. winclass.lpszMenuName = NULL; 
  142. winclass.lpszClassName = WINDOW_CLASS_NAME;
  143. // register the window class
  144. if (!RegisterClass(&winclass))
  145. return(0);
  146. // create the window, note the test to see if WINDOWED_APP is
  147. // true to select the appropriate window flags
  148. if (!(hwnd = CreateWindow(WINDOW_CLASS_NAME, // class
  149.   WINDOW_TITLE,  // title
  150.   (WINDOWED_APP ? (WS_OVERLAPPED | WS_SYSMENU | WS_CAPTION) : (WS_POPUP | WS_VISIBLE)),
  151.     0,0,    // x,y
  152.   WINDOW_WIDTH,  // width
  153.                           WINDOW_HEIGHT, // height
  154.   NULL,    // handle to parent 
  155.   NULL,    // handle to menu
  156.   hinstance,// instance
  157.   NULL))) // creation parms
  158. return(0);
  159. // save the window handle and instance in a global
  160. main_window_handle = hwnd;
  161. main_instance      = hinstance;
  162. // resize the window so that client is really width x height
  163. if (WINDOWED_APP)
  164. {
  165. // now resize the window, so the client area is the actual size requested
  166. // since there may be borders and controls if this is going to be a windowed app
  167. // if the app is not windowed then it won't matter
  168. RECT window_rect = {0,0,WINDOW_WIDTH-1,WINDOW_HEIGHT-1};
  169. // make the call to adjust window_rect
  170. AdjustWindowRectEx(&window_rect,
  171.      GetWindowStyle(main_window_handle),
  172.      GetMenu(main_window_handle) != NULL,  
  173.      GetWindowExStyle(main_window_handle));
  174. // save the global client offsets, they are needed in DDraw_Flip()
  175. window_client_x0 = -window_rect.left;
  176. window_client_y0 = -window_rect.top;
  177. // now resize the window with a call to MoveWindow()
  178. MoveWindow(main_window_handle,
  179.            0, // x position
  180.            0, // y position
  181.            window_rect.right - window_rect.left, // width
  182.            window_rect.bottom - window_rect.top, // height
  183.            FALSE);
  184. // show the window, so there's no garbage on first render
  185. ShowWindow(main_window_handle, SW_SHOW);
  186. } // end if windowed
  187. // perform all game console specific initialization
  188. Game_Init();
  189. // disable CTRL-ALT_DEL, ALT_TAB, comment this line out 
  190. // if it causes your system to crash
  191. SystemParametersInfo(SPI_SCREENSAVERRUNNING, TRUE, NULL, 0);
  192. // enter main event loop
  193. while(1)
  194. {
  195. if (PeekMessage(&msg,NULL,0,0,PM_REMOVE))
  196. // test if this is a quit
  197.         if (msg.message == WM_QUIT)
  198.            break;
  199. // translate any accelerator keys
  200. TranslateMessage(&msg);
  201. // send the message to the window proc
  202. DispatchMessage(&msg);
  203. } // end if
  204.     
  205.     // main game processing goes here
  206.     Game_Main();
  207. } // end while
  208. // shutdown game and release all resources
  209. Game_Shutdown();
  210. // enable CTRL-ALT_DEL, ALT_TAB, comment this line out 
  211. // if it causes your system to crash
  212. SystemParametersInfo(SPI_SCREENSAVERRUNNING, FALSE, NULL, 0);
  213. // return to Windows like this
  214. return(msg.wParam);
  215. } // end WinMain
  216. // T3D II GAME PROGRAMMING CONSOLE FUNCTIONS ////////////////
  217. int Game_Init(void *parms)
  218. {
  219. // this function is where you do all the initialization 
  220. // for your game
  221. int index; // looping var
  222. // start up DirectDraw (replace the parms as you desire)
  223. DDraw_Init(WINDOW_WIDTH, WINDOW_HEIGHT, WINDOW_BPP, WINDOWED_APP);
  224. // initialize directinput
  225. DInput_Init();
  226. // acquire the keyboard 
  227. DInput_Init_Keyboard();
  228. // add calls to acquire other directinput devices here...
  229. // initialize directsound and directmusic
  230. DSound_Init();
  231. DMusic_Init();
  232. // hide the mouse
  233. if (!WINDOWED_APP)
  234.     ShowCursor(FALSE);
  235. // seed random number generator
  236. srand(Start_Clock());
  237. Open_Error_File("ERROR.TXT");
  238. // initialize math engine
  239. Build_Sin_Cos_Tables();
  240. // initialize the camera with 90 FOV, normalized coordinates
  241. Init_CAM4DV1(&cam,      // the camera object
  242.              CAM_MODEL_EULER, // the euler model
  243.              &cam_pos,  // initial camera position
  244.              &cam_dir,  // initial camera angles
  245.              &cam_target,      // no target
  246.              200.0,      // near and far clipping planes
  247.              12000.0,
  248.              120.0,      // field of view in degrees
  249.              WINDOW_WIDTH,   // size of final screen viewport
  250.              WINDOW_HEIGHT);
  251. // load flat shaded cube
  252. VECTOR4D_INITXYZ(&vscale,20.00,20.00,20.00);
  253. Load_OBJECT4DV2_COB(&obj_flat_cube,"cube_flat_textured_01_256.cob",  
  254.                         &vscale, &vpos, &vrot, VERTEX_FLAGS_SWAP_YZ | 
  255.                                                VERTEX_FLAGS_TRANSFORM_LOCAL | 
  256.                                                VERTEX_FLAGS_TRANSFORM_LOCAL_WORLD );
  257. // set up lights
  258. Reset_Lights_LIGHTV1();
  259. // create some working colors
  260. white.rgba = _RGBA32BIT(255,255,255,0);
  261. gray.rgba  = _RGBA32BIT(100,100,100,0);
  262. black.rgba = _RGBA32BIT(0,0,0,0);
  263. red.rgba   = _RGBA32BIT(255,0,0,0);
  264. green.rgba = _RGBA32BIT(0,255,0,0);
  265. blue.rgba  = _RGBA32BIT(0,0,255,0);
  266. // ambient light
  267. Init_Light_LIGHTV1(AMBIENT_LIGHT_INDEX,   
  268.                    LIGHTV1_STATE_ON,      // turn the light on
  269.                    LIGHTV1_ATTR_AMBIENT,  // ambient light type
  270.                    gray, black, black,    // color for ambient term only
  271.                    NULL, NULL,            // no need for pos or dir
  272.                    0,0,0,                 // no need for attenuation
  273.                    0,0,0);                // spotlight info NA
  274. VECTOR4D dlight_dir = {-1,0,-1,0};
  275. // directional light
  276. Init_Light_LIGHTV1(INFINITE_LIGHT_INDEX,  
  277.                    LIGHTV1_STATE_ON,      // turn the light on
  278.                    LIGHTV1_ATTR_INFINITE, // infinite light type
  279.                    black, gray, black,    // color for diffuse term only
  280.                    NULL, &dlight_dir,     // need direction only
  281.                    0,0,0,                 // no need for attenuation
  282.                    0,0,0);                // spotlight info NA
  283. VECTOR4D plight_pos = {0,200,0,0};
  284. // point light
  285. Init_Light_LIGHTV1(POINT_LIGHT_INDEX,
  286.                    LIGHTV1_STATE_ON,      // turn the light on
  287.                    LIGHTV1_ATTR_POINT,    // pointlight type
  288.                    black, green, black,   // color for diffuse term only
  289.                    &plight_pos, NULL,     // need pos only
  290.                    0,.001,0,              // linear attenuation only
  291.                    0,0,1);                // spotlight info NA
  292. VECTOR4D slight2_pos = {0,200,0,0};
  293. VECTOR4D slight2_dir = {-1,0,-1,0};
  294. // spot light2
  295. Init_Light_LIGHTV1(SPOT_LIGHT2_INDEX,
  296.                    LIGHTV1_STATE_ON,         // turn the light on
  297.                    LIGHTV1_ATTR_SPOTLIGHT2,  // spot light type 2
  298.                    black, red, black,      // color for diffuse term only
  299.                    &slight2_pos, &slight2_dir, // need pos only
  300.                    0,.001,0,                 // linear attenuation only
  301.                    0,0,1);    
  302. // create lookup for lighting engine
  303. RGB_16_8_IndexedRGB_Table_Builder(DD_PIXEL_FORMAT565,  // format we want to build table for
  304.                                   palette,             // source palette
  305.                                   rgblookup);          // lookup table
  306. // THIS IS ABSOLUTELY A MUST WHEN USING FLAT SHADED TEXTURES!!!!
  307. // YOU NEED THIS TABLE!!!!
  308. // create 4.4.4 to 8 bit index color lookup for texture mapping
  309. RGB_12_8_Lighting_Table_Builder(palette,         // source palette
  310.                                 rgblightlookup);  // lookup table
  311. // return success
  312. return(1);
  313. } // end Game_Init
  314. ///////////////////////////////////////////////////////////
  315. int Game_Shutdown(void *parms)
  316. {
  317. // this function is where you shutdown your game and
  318. // release all resources that you allocated
  319. // shut everything down
  320. // release all your resources created for the game here....
  321. // now directsound
  322. DSound_Stop_All_Sounds();
  323. DSound_Delete_All_Sounds();
  324. DSound_Shutdown();
  325. // directmusic
  326. DMusic_Delete_All_MIDI();
  327. DMusic_Shutdown();
  328. // shut down directinput
  329. DInput_Release_Keyboard();
  330. // shutdown directinput
  331. DInput_Shutdown();
  332. // shutdown directdraw last
  333. DDraw_Shutdown();
  334. Close_Error_File();
  335. // return success
  336. return(1);
  337. } // end Game_Shutdown
  338. //////////////////////////////////////////////////////////
  339. int Game_Main(void *parms)
  340. {
  341. // this is the workhorse of your game it will be called
  342. // continuously in real-time this is like main() in C
  343. // all the calls for you game go here!
  344. static MATRIX4X4 mrot;   // general rotation matrix
  345. // these are used to create a circling camera
  346. static float view_angle = 0; 
  347. static float camera_distance = 6000;
  348. static VECTOR4D pos = {0,0,0,0};
  349. static float tank_speed;
  350. static float turning = 0;
  351. // state variables for different rendering modes and help
  352. static int wireframe_mode = 1;
  353. static int backface_mode  = 1;
  354. static int lighting_mode  = 1;
  355. static int help_mode      = 1;
  356. static int zsort_mode     = 1;
  357. char work_string[256]; // temp string
  358. int index; // looping var
  359. // start the timing clock
  360. Start_Clock();
  361. // clear the drawing surface 
  362. DDraw_Fill_Surface(lpddsback, 0);
  363. // draw the sky
  364. //Draw_Rectangle(0,0, WINDOW_WIDTH, WINDOW_HEIGHT/2, RGB16Bit(0,35,50), lpddsback);
  365. // draw the ground
  366. //Draw_Rectangle(0,WINDOW_HEIGHT/2-1, WINDOW_WIDTH, WINDOW_HEIGHT, RGB16Bit(20,12,0), lpddsback);
  367. // read keyboard and other devices here
  368. DInput_Read_Keyboard();
  369. // game logic here...
  370. // reset the render list
  371. Reset_RENDERLIST4DV2(&rend_list);
  372. // modes and lights
  373. // wireframe mode
  374. if (keyboard_state[DIK_W])
  375.    {
  376.    // toggle wireframe mode
  377.    if (++wireframe_mode > 1)
  378.        wireframe_mode=0;
  379.    Wait_Clock(100); // wait, so keyboard doesn't bounce
  380.    } // end if
  381. // backface removal
  382. if (keyboard_state[DIK_B])
  383.    {
  384.    // toggle backface removal
  385.    backface_mode = -backface_mode;
  386.    Wait_Clock(100); // wait, so keyboard doesn't bounce
  387.    } // end if
  388. // lighting
  389. if (keyboard_state[DIK_L])
  390.    {
  391.    // toggle lighting engine completely
  392.    lighting_mode = -lighting_mode;
  393.    Wait_Clock(100); // wait, so keyboard doesn't bounce
  394.    } // end if
  395. // toggle ambient light
  396. if (keyboard_state[DIK_A])
  397.    {
  398.    // toggle ambient light
  399.    if (lights[AMBIENT_LIGHT_INDEX].state == LIGHTV1_STATE_ON)
  400.       lights[AMBIENT_LIGHT_INDEX].state = LIGHTV1_STATE_OFF;
  401.    else
  402.       lights[AMBIENT_LIGHT_INDEX].state = LIGHTV1_STATE_ON;
  403.    Wait_Clock(100); // wait, so keyboard doesn't bounce
  404.    } // end if
  405. // toggle infinite light
  406. if (keyboard_state[DIK_I])
  407.    {
  408.    // toggle ambient light
  409.    if (lights[INFINITE_LIGHT_INDEX].state == LIGHTV1_STATE_ON)
  410.       lights[INFINITE_LIGHT_INDEX].state = LIGHTV1_STATE_OFF;
  411.    else
  412.       lights[INFINITE_LIGHT_INDEX].state = LIGHTV1_STATE_ON;
  413.    Wait_Clock(100); // wait, so keyboard doesn't bounce
  414.    } // end if
  415. // toggle point light
  416. if (keyboard_state[DIK_P])
  417.    {
  418.    // toggle point light
  419.    if (lights[POINT_LIGHT_INDEX].state == LIGHTV1_STATE_ON)
  420.       lights[POINT_LIGHT_INDEX].state = LIGHTV1_STATE_OFF;
  421.    else
  422.       lights[POINT_LIGHT_INDEX].state = LIGHTV1_STATE_ON;
  423.    Wait_Clock(100); // wait, so keyboard doesn't bounce
  424.    } // end if
  425. // toggle spot light
  426. if (keyboard_state[DIK_S])
  427.    {
  428.    // toggle spot light
  429.    if (lights[SPOT_LIGHT2_INDEX].state == LIGHTV1_STATE_ON)
  430.       lights[SPOT_LIGHT2_INDEX].state = LIGHTV1_STATE_OFF;
  431.    else
  432.       lights[SPOT_LIGHT2_INDEX].state = LIGHTV1_STATE_ON;
  433.    Wait_Clock(100); // wait, so keyboard doesn't bounce
  434.    } // end if
  435. // help menu
  436. if (keyboard_state[DIK_H])
  437.    {
  438.    // toggle help menu 
  439.    help_mode = -help_mode;
  440.    Wait_Clock(100); // wait, so keyboard doesn't bounce
  441.    } // end if
  442. // z-sorting
  443. if (keyboard_state[DIK_Z])
  444.    {
  445.    // toggle z sorting
  446.    zsort_mode = -zsort_mode;
  447.    Wait_Clock(100); // wait, so keyboard doesn't bounce
  448.    } // end if
  449. static float plight_ang = 0, slight_ang = 0; // angles for light motion
  450. // move point light source in ellipse around game world
  451. lights[POINT_LIGHT_INDEX].pos.x = 1000*Fast_Cos(plight_ang);
  452. lights[POINT_LIGHT_INDEX].pos.y = 100;
  453. lights[POINT_LIGHT_INDEX].pos.z = 1000*Fast_Sin(plight_ang);
  454. if ((plight_ang+=3) > 360)
  455.     plight_ang = 0;
  456. // move spot light source in ellipse around game world
  457. lights[SPOT_LIGHT2_INDEX].pos.x = 1000*Fast_Cos(slight_ang);
  458. lights[SPOT_LIGHT2_INDEX].pos.y = 200;
  459. lights[SPOT_LIGHT2_INDEX].pos.z = 1000*Fast_Sin(slight_ang);
  460. if ((slight_ang-=5) < 0)
  461.     slight_ang = 360;
  462. // generate camera matrix
  463. Build_CAM4DV1_Matrix_Euler(&cam, CAM_ROT_SEQ_ZYX);
  464. // use these to rotate objects
  465. static float x_ang = 0, y_ang = 0, z_ang = 0;
  466. //////////////////////////////////////////////////////////////////////////
  467. // flat shaded textured cube
  468. // reset the object (this only matters for backface and object removal)
  469. Reset_OBJECT4DV2(&obj_flat_cube);
  470. // set position of constant shaded cube
  471. obj_flat_cube.world_pos.x = 0;
  472. obj_flat_cube.world_pos.y = 0;
  473. obj_flat_cube.world_pos.z = 150;
  474. // generate rotation matrix around y axis
  475. Build_XYZ_Rotation_MATRIX4X4(x_ang, y_ang, z_ang, &mrot);
  476. // rotate the local coords of the object
  477. Transform_OBJECT4DV2(&obj_flat_cube, &mrot, TRANSFORM_LOCAL_TO_TRANS,1);
  478. // perform world transform
  479. Model_To_World_OBJECT4DV2(&obj_flat_cube, TRANSFORM_TRANS_ONLY);
  480. // insert the object into render list
  481. Insert_OBJECT4DV2_RENDERLIST4DV2(&rend_list, &obj_flat_cube,0);
  482. // update rotation angles
  483. if ((x_ang+=1) > 360) x_ang = 0;
  484. if ((y_ang+=2) > 360) y_ang = 0;
  485. if ((z_ang+=3) > 360) z_ang = 0;
  486. // remove backfaces
  487. if (backface_mode==1)
  488.    Remove_Backfaces_RENDERLIST4DV2(&rend_list, &cam);
  489. // light scene all at once 
  490. if (lighting_mode==1)
  491.    Light_RENDERLIST4DV2_World(&rend_list, &cam, lights, 4);
  492. // apply world to camera transform
  493. World_To_Camera_RENDERLIST4DV2(&rend_list, &cam);
  494. // sort the polygon list (hurry up!)
  495. if (zsort_mode == 1)
  496.    Sort_RENDERLIST4DV2(&rend_list,  SORT_POLYLIST_AVGZ);
  497. // apply camera to perspective transformation
  498. Camera_To_Perspective_RENDERLIST4DV2(&rend_list, &cam);
  499. // apply screen transform
  500. Perspective_To_Screen_RENDERLIST4DV2(&rend_list, &cam);
  501. sprintf(work_string,"Lighting [%s]: Ambient=%d, Infinite=%d, Point=%d, Spot=%d | Zsort [%s], BckFceRM [%s]", 
  502.                                                                                  ((lighting_mode == 1) ? "ON" : "OFF"),
  503.                                                                                  lights[AMBIENT_LIGHT_INDEX].state,
  504.                                                                                  lights[INFINITE_LIGHT_INDEX].state, 
  505.                                                                                  lights[POINT_LIGHT_INDEX].state,
  506.                                                                                  lights[SPOT_LIGHT2_INDEX].state,
  507.                                                                                  ((zsort_mode == 1) ? "ON" : "OFF"),
  508.                                                                                  ((backface_mode == 1) ? "ON" : "OFF"));
  509. Draw_Text_GDI(work_string, 0, WINDOW_HEIGHT-34, RGB(0,255,0), lpddsback);
  510. // draw instructions
  511. Draw_Text_GDI("Press ESC to exit. Press <H> for Help.", 0, 0, RGB(0,255,0), lpddsback);
  512. // should we display help
  513. int text_y = 16;
  514. if (help_mode==1)
  515.     {
  516.     // draw help menu
  517.     Draw_Text_GDI("<A>..............Toggle ambient light source.", 0, text_y+=12, RGB(255,255,255), lpddsback);
  518.     Draw_Text_GDI("<I>..............Toggle infinite light source.", 0, text_y+=12, RGB(255,255,255), lpddsback);
  519.     Draw_Text_GDI("<P>..............Toggle point light source.", 0, text_y+=12, RGB(255,255,255), lpddsback);
  520.     Draw_Text_GDI("<S>..............Toggle spot light source.", 0, text_y+=12, RGB(255,255,255), lpddsback);
  521.     Draw_Text_GDI("<W>..............Toggle wire frame/solid mode.", 0, text_y+=12, RGB(255,255,255), lpddsback);
  522.     Draw_Text_GDI("<B>..............Toggle backface removal.", 0, text_y+=12, RGB(255,255,255), lpddsback);
  523.     Draw_Text_GDI("<H>..............Toggle Help.", 0, text_y+=12, RGB(255,255,255), lpddsback);
  524.     Draw_Text_GDI("<ESC>............Exit demo.", 0, text_y+=12, RGB(255,255,255), lpddsback);
  525.     } // end help
  526. // lock the back buffer
  527. DDraw_Lock_Back_Surface();
  528. // reset number of polys rendered
  529. debug_polys_rendered_per_frame = 0;
  530. // render the object
  531. if (wireframe_mode  == 0)
  532.    Draw_RENDERLIST4DV2_Wire(&rend_list, back_buffer, back_lpitch);
  533. else
  534. if (wireframe_mode  == 1)
  535.    Draw_RENDERLIST4DV2_Solid(&rend_list, back_buffer, back_lpitch);
  536. // unlock the back buffer
  537. DDraw_Unlock_Back_Surface();
  538. // flip the surfaces
  539. DDraw_Flip();
  540. // sync to 30ish fps
  541. Wait_Clock(30);
  542. // check of user is trying to exit
  543. if (KEY_DOWN(VK_ESCAPE) || keyboard_state[DIK_ESCAPE])
  544.     {
  545.     PostMessage(main_window_handle, WM_DESTROY,0,0);
  546.     } // end if
  547. // return success
  548. return(1);
  549.  
  550. } // end Game_Main
  551. //////////////////////////////////////////////////////////