13 #pragma comment(lib, "opengl32.lib")
14 #pragma comment(lib, "glu32.lib")
15 #pragma comment(lib, "glaux.lib")
18 extern bool buttons[3];
19 extern float multiplier;
20 extern float screenwidth,screenheight;
22 extern float realmultiplier;
24 extern bool ismotionblur;
25 extern float usermousesensitivity;
27 extern bool floatjump;
28 extern bool cellophane;
30 //extern int terraindetail;
31 //extern int texdetail;
32 extern float terraindetail;
33 extern float texdetail;
34 extern int bloodtoggle;
36 extern bool autoslomo;
38 extern bool musictoggle;
39 extern bool trilinear;
40 extern float gamespeed;
41 extern int difficulty;
42 extern bool damageeffects;
43 extern int numplayers;
45 extern bool invertmouse;
46 extern bool texttoggle;
47 extern bool ambientsound;
48 extern bool mousejump;
50 extern Person player[maxplayers];
52 extern bool stillloading;
53 extern bool showpoints;
54 extern bool alwaysblur;
55 extern bool immediate;
56 extern bool velocityblur;
57 extern bool debugmode;
59 /*extern*/ bool gameFocused;
60 extern int kBitsPerPixel;
61 extern float slomospeed;
62 extern float slomofreq;
63 extern float oldgamespeed;
72 #include "MacCompatibility.h"
80 #include "res/resource.h"
85 unsigned int resolutionDepths[8][2] = {0};
87 bool selectDetail(int & width, int & height, int & bpp, int & detail);
88 int closestResolution(int width, int height);
89 int resolutionID(int width, int height);
91 void ReportError (char * strError);
93 void SetupDSpFullScreen();
96 void DrawGL(Game & game);
98 void CreateGLWindow (void);
99 Boolean SetUp (Game & game);
100 void DoKey (SInt8 theKey, SInt8 theCode);
101 void DoUpdate (Game & game);
107 // statics/globals (internal only) ------------------------------------------
109 typedef struct tagPOINT {
116 void sdlGetCursorPos(POINT *pt)
119 SDL_GetMouseState(&x, &y);
123 #define GetCursorPos(x) sdlGetCursorPos(x)
124 #define SetCursorPos(x, y) SDL_WarpMouse(x, y)
125 #define ScreenToClient(x, pt)
126 #define ClientToScreen(x, pt)
127 #define MessageBox(hwnd,text,title,flags) STUBBED("msgbox")
133 static const char g_wndClassName[]={ "LUGARUWINDOWCLASS" };
134 static HINSTANCE g_appInstance;
135 static HWND g_windowHandle;
139 static bool g_button, fullscreen = true;
150 kForegroundSleep = 10,
151 kBackgroundSleep = 10000
158 const RGBColor rgbBlack = { 0x0000, 0x0000, 0x0000 };
161 char gcstrMode [256] = "";
163 UInt32 gSleepTime = kForegroundSleep;
164 Boolean gDone = false, gfFrontProcess = true;
168 static bool gMouseGrabbed = true;
170 // --------------------------------------------------------------------------
172 void ReportError (char * strError)
174 #ifdef WIN32 // !!! FIXME. --ryan.
175 throw std::exception( strError);
178 /* char errMsgCStr [256];
181 sprintf (errMsgCStr, "%s", strError);
183 // out as debug string
184 CToPStr (strErr, errMsgCStr);
189 void SetupDSpFullScreen ()
196 DEVMODE dmScreenSettings;
197 memset( &dmScreenSettings, 0, sizeof( dmScreenSettings));
198 dmScreenSettings.dmSize = sizeof( dmScreenSettings);
199 dmScreenSettings.dmPelsWidth = kContextWidth;
200 dmScreenSettings.dmPelsHeight = kContextHeight;
201 dmScreenSettings.dmBitsPerPel = kBitsPerPixel;
202 dmScreenSettings.dmFields = DM_BITSPERPEL | DM_PELSWIDTH | DM_PELSHEIGHT;
205 if (ChangeDisplaySettings( &dmScreenSettings, CDS_FULLSCREEN) != DISP_CHANGE_SUCCESSFUL)
207 ReportError( "Could not set display mode");
224 ChangeDisplaySettings( NULL, 0);
232 //-----------------------------------------------------------------------------------------------------------------------
236 void DrawGL (Game & game)
247 static KeyMap g_theKeys;
249 void SetKey( int key)
251 g_theKeys[ key >> 3] |= (1 << (key & 7));
254 void ClearKey( int key)
256 g_theKeys[ key >> 3] &= (0xff ^ (1 << (key & 7)));
259 void GetKeys( unsigned char theKeys[16])
261 memcpy( theKeys, &g_theKeys, 16);
270 static void initSDLKeyTable(void) {}
272 #define MAX_SDLKEYS SDLK_LAST
273 static unsigned short KeyTable[MAX_SDLKEYS];
275 static void initSDLKeyTable(void)
277 memset(KeyTable, 0xFF, sizeof (KeyTable));
278 KeyTable[SDLK_BACKSPACE] = MAC_DELETE_KEY;
279 KeyTable[SDLK_TAB] = MAC_TAB_KEY;
280 KeyTable[SDLK_RETURN] = MAC_RETURN_KEY;
281 KeyTable[SDLK_ESCAPE] = MAC_ESCAPE_KEY;
282 KeyTable[SDLK_SPACE] = MAC_SPACE_KEY;
283 KeyTable[SDLK_PAGEUP] = MAC_PAGE_UP_KEY;
284 KeyTable[SDLK_PAGEDOWN] = MAC_PAGE_DOWN_KEY;
285 KeyTable[SDLK_END] = MAC_END_KEY;
286 KeyTable[SDLK_HOME] = MAC_HOME_KEY;
287 KeyTable[SDLK_LEFT] = MAC_ARROW_LEFT_KEY;
288 KeyTable[SDLK_UP] = MAC_ARROW_UP_KEY;
289 KeyTable[SDLK_RIGHT] = MAC_ARROW_RIGHT_KEY;
290 KeyTable[SDLK_DOWN] = MAC_ARROW_DOWN_KEY;
291 KeyTable[SDLK_INSERT] = MAC_INSERT_KEY;
292 KeyTable[SDLK_DELETE] = MAC_DEL_KEY;
293 KeyTable[SDLK_0] = MAC_0_KEY;
294 KeyTable[SDLK_1] = MAC_1_KEY;
295 KeyTable[SDLK_2] = MAC_2_KEY;
296 KeyTable[SDLK_3] = MAC_3_KEY;
297 KeyTable[SDLK_4] = MAC_4_KEY;
298 KeyTable[SDLK_5] = MAC_5_KEY;
299 KeyTable[SDLK_6] = MAC_6_KEY;
300 KeyTable[SDLK_7] = MAC_7_KEY;
301 KeyTable[SDLK_8] = MAC_8_KEY;
302 KeyTable[SDLK_9] = MAC_9_KEY;
303 KeyTable[SDLK_a] = MAC_A_KEY;
304 KeyTable[SDLK_b] = MAC_B_KEY;
305 KeyTable[SDLK_c] = MAC_C_KEY;
306 KeyTable[SDLK_d] = MAC_D_KEY;
307 KeyTable[SDLK_e] = MAC_E_KEY;
308 KeyTable[SDLK_f] = MAC_F_KEY;
309 KeyTable[SDLK_g] = MAC_G_KEY;
310 KeyTable[SDLK_h] = MAC_H_KEY;
311 KeyTable[SDLK_i] = MAC_I_KEY;
312 KeyTable[SDLK_j] = MAC_J_KEY;
313 KeyTable[SDLK_k] = MAC_K_KEY;
314 KeyTable[SDLK_l] = MAC_L_KEY;
315 KeyTable[SDLK_m] = MAC_M_KEY;
316 KeyTable[SDLK_n] = MAC_N_KEY;
317 KeyTable[SDLK_o] = MAC_O_KEY;
318 KeyTable[SDLK_p] = MAC_P_KEY;
319 KeyTable[SDLK_q] = MAC_Q_KEY;
320 KeyTable[SDLK_r] = MAC_R_KEY;
321 KeyTable[SDLK_s] = MAC_S_KEY;
322 KeyTable[SDLK_t] = MAC_T_KEY;
323 KeyTable[SDLK_u] = MAC_U_KEY;
324 KeyTable[SDLK_v] = MAC_V_KEY;
325 KeyTable[SDLK_w] = MAC_W_KEY;
326 KeyTable[SDLK_x] = MAC_X_KEY;
327 KeyTable[SDLK_y] = MAC_Y_KEY;
328 KeyTable[SDLK_z] = MAC_Z_KEY;
329 KeyTable[SDLK_KP0] = MAC_NUMPAD_0_KEY;
330 KeyTable[SDLK_KP1] = MAC_NUMPAD_1_KEY;
331 KeyTable[SDLK_KP2] = MAC_NUMPAD_2_KEY;
332 KeyTable[SDLK_KP3] = MAC_NUMPAD_3_KEY;
333 KeyTable[SDLK_KP4] = MAC_NUMPAD_4_KEY;
334 KeyTable[SDLK_KP5] = MAC_NUMPAD_5_KEY;
335 KeyTable[SDLK_KP6] = MAC_NUMPAD_6_KEY;
336 KeyTable[SDLK_KP7] = MAC_NUMPAD_7_KEY;
337 KeyTable[SDLK_KP8] = MAC_NUMPAD_8_KEY;
338 KeyTable[SDLK_KP9] = MAC_NUMPAD_9_KEY;
339 KeyTable[SDLK_KP_MULTIPLY] = MAC_NUMPAD_ASTERISK_KEY;
340 KeyTable[SDLK_KP_PLUS] = MAC_NUMPAD_PLUS_KEY;
341 KeyTable[SDLK_KP_ENTER] = MAC_NUMPAD_ENTER_KEY;
342 KeyTable[SDLK_KP_MINUS] = MAC_NUMPAD_MINUS_KEY;
343 KeyTable[SDLK_KP_PERIOD] = MAC_NUMPAD_PERIOD_KEY;
344 KeyTable[SDLK_KP_DIVIDE] = MAC_NUMPAD_SLASH_KEY;
345 KeyTable[SDLK_F1] = MAC_F1_KEY;
346 KeyTable[SDLK_F2] = MAC_F2_KEY;
347 KeyTable[SDLK_F3] = MAC_F3_KEY;
348 KeyTable[SDLK_F4] = MAC_F4_KEY;
349 KeyTable[SDLK_F5] = MAC_F5_KEY;
350 KeyTable[SDLK_F6] = MAC_F6_KEY;
351 KeyTable[SDLK_F7] = MAC_F7_KEY;
352 KeyTable[SDLK_F8] = MAC_F8_KEY;
353 KeyTable[SDLK_F9] = MAC_F9_KEY;
354 KeyTable[SDLK_F10] = MAC_F10_KEY;
355 KeyTable[SDLK_F11] = MAC_F11_KEY;
356 KeyTable[SDLK_F12] = MAC_F12_KEY;
357 KeyTable[SDLK_SEMICOLON] = MAC_SEMICOLON_KEY;
358 KeyTable[SDLK_PLUS] = MAC_PLUS_KEY;
359 KeyTable[SDLK_COMMA] = MAC_COMMA_KEY;
360 KeyTable[SDLK_MINUS] = MAC_MINUS_KEY;
361 KeyTable[SDLK_PERIOD] = MAC_PERIOD_KEY;
362 KeyTable[SDLK_SLASH] = MAC_SLASH_KEY;
363 KeyTable[SDLK_BACKQUOTE] = MAC_TILDE_KEY;
364 KeyTable[SDLK_LEFTBRACKET] = MAC_LEFTBRACKET_KEY;
365 KeyTable[SDLK_BACKSLASH] = MAC_BACKSLASH_KEY;
366 KeyTable[SDLK_RIGHTBRACKET] = MAC_RIGHTBRACKET_KEY;
367 KeyTable[SDLK_QUOTE] = MAC_APOSTROPHE_KEY;
370 static inline int clamp_sdl_mouse_button(Uint8 button)
372 if ((button >= 1) && (button <= 3))
377 static void sdlEventProc(const SDL_Event &e)
382 case SDL_MOUSEBUTTONDOWN:
384 val = clamp_sdl_mouse_button(e.button.button);
390 SetKey(MAC_MOUSEBUTTON1);
394 SetKey(MAC_MOUSEBUTTON2);
401 case SDL_MOUSEBUTTONUP:
403 val = clamp_sdl_mouse_button(e.button.button);
409 ClearKey(MAC_MOUSEBUTTON1);
413 ClearKey(MAC_MOUSEBUTTON2);
415 buttons[val] = false;
421 if (e.key.keysym.sym == SDLK_g)
423 if (e.key.keysym.mod & KMOD_CTRL)
424 gMouseGrabbed = !gMouseGrabbed;
427 else if (e.key.keysym.sym == SDLK_RETURN)
429 if (e.key.keysym.mod & KMOD_ALT)
430 SDL_WM_ToggleFullScreen(SDL_GetVideoSurface());
433 if (e.key.keysym.sym < SDLK_LAST)
435 if (KeyTable[e.key.keysym.sym] != 0xffff)
436 SetKey(KeyTable[e.key.keysym.sym]);
439 if (e.key.keysym.mod & KMOD_CTRL)
440 SetKey(MAC_CONTROL_KEY);
441 if (e.key.keysym.mod & KMOD_ALT)
442 SetKey(MAC_OPTION_KEY);
443 if (e.key.keysym.mod & KMOD_SHIFT)
444 SetKey(MAC_SHIFT_KEY);
445 if (e.key.keysym.mod & KMOD_CAPS)
446 SetKey(MAC_CAPS_LOCK_KEY);
451 if (e.key.keysym.sym < SDLK_LAST)
453 if (KeyTable[e.key.keysym.sym] != 0xffff)
454 ClearKey(KeyTable[e.key.keysym.sym]);
457 if (e.key.keysym.mod & KMOD_CTRL)
458 ClearKey(MAC_CONTROL_KEY);
459 if (e.key.keysym.mod & KMOD_ALT)
460 ClearKey(MAC_OPTION_KEY);
461 if (e.key.keysym.mod & KMOD_SHIFT)
462 ClearKey(MAC_SHIFT_KEY);
463 if (e.key.keysym.mod & KMOD_CAPS)
464 ClearKey(MAC_CAPS_LOCK_KEY);
470 // --------------------------------------------------------------------------
472 static Point gMidPoint;
474 Boolean SetUp (Game & game)
480 randSeed = UpTime().lo;
483 // ifstream ipstream(":Data:config.txt", std::ios::in /*| std::ios::nocreate*/);
484 ifstream ipstream("./Data/config.txt", std::ios::in /*| std::ios::nocreate*/);
487 usermousesensitivity=1;
516 game.crouchkey=MAC_SHIFT_KEY;
517 game.jumpkey=MAC_SPACE_KEY;
518 game.leftkey=MAC_A_KEY;
519 game.forwardkey=MAC_W_KEY;
520 game.backkey=MAC_S_KEY;
521 game.rightkey=MAC_D_KEY;
522 game.drawkey=MAC_E_KEY;
523 game.throwkey=MAC_Q_KEY;
524 game.attackkey=MAC_MOUSEBUTTON1;
525 game.chatkey=MAC_T_KEY;
531 selectDetail(kContextWidth, kContextHeight, kBitsPerPixel, detail);
534 //ofstream opstream(":Data:config.txt");
535 ofstream opstream("./Data/config.txt");
536 opstream << "Screenwidth:\n";
537 opstream << kContextWidth;
538 opstream << "\nScreenheight:\n";
539 opstream << kContextHeight;
540 opstream << "\nMouse sensitivity:\n";
541 opstream << usermousesensitivity;
542 opstream << "\nBlur(0,1):\n";
543 opstream << ismotionblur;
544 opstream << "\nOverall Detail(0,1,2) higher=better:\n";
546 opstream << "\nFloating jump:\n";
547 opstream << floatjump;
548 opstream << "\nMouse jump:\n";
549 opstream << mousejump;
550 opstream << "\nAmbient sound:\n";
551 opstream << ambientsound;
552 opstream << "\nBlood (0,1,2):\n";
553 opstream << bloodtoggle;
554 opstream << "\nAuto slomo:\n";
555 opstream << autoslomo;
556 opstream << "\nFoliage:\n";
558 opstream << "\nMusic:\n";
559 opstream << musictoggle;
560 opstream << "\nTrilinear:\n";
561 opstream << trilinear;
562 opstream << "\nDecals(shadows,blood puddles,etc):\n";
564 opstream << "\nInvert mouse:\n";
565 opstream << invertmouse;
566 opstream << "\nGamespeed:\n";
567 opstream << gamespeed;
568 opstream << "\nDifficulty(0,1,2) higher=harder:\n";
569 opstream << difficulty;
570 opstream << "\nDamage effects(blackout, doublevision):\n";
571 opstream << damageeffects;
572 opstream << "\nText:\n";
573 opstream << texttoggle;
574 opstream << "\nDebug:\n";
575 opstream << debugmode;
576 opstream << "\nVBL Sync:\n";
578 opstream << "\nShow Points:\n";
579 opstream << showpoints;
580 opstream << "\nAlways Blur:\n";
581 opstream << alwaysblur;
582 opstream << "\nImmediate mode (turn on on G5):\n";
583 opstream << immediate;
584 opstream << "\nVelocity blur:\n";
585 opstream << velocityblur;
586 opstream << "\nVolume:\n";
588 opstream << "\nForward key:\n";
589 opstream << KeyToChar(game.forwardkey);
590 opstream << "\nBack key:\n";
591 opstream << KeyToChar(game.backkey);
592 opstream << "\nLeft key:\n";
593 opstream << KeyToChar(game.leftkey);
594 opstream << "\nRight key:\n";
595 opstream << KeyToChar(game.rightkey);
596 opstream << "\nJump key:\n";
597 opstream << KeyToChar(game.jumpkey);
598 opstream << "\nCrouch key:\n";
599 opstream << KeyToChar(game.crouchkey);
600 opstream << "\nDraw key:\n";
601 opstream << KeyToChar(game.drawkey);
602 opstream << "\nThrow key:\n";
603 opstream << KeyToChar(game.throwkey);
604 opstream << "\nAttack key:\n";
605 opstream << KeyToChar(game.attackkey);
606 opstream << "\nChat key:\n";
607 opstream << KeyToChar(game.chatkey);
612 ipstream.ignore(256,'\n');
613 ipstream >> kContextWidth;
614 ipstream.ignore(256,'\n');
615 ipstream.ignore(256,'\n');
616 ipstream >> kContextHeight;
617 ipstream.ignore(256,'\n');
618 ipstream.ignore(256,'\n');
619 ipstream >> usermousesensitivity;
620 ipstream.ignore(256,'\n');
621 ipstream.ignore(256,'\n');
623 ismotionblur = (i != 0);
624 ipstream.ignore(256,'\n');
625 ipstream.ignore(256,'\n');
627 if(detail!=0)kBitsPerPixel=32;
628 else kBitsPerPixel=16;
629 ipstream.ignore(256,'\n');
630 ipstream.ignore(256,'\n');
632 floatjump = (i != 0);
633 ipstream.ignore(256,'\n');
634 ipstream.ignore(256,'\n');
636 mousejump = (i != 0);
637 ipstream.ignore(256,'\n');
638 ipstream.ignore(256,'\n');
640 ambientsound = (i != 0);
641 ipstream.ignore(256,'\n');
642 ipstream.ignore(256,'\n');
643 ipstream >> bloodtoggle;
644 ipstream.ignore(256,'\n');
645 ipstream.ignore(256,'\n');
647 autoslomo = (i != 0);
648 ipstream.ignore(256,'\n');
649 ipstream.ignore(256,'\n');
652 ipstream.ignore(256,'\n');
653 ipstream.ignore(256,'\n');
655 musictoggle = (i != 0);
656 ipstream.ignore(256,'\n');
657 ipstream.ignore(256,'\n');
659 trilinear = (i != 0);
660 ipstream.ignore(256,'\n');
661 ipstream.ignore(256,'\n');
664 ipstream.ignore(256,'\n');
665 ipstream.ignore(256,'\n');
667 invertmouse = (i != 0);
668 ipstream.ignore(256,'\n');
669 ipstream.ignore(256,'\n');
670 ipstream >> gamespeed;
671 oldgamespeed=gamespeed;
676 ipstream.ignore(256,'\n');
677 ipstream.ignore(256,'\n');
678 ipstream >> difficulty;
679 ipstream.ignore(256,'\n');
680 ipstream.ignore(256,'\n');
682 damageeffects = (i != 0);
683 ipstream.ignore(256,'\n');
684 ipstream.ignore(256,'\n');
686 texttoggle = (i != 0);
687 ipstream.ignore(256,'\n');
688 ipstream.ignore(256,'\n');
690 debugmode = (i != 0);
691 ipstream.ignore(256,'\n');
692 ipstream.ignore(256,'\n');
695 ipstream.ignore(256,'\n');
696 ipstream.ignore(256,'\n');
698 showpoints = (i != 0);
699 ipstream.ignore(256,'\n');
700 ipstream.ignore(256,'\n');
702 alwaysblur = (i != 0);
703 ipstream.ignore(256,'\n');
704 ipstream.ignore(256,'\n');
706 immediate = (i != 0);
707 ipstream.ignore(256,'\n');
708 ipstream.ignore(256,'\n');
710 velocityblur = (i != 0);
711 ipstream.ignore(256,'\n');
712 ipstream.ignore(256,'\n');
714 ipstream.ignore(256,'\n');
715 ipstream.ignore(256,'\n');
717 game.forwardkey=CharToKey(string);
718 ipstream.ignore(256,'\n');
719 ipstream.ignore(256,'\n');
721 game.backkey=CharToKey(string);
722 ipstream.ignore(256,'\n');
723 ipstream.ignore(256,'\n');
725 game.leftkey=CharToKey(string);
726 ipstream.ignore(256,'\n');
727 ipstream.ignore(256,'\n');
729 game.rightkey=CharToKey(string);
730 ipstream.ignore(256,'\n');
731 ipstream.ignore(256,'\n');
733 game.jumpkey=CharToKey(string);
734 ipstream.ignore(256,'\n');
735 ipstream.ignore(256,'\n');
737 game.crouchkey=CharToKey(string);
738 ipstream.ignore(256,'\n');
739 ipstream.ignore(256,'\n');
741 game.drawkey=CharToKey(string);
742 ipstream.ignore(256,'\n');
743 ipstream.ignore(256,'\n');
745 game.throwkey=CharToKey(string);
746 ipstream.ignore(256,'\n');
747 ipstream.ignore(256,'\n');
749 game.attackkey=CharToKey(string);
750 ipstream.ignore(256,'\n');
751 ipstream.ignore(256,'\n');
753 game.chatkey=CharToKey(string);
756 if(detail>2)detail=2;
757 if(detail<0)detail=0;
758 if(screenwidth>3000)screenwidth=640;
759 if(screenwidth<0)screenwidth=640;
760 if(screenheight>3000)screenheight=480;
761 if(screenheight<0)screenheight=480;
763 if(kBitsPerPixel!=32&&kBitsPerPixel!=16){
768 selectDetail(kContextWidth, kContextHeight, kBitsPerPixel, detail);
770 SetupDSpFullScreen();
773 if (!SDL_WasInit(SDL_INIT_VIDEO))
775 if (SDL_Init(SDL_INIT_VIDEO) == -1)
777 fprintf(stderr, "SDL_Init() failed: %s\n", SDL_GetError());
782 Uint32 sdlflags = SDL_OPENGL;
783 SDL_WM_SetCaption("Lugaru", "lugaru");
785 if (SDL_SetVideoMode(kContextWidth, kContextHeight, 0, sdlflags) == NULL)
787 fprintf(stderr, "SDL_SetVideoMode() failed: %s\n", SDL_GetError());
791 #elif (defined WIN32)
792 //------------------------------------------------------------------
795 RECT r = {0, 0, kContextWidth-1, kContextHeight-1};
796 DWORD dwStyle = WS_CLIPCHILDREN | WS_CLIPSIBLINGS | WS_VISIBLE;
797 DWORD dwExStyle = WS_EX_APPWINDOW;
806 dwStyle |= WS_OVERLAPPEDWINDOW;
807 dwExStyle |= WS_EX_WINDOWEDGE;
810 AdjustWindowRectEx(&r, dwStyle, FALSE, dwExStyle);
814 x = (GetSystemMetrics(SM_CXSCREEN) >> 1) - ((r.right - r.left + 1) >> 1);
815 y = (GetSystemMetrics(SM_CYSCREEN) >> 1) - ((r.bottom - r.top + 1) >> 1);
818 g_windowHandle=CreateWindowEx(
820 g_wndClassName, "Lugaru", dwStyle,
822 // kContextWidth, kContextHeight,
823 r.right - r.left + 1, r.bottom - r.top + 1,
824 NULL,NULL,g_appInstance,NULL );
827 ReportError("Could not create window");
831 //------------------------------------------------------------------
834 static PIXELFORMATDESCRIPTOR pfd =
836 sizeof(PIXELFORMATDESCRIPTOR), // Size Of This Pixel Format Descriptor
838 PFD_DRAW_TO_WINDOW | // Format Must Support Window
839 PFD_SUPPORT_OPENGL | // Format Must Support OpenGL
840 PFD_DOUBLEBUFFER, // Must Support Double Buffering
841 PFD_TYPE_RGBA, // Request An RGBA Format
842 kBitsPerPixel, // Select Our Color Depth
843 0, 0, 0, 0, 0, 0, // Color Bits Ignored
844 0, // No Alpha Buffer
845 0, // Shift Bit Ignored
846 0, // No Accumulation Buffer
847 0, 0, 0, 0, // Accumulation Bits Ignored
848 16, // 16Bit Z-Buffer (Depth Buffer)
849 0, // No Stencil Buffer
850 0, // No Auxiliary Buffer
851 PFD_MAIN_PLANE, // Main Drawing Layer
853 0, 0, 0 // Layer Masks Ignored
856 if (!(hDC = GetDC( g_windowHandle)))
857 ReportError( "Could not get device context");
860 if (!(PixelFormat = ChoosePixelFormat(hDC, &pfd)))
862 ReportError( "Could not find appropriate pixel format");
866 if (!DescribePixelFormat(hDC, PixelFormat, sizeof(PIXELFORMATDESCRIPTOR), &pfd))
868 ReportError( "Could not retrieve pixel format");
872 if (!SetPixelFormat( hDC, PixelFormat, &pfd))
874 ReportError( "Could not set pixel format");
878 if (!(hRC = wglCreateContext(hDC)))
880 ReportError( "Could not create rendering context");
884 if (!wglMakeCurrent(hDC, hRC))
886 ReportError( "Could not activate rendering context");
892 // Place the window above all topmost windows
893 SetWindowPos( g_windowHandle, HWND_TOPMOST, 0,0,0,0,
894 SWP_NOMOVE | SWP_NOSIZE );
897 SetForegroundWindow(g_windowHandle);
898 SetFocus(g_windowHandle);
901 glClear( GL_COLOR_BUFFER_BIT );
905 glDisable( GL_ALPHA_TEST);
906 glDisable( GL_BLEND);
907 glDisable( GL_DEPTH_TEST);
908 // glDisable( GL_DITHER);
910 glDisable( GL_LIGHTING);
911 glDisable( GL_LOGIC_OP);
912 glDisable( GL_STENCIL_TEST);
913 glDisable( GL_TEXTURE_1D);
914 glDisable( GL_TEXTURE_2D);
915 glPixelTransferi( GL_MAP_COLOR, GL_FALSE);
916 glPixelTransferi( GL_RED_SCALE, 1);
917 glPixelTransferi( GL_RED_BIAS, 0);
918 glPixelTransferi( GL_GREEN_SCALE, 1);
919 glPixelTransferi( GL_GREEN_BIAS, 0);
920 glPixelTransferi( GL_BLUE_SCALE, 1);
921 glPixelTransferi( GL_BLUE_BIAS, 0);
922 glPixelTransferi( GL_ALPHA_SCALE, 1);
923 glPixelTransferi( GL_ALPHA_BIAS, 0);
925 // set initial rendering states
926 glShadeModel( GL_SMOOTH);
928 glDepthFunc( GL_LEQUAL);
929 glDepthMask( GL_TRUE);
930 // glDepthRange( FRONT_CLIP, BACK_CLIP);
931 glEnable( GL_DEPTH_TEST);
932 glHint( GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);
933 glCullFace( GL_FRONT);
934 glEnable( GL_CULL_FACE);
935 glEnable( GL_LIGHTING);
936 // glEnable( GL_LIGHT_MODEL_AMBIENT);
937 glEnable( GL_DITHER);
938 glEnable( GL_COLOR_MATERIAL);
939 glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
940 glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
941 glAlphaFunc( GL_GREATER, 0.5f);
943 if (ilGetInteger(IL_VERSION_NUM) < IL_VERSION ||
944 iluGetInteger(ILU_VERSION_NUM) < ILU_VERSION ||
945 ilutGetInteger(ILUT_VERSION_NUM) < ILUT_VERSION)
947 ReportError("DevIL version is different...exiting!\n");
955 ilutRenderer(ILUT_OPENGL);
957 ilEnable(IL_ORIGIN_SET);
958 ilOriginFunc(IL_ORIGIN_LOWER_LEFT);
960 GLint width = kContextWidth;
961 GLint height = kContextHeight;
962 gMidPoint.h = width / 2;
963 gMidPoint.v = height / 2;
967 game.newdetail=detail;
968 game.newscreenwidth=screenwidth;
969 game.newscreenheight=screenheight;
977 static void DoMouse(Game & game)
979 static Point lastMouse = {-1,-1};
984 ScreenToClient(g_windowHandle, &pos);
985 globalMouse.h = pos.x;
986 globalMouse.v = pos.y;
988 if (lastMouse.h == globalMouse.h && lastMouse.v == globalMouse.v)
995 static Point virtualMouse = {0,0};
998 delta.h -= lastMouse.h;
999 delta.v -= lastMouse.v;
1000 lastMouse.h = pos.x;
1001 lastMouse.v = pos.y;
1003 if(mainmenu||(abs(delta.h)<10*realmultiplier*1000&&abs(delta.v)<10*realmultiplier*1000)){
1004 game.deltah=delta.h*usermousesensitivity;
1005 game.deltav=delta.v*usermousesensitivity;
1006 game.mousecoordh=globalMouse.h;
1007 game.mousecoordv=globalMouse.v;
1010 if((!mainmenu)&&(gMouseGrabbed))
1012 if(lastMouse.h>gMidPoint.h+100||lastMouse.h<gMidPoint.h-100||lastMouse.v>gMidPoint.v+100||lastMouse.v<gMidPoint.v-100){
1013 pos.x = gMidPoint.h;
1014 pos.y = gMidPoint.v;
1015 ClientToScreen(g_windowHandle, &pos);
1016 //SetCursorPos( gMidPoint.h,gMidPoint.v);
1017 SetCursorPos(pos.x, pos.y);
1018 lastMouse = gMidPoint;
1026 // --------------------------------------------------------------------------
1028 void DoKey (SInt8 theKey, SInt8 theCode)
1033 // --------------------------------------------------------------------------
1037 void DoFrameRate (int update)
1039 static long frames = 0;
1041 static AbsoluteTime time = {0,0};
1042 static AbsoluteTime frametime = {0,0};
1043 AbsoluteTime currTime = UpTime ();
1044 double deltaTime = (float) AbsoluteDeltaToDuration (currTime, frametime);
1046 if (0 > deltaTime) // if negative microseconds
1047 deltaTime /= -1000000.0;
1048 else // else milliseconds
1049 deltaTime /= 1000.0;
1051 multiplier=deltaTime;
1052 if(multiplier<.001)multiplier=.001;
1053 if(multiplier>10)multiplier=10;
1054 if(update)frametime = currTime; // reset for next time interval
1056 deltaTime = (float) AbsoluteDeltaToDuration (currTime, time);
1058 if (0 > deltaTime) // if negative microseconds
1059 deltaTime /= -1000000.0;
1060 else // else milliseconds
1061 deltaTime /= 1000.0;
1063 if (0.001 <= deltaTime) // has update interval passed
1066 time = currTime; // reset for next time interval
1073 void DoUpdate (Game & game)
1075 static float sps=200;
1077 static float oldmult;
1080 if(multiplier>.6)multiplier=.6;
1082 game.fps=1/multiplier;
1084 count = multiplier*sps;
1086 //if(count>10)count=10;
1088 realmultiplier=multiplier;
1089 multiplier*=gamespeed;
1090 if(difficulty==1)multiplier*=.9;
1091 if(difficulty==0)multiplier*=.8;
1093 if(game.loading==4)multiplier*=.00001;
1095 if(slomo&&!mainmenu)multiplier*=slomospeed;
1096 //if(freeze)multiplier*=0.00001;
1098 multiplier/=(float)count;
1104 for(int i=0;i<count;i++)
1110 game.TickOnceAfter();
1111 /* - Debug code to test how many channels were active on average per frame
1112 static long frames = 0;
1114 static AbsoluteTime start = {0,0};
1115 AbsoluteTime currTime = UpTime ();
1116 static int num_channels = 0;
1118 num_channels += FSOUND_GetChannelsPlaying();
1119 double deltaTime = (float) AbsoluteDeltaToDuration (currTime, start);
1121 if (0 > deltaTime) // if negative microseconds
1122 deltaTime /= -1000000.0;
1123 else // else milliseconds
1124 deltaTime /= 1000.0;
1131 float avg_channels = (float)num_channels / (float)frames;
1133 ofstream opstream("log.txt",ios::app);
1134 opstream << "Average frame count: ";
1136 opstream << " frames - ";
1137 opstream << avg_channels;
1138 opstream << " per frame.\n";
1148 // --------------------------------------------------------------------------
1162 #elif (defined WIN32)
1165 wglMakeCurrent( NULL, NULL);
1166 wglDeleteContext( hRC);
1172 ReleaseDC( g_windowHandle, hDC);
1178 ShowWindow( g_windowHandle, SW_HIDE );
1179 DestroyWindow( g_windowHandle);
1180 g_windowHandle = NULL;
1188 // --------------------------------------------------------------------------
1190 static bool g_focused = true;
1193 static bool IsFocused()
1199 if (GetActiveWindow() != g_windowHandle)
1202 if (IsIconic( g_windowHandle))
1213 #ifndef WIN32 // this is in WinMain, too.
1215 memset( &g_theKeys, 0, sizeof( KeyMap));
1222 bool regnow = false;
1227 //ofstream os("error.txt");
1229 //ofstream os("log.txt");
1234 while (!gDone&&!game.quit&&(!game.tryquit||!game.registered))
1240 // check windows messages
1244 while( SDL_PollEvent( &e ) )
1246 if( e.type == SDL_QUIT )
1253 #elif (defined WIN32)
1256 while( PeekMessage( &msg, NULL, 0, 0, PM_REMOVE | PM_NOYIELD ) )
1258 if( msg.message == WM_QUIT )
1265 TranslateMessage( &msg );
1266 DispatchMessage( &msg );
1278 // allow game chance to pause
1279 gameFocused = false;
1283 // game is not in focus, give CPU time to other apps by waiting for messages instead of 'peeking'
1287 //if (GetMessage( &msg, g_windowHandle, 0, 0 ))
1288 /*if (GetMessage( &msg, NULL, 0, 0 ))
1290 TranslateMessage(&msg);
1291 DispatchMessage(&msg);
1293 if ( (bRet = GetMessage( &msg, NULL, 0, 0 )) != 0)
1297 // handle the error and possibly exit
1302 TranslateMessage(&msg);
1303 DispatchMessage(&msg);
1307 STUBBED("give up CPU but sniff the event queue");
1312 regnow = game.registernow;
1317 // if(game.registernow){
1321 STUBBED("launch a web browser");
1324 sprintf(url,"http://www.wolfire.com/registerpc.html");
1326 ShellExecute(NULL, "open", url, NULL, NULL, SW_SHOWNORMAL);
1331 catch (const std::exception& error)
1335 std::string e = "Caught exception: ";
1338 LOG(e, Logger::LOG_ERR);
1340 MessageBox(g_windowHandle, error.what(), "ERROR", MB_OK | MB_ICONEXCLAMATION);
1350 // --------------------------------------------------------------------------
1353 #define MAX_WINKEYS 256
1354 static unsigned short KeyTable[MAX_WINKEYS]=
1357 MAC_MOUSEBUTTON1, // VK_LBUTTON (1)
1358 MAC_MOUSEBUTTON2, // VK_RBUTTON (2)
1359 0xffff, // VK_CANCEL (3)
1360 0xffff, // VK_MBUTTON (4)
1364 MAC_DELETE_KEY, // VK_BACK (8)
1365 MAC_TAB_KEY, // VK_TAB (9)
1368 0xffff, // VK_CLEAR (12)
1369 MAC_RETURN_KEY, // VK_RETURN (13)
1372 MAC_SHIFT_KEY, // VK_SHIFT (16)
1373 MAC_CONTROL_KEY, // VK_CONTROL (17)
1374 MAC_OPTION_KEY, // VK_MENU (18)
1375 0xffff, // VK_PAUSE (19)
1376 MAC_CAPS_LOCK_KEY, // #define VK_CAPITAL (20)
1383 MAC_ESCAPE_KEY, // VK_ESCAPE (27)
1388 MAC_SPACE_KEY, // VK_SPACE (32)
1389 MAC_PAGE_UP_KEY, // VK_PRIOR (33)
1390 MAC_PAGE_DOWN_KEY, // VK_NEXT (34)
1391 MAC_END_KEY, // VK_END (35)
1392 MAC_HOME_KEY, // VK_HOME (36)
1393 MAC_ARROW_LEFT_KEY, // VK_LEFT (37)
1394 MAC_ARROW_UP_KEY, // VK_UP (38)
1395 MAC_ARROW_RIGHT_KEY, // VK_RIGHT (39)
1396 MAC_ARROW_DOWN_KEY, // VK_DOWN (40)
1397 0xffff, // VK_SELECT (41)
1398 0xffff, // VK_PRINT (42)
1399 0xffff, // VK_EXECUTE (43)
1400 0xffff, // VK_SNAPSHOT (44)
1401 MAC_INSERT_KEY, // VK_INSERT (45)
1402 MAC_DEL_KEY, // VK_DELETE (46)
1403 0xffff, // VK_HELP (47)
1404 MAC_0_KEY, // VK_0 (48)
1405 MAC_1_KEY, // VK_1 (49)
1406 MAC_2_KEY, // VK_2 (50)
1407 MAC_3_KEY, // VK_3 (51)
1408 MAC_4_KEY, // VK_4 (52)
1409 MAC_5_KEY, // VK_5 (53)
1410 MAC_6_KEY, // VK_6 (54)
1411 MAC_7_KEY, // VK_7 (55)
1412 MAC_8_KEY, // VK_8 (56)
1413 MAC_9_KEY, // VK_9 (57)
1421 MAC_A_KEY, // VK_A (65)
1422 MAC_B_KEY, // VK_B (66)
1423 MAC_C_KEY, // VK_C (67)
1424 MAC_D_KEY, // VK_D (68)
1425 MAC_E_KEY, // VK_E (69)
1426 MAC_F_KEY, // VK_F (70)
1427 MAC_G_KEY, // VK_G (71)
1428 MAC_H_KEY, // VK_H (72)
1429 MAC_I_KEY, // VK_I (73)
1430 MAC_J_KEY, // VK_J (74)
1431 MAC_K_KEY, // VK_K (75)
1432 MAC_L_KEY, // VK_L (76)
1433 MAC_M_KEY, // VK_M (77)
1434 MAC_N_KEY, // VK_N (78)
1435 MAC_O_KEY, // VK_O (79)
1436 MAC_P_KEY, // VK_P (80)
1437 MAC_Q_KEY, // VK_Q (81)
1438 MAC_R_KEY, // VK_R (82)
1439 MAC_S_KEY, // VK_S (83)
1440 MAC_T_KEY, // VK_T (84)
1441 MAC_U_KEY, // VK_U (85)
1442 MAC_V_KEY, // VK_V (86)
1443 MAC_W_KEY, // VK_W (87)
1444 MAC_X_KEY, // VK_X (88)
1445 MAC_Y_KEY, // VK_Y (89)
1446 MAC_Z_KEY, // VK_Z (90)
1452 MAC_NUMPAD_0_KEY, // VK_NUMPAD0 (96)
1453 MAC_NUMPAD_1_KEY, // VK_NUMPAD1 (97)
1454 MAC_NUMPAD_2_KEY, // VK_NUMPAD2 (98)
1455 MAC_NUMPAD_3_KEY, // VK_NUMPAD3 (99)
1456 MAC_NUMPAD_4_KEY, // VK_NUMPAD4 (100)
1457 MAC_NUMPAD_5_KEY, // VK_NUMPAD5 (101)
1458 MAC_NUMPAD_6_KEY, // VK_NUMPAD6 (102)
1459 MAC_NUMPAD_7_KEY, // VK_NUMPAD7 (103)
1460 MAC_NUMPAD_8_KEY, // VK_NUMPAD8 (104)
1461 MAC_NUMPAD_9_KEY, // VK_NUMPAD9 (105)
1462 MAC_NUMPAD_ASTERISK_KEY, // VK_MULTIPLY (106)
1463 MAC_NUMPAD_PLUS_KEY, // VK_ADD (107)
1464 MAC_NUMPAD_ENTER_KEY, // VK_SEPARATOR (108)
1465 MAC_NUMPAD_MINUS_KEY, // VK_SUBTRACT (109)
1466 MAC_NUMPAD_PERIOD_KEY, // VK_DECIMAL (110)
1467 MAC_NUMPAD_SLASH_KEY, // VK_DIVIDE (111)
1468 MAC_F1_KEY, // VK_F1 (112)
1469 MAC_F2_KEY, // VK_F2 (113)
1470 MAC_F3_KEY, // VK_F3 (114)
1471 MAC_F4_KEY, // VK_F4 (115)
1472 MAC_F5_KEY, // VK_F5 (116)
1473 MAC_F6_KEY, // VK_F6 (117)
1474 MAC_F7_KEY, // VK_F7 (118)
1475 MAC_F8_KEY, // VK_F8 (119)
1476 MAC_F9_KEY, // VK_F9 (120)
1477 MAC_F10_KEY, // VK_F10 (121)
1478 MAC_F11_KEY, // VK_F11 (122)
1479 MAC_F12_KEY, // VK_F12 (123)
1500 0xffff, // VK_NUMLOCK (144)
1501 0xffff, // VK_SCROLL (145)
1516 MAC_SHIFT_KEY, // VK_LSHIFT (160)
1517 MAC_SHIFT_KEY, // VK_RSHIFT (161)
1518 MAC_CONTROL_KEY, // VK_LCONTROL (162)
1519 MAC_CONTROL_KEY, // VK_RCONTROL (163)
1520 MAC_OPTION_KEY, // VK_LMENU (164)
1521 MAC_OPTION_KEY, // VK_RMENU (165)
1542 MAC_SEMICOLON_KEY, // (186)
1543 MAC_PLUS_KEY, // (187)
1544 MAC_COMMA_KEY, // (188)
1545 MAC_MINUS_KEY, // (189)
1546 MAC_PERIOD_KEY, // (190)
1547 MAC_SLASH_KEY, // (191)
1548 MAC_TILDE_KEY, // (192)
1575 MAC_LEFTBRACKET_KEY, // (219)
1576 MAC_BACKSLASH_KEY, // (220)
1577 MAC_RIGHTBRACKET_KEY, // (221)
1578 MAC_APOSTROPHE_KEY, // (222)
1614 void ClipMouseToWindow(HWND window)
1618 GetClientRect(window, &wRect);
1620 ClientToScreen(window, (LPPOINT)&wRect.left);
1621 ClientToScreen(window, (LPPOINT)&wRect.right);
1628 LRESULT FAR PASCAL AppWndProc(HWND hWnd,UINT msg,WPARAM wParam,LPARAM lParam)
1630 /* this is where we receive all messages concerning this window
1631 * we can either process a message or pass it on to the default
1632 * message handler of windows */
1634 static PAINTSTRUCT ps;
1638 case WM_ACTIVATE: // Watch For Window Activate Message
1640 // Check Minimization State
1641 BOOL iconified = HIWORD(wParam) ? TRUE : FALSE;
1643 if (LOWORD(wParam) == WA_INACTIVE)
1652 CloseWindow( hWnd );
1654 // The window is now iconified
1655 iconified = GL_TRUE;
1661 g_focused=false; // Program Is Active
1665 SetupDSpFullScreen();
1672 // The window is now iconified
1673 iconified = GL_FALSE;
1676 ShowWindow( hWnd, SW_SHOW );
1677 SetForegroundWindow( hWnd );
1681 ClipMouseToWindow(hWnd);
1682 g_focused=true; // Program Is No Longer Active
1685 return 0; // Return To The Message Loop
1691 // check for Alt-F4 (exit hotkey)
1692 if (wParam == VK_F4)
1694 if (GetKeyState( VK_MENU) & 0x8080)
1700 if (wParam < MAX_WINKEYS)
1702 if (KeyTable[wParam] != 0xffff)
1703 SetKey( KeyTable[wParam]);
1711 if (wParam < MAX_WINKEYS)
1712 if (KeyTable[wParam] != 0xffff)
1713 ClearKey( KeyTable[wParam]);
1720 case WM_SYSDEADCHAR:
1723 case WM_NCLBUTTONDOWN:
1724 case WM_LBUTTONDOWN:
1731 case WM_NCRBUTTONDOWN:
1732 case WM_RBUTTONDOWN:
1738 case WM_NCMBUTTONDOWN:
1739 case WM_MBUTTONDOWN:
1745 case WM_NCLBUTTONUP:
1749 buttons[ 0] = false;
1753 case WM_NCRBUTTONUP:
1756 buttons[ 1] = false;
1760 case WM_NCMBUTTONUP:
1763 buttons[ 2] = false;
1767 case WM_NCLBUTTONDBLCLK:
1768 case WM_NCRBUTTONDBLCLK:
1769 case WM_NCMBUTTONDBLCLK:
1770 case WM_LBUTTONDBLCLK:
1772 case WM_RBUTTONDBLCLK:
1773 case WM_MBUTTONDBLCLK:
1776 case WM_NCMOUSEMOVE:
1778 /* ((WindowInfo *)g_lastWindow->GetInfo())->m_mouseX = (signed short)(lParam & 0xffff);
1779 ((WindowInfo *)g_lastWindow->GetInfo())->m_mouseY = (signed short)(lParam >> 16);
1780 if (g_lastWindow->m_mouseCallbacksEnabled) g_lastWindow->MouseMoveCallback();
1781 */// goto winmessage;
1784 case WM_SYSCOMMAND: // Intercept System Commands
1786 switch (wParam) // Check System Calls
1788 case SC_SCREENSAVE: // Screensaver Trying To Start?
1789 case SC_MONITORPOWER: // Monitor Trying To Enter Powersave?
1790 return 0; // Prevent From Happening
1792 // User trying to access application menu using ALT?
1801 // ReleaseCapture();
1802 // ClipMouseToWindow(hWnd);
1819 PostQuitMessage(0); /* Terminate Application */
1827 // BeginPaint( g_windowHandle,&ps);
1828 // EndPaint( g_windowHandle,&ps);
1835 /* We processed the message and there
1836 * is no processing by Windows necessary */
1838 /* We didn't process the message so let Windows do it */
1839 return DefWindowProc(hWnd,msg,wParam,lParam);
1843 static BOOL RegisterWindowClasses(HINSTANCE hFirstInstance)
1846 memset( &wc, 0, sizeof( wc));
1848 /* Register the window class. */
1849 wc.cbSize = sizeof(wc);
1851 wc.style = (CS_DBLCLKS | CS_HREDRAW | CS_VREDRAW | CS_OWNDC); /* Combination of Class Styles */
1852 wc.lpfnWndProc = AppWndProc; /* Adress of Window Procedure */
1853 wc.cbClsExtra = 0; /* Extra Bytes allocated for this Class */
1854 wc.cbWndExtra = 0; /* Extra Bytes allocated for each Window */
1855 wc.hInstance = hFirstInstance; /* Handle of program instance */
1856 wc.hIcon = LoadIcon( hFirstInstance, MAKEINTRESOURCE(IDI_LUGARU) );
1857 wc.hCursor = LoadCursor(NULL, IDC_ARROW);
1858 wc.hbrBackground = NULL;
1859 wc.lpszMenuName = NULL;
1860 wc.lpszClassName = g_wndClassName; /* Name of the Window Class */
1861 wc.hIconSm = LoadIcon( hFirstInstance, MAKEINTRESOURCE(IDI_LUGARU) );
1863 if (!RegisterClassEx(&wc)) return FALSE; /* Register Class failed */
1869 int resolutionID(int width, int height)
1873 if(width==640 && height==480)whichres=0;
1874 if(width==800 && height==600)whichres=1;
1875 if(width==1024 && height==768)whichres=2;
1876 if(width==1280 && height==1024)whichres=3;
1877 if(width==1600 && height==1200)whichres=4;
1878 if(width==840 && height==524)whichres=5;
1879 if(width==1024 && height==640)whichres=6;
1880 if(width==1344 && height==840)whichres=7;
1885 int closestResolution(int width, int height)
1889 if(width>=640 && height>=480)whichres=0;
1890 if(width>=800 && height>=600)whichres=1;
1891 if(width>=1024 && height>=768)whichres=2;
1892 if(width>=1280 && height>=1024)whichres=3;
1893 if(width>=1600 && height>=1200)whichres=4;
1894 if(width==840 && height==524)whichres=5;
1895 if(width==1024 && height==640)whichres=6;
1896 if(width==1344 && height==840)whichres=7;
1901 bool selectDetail(int & width, int & height, int & bpp, int & detail)
1904 int whichres = closestResolution(width, height);
1908 if(whichres<=0 || whichres>7){
1942 if ((detail != 0) && (resolutionDepths[whichres][1] != 0))
1946 else if ((detail == 0) && (resolutionDepths[whichres][0] != 0))
1950 else if ((detail != 0) && (resolutionDepths[whichres][0] != 0))
1956 else if (0 == whichres)
1964 bpp = resolutionDepths[whichres][(detail != 0)];
1970 int __stdcall WinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance,LPSTR lpCmdLine,int nShowCmd)
1973 LPWSTR * cl = CommandLineToArgvW(GetCommandLineW(), &argc);
1976 if (0 == _wcsicmp(cl[1], L"-windowed"))
1984 memset( &g_theKeys, 0, sizeof( KeyMap));
1988 memset(&mode, 0, sizeof(mode));
1989 mode.dmSize = sizeof(mode);
1990 while (EnumDisplaySettings(NULL, i++, &mode))
1992 if (mode.dmBitsPerPel < 16)
1997 int res = resolutionID(mode.dmPelsWidth, mode.dmPelsHeight);
1999 if (res > -1 && res < 8)
2001 if (DISP_CHANGE_SUCCESSFUL != ChangeDisplaySettings(&mode, CDS_TEST))
2006 switch(mode.dmBitsPerPel)
2010 resolutionDepths[res][1] = mode.dmBitsPerPel;
2013 resolutionDepths[res][0] = mode.dmBitsPerPel;
2019 /* if there is no Instance of our program in memory then register the window class */
2020 if (hPrevInstance == NULL && !RegisterWindowClasses(hInstance))
2021 return FALSE; /* registration failed! */
2023 g_appInstance=hInstance;
2027 UnregisterClass( g_wndClassName, hInstance);
2034 extern int channels[100];
2035 extern FSOUND_SAMPLE * samp[100];
2036 extern FSOUND_STREAM * strm[10];
2038 extern "C" void PlaySoundEx(int chan, FSOUND_SAMPLE *sptr, FSOUND_DSPUNIT *dsp, signed char startpaused)
2040 const FSOUND_SAMPLE * currSample = FSOUND_GetCurrentSample(channels[chan]);
2041 if (currSample && currSample == samp[chan])
2043 if (FSOUND_GetPaused(channels[chan]))
2045 FSOUND_StopSound(channels[chan]);
2046 channels[chan] = FSOUND_FREE;
2048 else if (FSOUND_IsPlaying(channels[chan]))
2050 int loop_mode = FSOUND_GetLoopMode(channels[chan]);
2051 if (loop_mode & FSOUND_LOOP_OFF)
2053 channels[chan] = FSOUND_FREE;
2059 channels[chan] = FSOUND_FREE;
2062 channels[chan] = FSOUND_PlaySoundEx(channels[chan], sptr, dsp, startpaused);
2063 if (channels[chan] < 0)
2065 channels[chan] = FSOUND_PlaySoundEx(FSOUND_FREE, sptr, dsp, startpaused);
2069 extern "C" void PlayStreamEx(int chan, FSOUND_STREAM *sptr, FSOUND_DSPUNIT *dsp, signed char startpaused)
2071 const FSOUND_SAMPLE * currSample = FSOUND_GetCurrentSample(channels[chan]);
2072 if (currSample && currSample == FSOUND_Stream_GetSample(sptr))
2074 FSOUND_StopSound(channels[chan]);
2075 FSOUND_Stream_Stop(sptr);
2079 FSOUND_Stream_Stop(sptr);
2080 channels[chan] = FSOUND_FREE;
2083 channels[chan] = FSOUND_Stream_PlayEx(channels[chan], sptr, dsp, startpaused);
2084 if (channels[chan] < 0)
2086 channels[chan] = FSOUND_Stream_PlayEx(FSOUND_FREE, sptr, dsp, startpaused);
2090 bool LoadImage(const char * fname, TGAImageRec & tex)
2094 if ( tex.data == NULL )
2099 ILstring f = strdup(ConvertFileName(fname));
2106 ilGenImages(1, &iid);
2111 tex.sizeX = ilGetInteger(IL_IMAGE_WIDTH);
2112 tex.sizeY = ilGetInteger(IL_IMAGE_HEIGHT);
2113 tex.bpp = ilGetInteger(IL_IMAGE_BITS_PER_PIXEL);
2114 ILuint Bpp = ilGetInteger(IL_IMAGE_BYTES_PER_PIXEL),
2115 imageSize = tex.sizeX * tex.sizeY * Bpp;
2116 ILubyte *Data = ilGetData();
2117 memcpy(tex.data, Data, imageSize);
2119 // Truvision Targa files are stored as BGR colors
2120 // We want RGB so Blue and Red bytes are switched
2121 if (IL_TGA == ilGetInteger(IL_IMAGE_FORMAT))
2123 // Loop Through The Image Data
2124 for (GLuint i = 0; i < int(imageSize); i += Bpp)
2126 // Swaps The 1st And 3rd Bytes ('R'ed and 'B'lue)
2127 GLbyte temp; // Temporary Variable
2128 temp = tex.data[i]; // Temporarily Store The Value At Image Data 'i'
2129 tex.data[i] = tex.data[i + 2]; // Set The 1st Byte To The Value Of The 3rd Byte
2130 tex.data[i + 2] = temp; // Set The 3rd Byte To The Value In 'temp' (1st Byte Value)
2138 ilDeleteImages(1, &iid);
2142 GLuint texid = ilutGLLoadImage(f);
2147 ilutGLBuildMipmaps()
2159 void ScreenShot(const char * fname)
2161 ILstring f = strdup(fname);
2168 ilGenImages(1, &iid);
2174 ilDeleteImages(1, &iid);