]> git.jsancho.org Git - lugaru.git/blobdiff - Source/OpenGL_Windows.cpp
Try fallbacks if we can't set video mode.
[lugaru.git] / Source / OpenGL_Windows.cpp
index 59df351e4574ceea0416e978c3e18ddb1757ef52..2937fefc3948994ab0af8bd9aaf803c729c209c5 100644 (file)
@@ -504,6 +504,16 @@ static void sdlEventProc(const SDL_Event &e, Game &game)
                 }
             }
 
+            #if (defined(__APPLE__) && defined(__MACH__))
+            if (e.key.keysym.sym == SDLK_q)
+            {
+                if (e.key.keysym.mod & KMOD_META)
+                {
+                    gDone=true;
+                }
+            }
+            #endif
+
             else if (e.key.keysym.sym == SDLK_RETURN)
             {
                 if (e.key.keysym.mod & KMOD_ALT)
@@ -877,7 +887,20 @@ Boolean SetUp (Game & game)
     if (SDL_SetVideoMode(kContextWidth, kContextHeight, 0, sdlflags) == NULL)
     {
         fprintf(stderr, "SDL_SetVideoMode() failed: %s\n", SDL_GetError());
-        return false;
+        fprintf(stderr, "forcing 640x480...\n");
+        kContextWidth = 640;
+        kContextHeight = 480;
+        if (SDL_SetVideoMode(kContextWidth, kContextHeight, 0, sdlflags) == NULL)
+        {
+            fprintf(stderr, "SDL_SetVideoMode() failed: %s\n", SDL_GetError());
+            fprintf(stderr, "forcing 640x480 windowed mode...\n");
+            sdlflags &= ~SDL_FULLSCREEN;
+            if (SDL_SetVideoMode(kContextWidth, kContextHeight, 0, sdlflags) == NULL)
+            {
+                fprintf(stderr, "SDL_SetVideoMode() failed: %s\n", SDL_GetError());
+                return false;
+            }
+        }
     }
 
     if (!lookup_all_glsyms())
@@ -1442,6 +1465,19 @@ static inline void chdirToAppPath(const char *argv0)
     char *dir = calcBaseDir(argv0);
     if (dir)
     {
+        #if (defined(__APPLE__) && defined(__MACH__))
+        // Chop off /Contents/MacOS if it's at the end of the string, so we
+        //  land in the base of the app bundle.
+        const size_t len = strlen(dir);
+        const char *bundledirs = "/Contents/MacOS";
+        const size_t bundledirslen = strlen(bundledirs);
+        if (len > bundledirslen)
+        {
+            char *ptr = (dir + len) - bundledirslen;
+            if (strcasecmp(ptr, bundledirs) == 0)
+                *ptr = '\0';
+        }
+        #endif
         chdir(dir);
         free(dir);
     }