home *** CD-ROM | disk | FTP | other *** search
/ 3D Games - Real-time Rend…ng & Software Technology / 3D Games - Real-time Rendering & Software Technology.iso / flysdk / frontend / flyfe / flyfe.cpp next >
Encoding:
C/C++ Source or Header  |  2001-03-01  |  2.6 KB  |  120 lines

  1. #include <windows.h>
  2. #include "..\..\lib\Fly3D.h"
  3.  
  4. char szTitle[100]="MyGame Title";
  5. char szWindowClass[100]="MyGame";
  6.  
  7. LRESULT CALLBACK WinFunc (HWND, UINT, WPARAM, LPARAM);
  8. void LoadLevel (HWND, HINSTANCE);
  9.  
  10. int WINAPI WinMain (HINSTANCE hInst, HINSTANCE hPrev, LPSTR lp, int nCmd)
  11. {
  12.     WNDCLASS wcl;
  13.     MSG  msg;
  14.  
  15.     // register window class
  16.     wcl.style            = CS_HREDRAW | CS_VREDRAW;
  17.     wcl.lpfnWndProc        = (WNDPROC)WinFunc;
  18.     wcl.cbClsExtra        = 0;
  19.     wcl.cbWndExtra        = 0;
  20.     wcl.hInstance        = hInst;
  21.     wcl.hIcon            = LoadIcon(NULL, IDI_WINLOGO);
  22.     wcl.hCursor            = 0;
  23.     wcl.hbrBackground    = (HBRUSH)(COLOR_WINDOW+1);
  24.     wcl.lpszMenuName    = NULL;
  25.     wcl.lpszClassName    = szWindowClass;
  26.     if (!RegisterClass (&wcl))
  27.     {
  28.       MessageBox (0, "Can't register Window", "ERROR", MB_OK);
  29.       return 0;
  30.     }
  31.  
  32.     // cerate main window
  33.     HWND hWndMain = CreateWindowEx(
  34.                             0,
  35.                             szWindowClass,
  36.                             szTitle,
  37.                             WS_POPUP,
  38.                             0, 0,
  39.                             GetSystemMetrics( SM_CXSCREEN ),
  40.                             GetSystemMetrics( SM_CYSCREEN ),
  41.                             NULL,
  42.                             NULL,
  43.                             hInst,
  44.                             NULL 
  45.                           );
  46.  
  47.     // load the level
  48.     ShowWindow (hWndMain, SW_MAXIMIZE);
  49.     LoadLevel (hWndMain, hInst);
  50.  
  51.     // main loop
  52.     while (1) 
  53.     {
  54.         while (PeekMessage(&msg, NULL, 0, 0, PM_NOREMOVE) == TRUE) 
  55.         {
  56.             if (GetMessage(&msg, NULL, 0, 0)) 
  57.                 {
  58.                 if (flyengine && (
  59.                     (msg.message==WM_KEYDOWN && msg.wParam==VK_ESCAPE) ||
  60.                     (msg.message==WM_CHAR && flyengine->con.mode && msg.wParam!=VK_ESCAPE)))
  61.                         flyengine->con.key_press(msg.wParam);
  62.                 TranslateMessage(&msg);
  63.                 DispatchMessage(&msg);
  64.                 }
  65.             else 
  66.                 return TRUE;
  67.             }
  68.         
  69.         if (rend && flyengine)
  70.             if (flyengine->step())    // simmulate
  71.                 rend->DrawView();   // draw view
  72.         }
  73. }
  74.  
  75. // loads the menu level
  76. void LoadLevel(HWND hWnd, HINSTANCE hInst)
  77. {
  78.     init_engine(hWnd,hInst,FLYAPPID_FLY);
  79.     init_directx();
  80.     init_render(FLY_RENDER_OPENGL);
  81.     
  82.     fullscreen=1;
  83.     rend->SetFullScreen();
  84.     
  85.     flyengine->open_fly_file("menu/menu.fly");
  86.     flyengine->init_texture_cache();
  87.     InvalidateRect(hFlyWnd, 0, 0);
  88. }
  89.  
  90. // main window message processing
  91. LRESULT CALLBACK WinFunc (HWND hWnd, UINT mens, WPARAM wParam, LPARAM lParam)
  92. {
  93.     switch (mens)
  94.     {
  95.     // window resize
  96.     case WM_SIZE:
  97.         if (rend)
  98.             rend->ResizeView(LOWORD(lParam),HIWORD(lParam));
  99.     break;
  100.  
  101.     // window activation
  102.     case WM_ACTIVATE:
  103.         if (flyengine)
  104.             if (LOWORD(wParam)==WA_INACTIVE || flyengine->con.mode)
  105.                 flyengine->noinput=1;
  106.             else flyengine->noinput=0;
  107.         break;
  108.  
  109.     // quit app
  110.     case WM_DESTROY:
  111.         free_engine();
  112.         free_render();
  113.         free_directx();
  114.         PostQuitMessage (0);
  115.     break;
  116.     }
  117.  
  118.     return DefWindowProc (hWnd, mens, wParam, lParam);
  119. }
  120.