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

游戏

开发平台:

Visual C++

  1. // DEMOII9_3.CPP - 3D textured cube rotating with flat shading and lights
  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        16    // 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.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. // return success
  307. return(1);
  308. } // end Game_Init
  309. ///////////////////////////////////////////////////////////
  310. int Game_Shutdown(void *parms)
  311. {
  312. // this function is where you shutdown your game and
  313. // release all resources that you allocated
  314. // shut everything down
  315. // release all your resources created for the game here....
  316. // now directsound
  317. DSound_Stop_All_Sounds();
  318. DSound_Delete_All_Sounds();
  319. DSound_Shutdown();
  320. // directmusic
  321. DMusic_Delete_All_MIDI();
  322. DMusic_Shutdown();
  323. // shut down directinput
  324. DInput_Release_Keyboard();
  325. // shutdown directinput
  326. DInput_Shutdown();
  327. // shutdown directdraw last
  328. DDraw_Shutdown();
  329. Close_Error_File();
  330. // return success
  331. return(1);
  332. } // end Game_Shutdown
  333. //////////////////////////////////////////////////////////
  334. int Game_Main(void *parms)
  335. {
  336. // this is the workhorse of your game it will be called
  337. // continuously in real-time this is like main() in C
  338. // all the calls for you game go here!
  339. static MATRIX4X4 mrot;   // general rotation matrix
  340. // these are used to create a circling camera
  341. static float view_angle = 0; 
  342. static float camera_distance = 6000;
  343. static VECTOR4D pos = {0,0,0,0};
  344. static float tank_speed;
  345. static float turning = 0;
  346. // state variables for different rendering modes and help
  347. static int wireframe_mode = 1;
  348. static int backface_mode  = 1;
  349. static int lighting_mode  = 1;
  350. static int help_mode      = 1;
  351. static int zsort_mode     = 1;
  352. char work_string[256]; // temp string
  353. int index; // looping var
  354. // start the timing clock
  355. Start_Clock();
  356. // clear the drawing surface 
  357. DDraw_Fill_Surface(lpddsback, 0);
  358. // draw the sky
  359. //Draw_Rectangle(0,0, WINDOW_WIDTH, WINDOW_HEIGHT/2, RGB16Bit(0,35,50), lpddsback);
  360. // draw the ground
  361. //Draw_Rectangle(0,WINDOW_HEIGHT/2-1, WINDOW_WIDTH, WINDOW_HEIGHT, RGB16Bit(20,12,0), lpddsback);
  362. // read keyboard and other devices here
  363. DInput_Read_Keyboard();
  364. // game logic here...
  365. // reset the render list
  366. Reset_RENDERLIST4DV2(&rend_list);
  367. // modes and lights
  368. // wireframe mode
  369. if (keyboard_state[DIK_W])
  370.    {
  371.    // toggle wireframe mode
  372.    if (++wireframe_mode > 1)
  373.        wireframe_mode=0;
  374.    Wait_Clock(100); // wait, so keyboard doesn't bounce
  375.    } // end if
  376. // backface removal
  377. if (keyboard_state[DIK_B])
  378.    {
  379.    // toggle backface removal
  380.    backface_mode = -backface_mode;
  381.    Wait_Clock(100); // wait, so keyboard doesn't bounce
  382.    } // end if
  383. // lighting
  384. if (keyboard_state[DIK_L])
  385.    {
  386.    // toggle lighting engine completely
  387.    lighting_mode = -lighting_mode;
  388.    Wait_Clock(100); // wait, so keyboard doesn't bounce
  389.    } // end if
  390. // toggle ambient light
  391. if (keyboard_state[DIK_A])
  392.    {
  393.    // toggle ambient light
  394.    if (lights[AMBIENT_LIGHT_INDEX].state == LIGHTV1_STATE_ON)
  395.       lights[AMBIENT_LIGHT_INDEX].state = LIGHTV1_STATE_OFF;
  396.    else
  397.       lights[AMBIENT_LIGHT_INDEX].state = LIGHTV1_STATE_ON;
  398.    Wait_Clock(100); // wait, so keyboard doesn't bounce
  399.    } // end if
  400. // toggle infinite light
  401. if (keyboard_state[DIK_I])
  402.    {
  403.    // toggle ambient light
  404.    if (lights[INFINITE_LIGHT_INDEX].state == LIGHTV1_STATE_ON)
  405.       lights[INFINITE_LIGHT_INDEX].state = LIGHTV1_STATE_OFF;
  406.    else
  407.       lights[INFINITE_LIGHT_INDEX].state = LIGHTV1_STATE_ON;
  408.    Wait_Clock(100); // wait, so keyboard doesn't bounce
  409.    } // end if
  410. // toggle point light
  411. if (keyboard_state[DIK_P])
  412.    {
  413.    // toggle point light
  414.    if (lights[POINT_LIGHT_INDEX].state == LIGHTV1_STATE_ON)
  415.       lights[POINT_LIGHT_INDEX].state = LIGHTV1_STATE_OFF;
  416.    else
  417.       lights[POINT_LIGHT_INDEX].state = LIGHTV1_STATE_ON;
  418.    Wait_Clock(100); // wait, so keyboard doesn't bounce
  419.    } // end if
  420. // toggle spot light
  421. if (keyboard_state[DIK_S])
  422.    {
  423.    // toggle spot light
  424.    if (lights[SPOT_LIGHT2_INDEX].state == LIGHTV1_STATE_ON)
  425.       lights[SPOT_LIGHT2_INDEX].state = LIGHTV1_STATE_OFF;
  426.    else
  427.       lights[SPOT_LIGHT2_INDEX].state = LIGHTV1_STATE_ON;
  428.    Wait_Clock(100); // wait, so keyboard doesn't bounce
  429.    } // end if
  430. // help menu
  431. if (keyboard_state[DIK_H])
  432.    {
  433.    // toggle help menu 
  434.    help_mode = -help_mode;
  435.    Wait_Clock(100); // wait, so keyboard doesn't bounce
  436.    } // end if
  437. // z-sorting
  438. if (keyboard_state[DIK_Z])
  439.    {
  440.    // toggle z sorting
  441.    zsort_mode = -zsort_mode;
  442.    Wait_Clock(100); // wait, so keyboard doesn't bounce
  443.    } // end if
  444. static float plight_ang = 0, slight_ang = 0; // angles for light motion
  445. // move point light source in ellipse around game world
  446. lights[POINT_LIGHT_INDEX].pos.x = 1000*Fast_Cos(plight_ang);
  447. lights[POINT_LIGHT_INDEX].pos.y = 100;
  448. lights[POINT_LIGHT_INDEX].pos.z = 1000*Fast_Sin(plight_ang);
  449. if ((plight_ang+=3) > 360)
  450.     plight_ang = 0;
  451. // move spot light source in ellipse around game world
  452. lights[SPOT_LIGHT2_INDEX].pos.x = 1000*Fast_Cos(slight_ang);
  453. lights[SPOT_LIGHT2_INDEX].pos.y = 200;
  454. lights[SPOT_LIGHT2_INDEX].pos.z = 1000*Fast_Sin(slight_ang);
  455. if ((slight_ang-=5) < 0)
  456.     slight_ang = 360;
  457. // generate camera matrix
  458. Build_CAM4DV1_Matrix_Euler(&cam, CAM_ROT_SEQ_ZYX);
  459. // use these to rotate objects
  460. static float x_ang = 0, y_ang = 0, z_ang = 0;
  461. //////////////////////////////////////////////////////////////////////////
  462. // flat shaded textured cube
  463. // reset the object (this only matters for backface and object removal)
  464. Reset_OBJECT4DV2(&obj_flat_cube);
  465. // set position of constant shaded cube
  466. obj_flat_cube.world_pos.x = 0;
  467. obj_flat_cube.world_pos.y = 0;
  468. obj_flat_cube.world_pos.z = 150;
  469. // generate rotation matrix around y axis
  470. Build_XYZ_Rotation_MATRIX4X4(x_ang, y_ang, z_ang, &mrot);
  471. // rotate the local coords of the object
  472. Transform_OBJECT4DV2(&obj_flat_cube, &mrot, TRANSFORM_LOCAL_TO_TRANS,1);
  473. // perform world transform
  474. Model_To_World_OBJECT4DV2(&obj_flat_cube, TRANSFORM_TRANS_ONLY);
  475. // insert the object into render list
  476. Insert_OBJECT4DV2_RENDERLIST4DV2(&rend_list, &obj_flat_cube,0);
  477. // update rotation angles
  478. if ((x_ang+=1) > 360) x_ang = 0;
  479. if ((y_ang+=2) > 360) y_ang = 0;
  480. if ((z_ang+=3) > 360) z_ang = 0;
  481. // remove backfaces
  482. if (backface_mode==1)
  483.    Remove_Backfaces_RENDERLIST4DV2(&rend_list, &cam);
  484. // light scene all at once 
  485. if (lighting_mode==1)
  486.    Light_RENDERLIST4DV2_World16(&rend_list, &cam, lights, 4);
  487. // apply world to camera transform
  488. World_To_Camera_RENDERLIST4DV2(&rend_list, &cam);
  489. // sort the polygon list (hurry up!)
  490. if (zsort_mode == 1)
  491.    Sort_RENDERLIST4DV2(&rend_list,  SORT_POLYLIST_AVGZ);
  492. // apply camera to perspective transformation
  493. Camera_To_Perspective_RENDERLIST4DV2(&rend_list, &cam);
  494. // apply screen transform
  495. Perspective_To_Screen_RENDERLIST4DV2(&rend_list, &cam);
  496. sprintf(work_string,"Lighting [%s]: Ambient=%d, Infinite=%d, Point=%d, Spot=%d | Zsort [%s], BckFceRM [%s]", 
  497.                                                                                  ((lighting_mode == 1) ? "ON" : "OFF"),
  498.                                                                                  lights[AMBIENT_LIGHT_INDEX].state,
  499.                                                                                  lights[INFINITE_LIGHT_INDEX].state, 
  500.                                                                                  lights[POINT_LIGHT_INDEX].state,
  501.                                                                                  lights[SPOT_LIGHT2_INDEX].state,
  502.                                                                                  ((zsort_mode == 1) ? "ON" : "OFF"),
  503.                                                                                  ((backface_mode == 1) ? "ON" : "OFF"));
  504. Draw_Text_GDI(work_string, 0, WINDOW_HEIGHT-34, RGB(0,255,0), lpddsback);
  505. // draw instructions
  506. Draw_Text_GDI("Press ESC to exit. Press <H> for Help.", 0, 0, RGB(0,255,0), lpddsback);
  507. // should we display help
  508. int text_y = 16;
  509. if (help_mode==1)
  510.     {
  511.     // draw help menu
  512.     Draw_Text_GDI("<A>..............Toggle ambient light source.", 0, text_y+=12, RGB(255,255,255), lpddsback);
  513.     Draw_Text_GDI("<I>..............Toggle infinite light source.", 0, text_y+=12, RGB(255,255,255), lpddsback);
  514.     Draw_Text_GDI("<P>..............Toggle point light source.", 0, text_y+=12, RGB(255,255,255), lpddsback);
  515.     Draw_Text_GDI("<S>..............Toggle spot light source.", 0, text_y+=12, RGB(255,255,255), lpddsback);
  516.     Draw_Text_GDI("<W>..............Toggle wire frame/solid mode.", 0, text_y+=12, RGB(255,255,255), lpddsback);
  517.     Draw_Text_GDI("<B>..............Toggle backface removal.", 0, text_y+=12, RGB(255,255,255), lpddsback);
  518.     Draw_Text_GDI("<H>..............Toggle Help.", 0, text_y+=12, RGB(255,255,255), lpddsback);
  519.     Draw_Text_GDI("<ESC>............Exit demo.", 0, text_y+=12, RGB(255,255,255), lpddsback);
  520.     } // end help
  521. // lock the back buffer
  522. DDraw_Lock_Back_Surface();
  523. // reset number of polys rendered
  524. debug_polys_rendered_per_frame = 0;
  525. // render the object
  526. if (wireframe_mode  == 0)
  527.    Draw_RENDERLIST4DV2_Wire16(&rend_list, back_buffer, back_lpitch);
  528. else
  529. if (wireframe_mode  == 1)
  530.    Draw_RENDERLIST4DV2_Solid16(&rend_list, back_buffer, back_lpitch);
  531. // unlock the back buffer
  532. DDraw_Unlock_Back_Surface();
  533. // flip the surfaces
  534. DDraw_Flip();
  535. // sync to 30ish fps
  536. Wait_Clock(30);
  537. // check of user is trying to exit
  538. if (KEY_DOWN(VK_ESCAPE) || keyboard_state[DIK_ESCAPE])
  539.     {
  540.     PostMessage(main_window_handle, WM_DESTROY,0,0);
  541.     } // end if
  542. // return success
  543. return(1);
  544.  
  545. } // end Game_Main
  546. //////////////////////////////////////////////////////////