shithub: choc

Download patch

ref: 025459ccb43b0a5a23cbb4453c9a0a1139b0bb2d
parent: 3d1cf028d866c9fabce4cfdcaadbe87bba29256a
author: Simon Howard <fraggle@gmail.com>
date: Sat Mar 18 18:42:03 EST 2006

Auto adjust settings when running fullscreen so that we run in a 
valid video mode.

Subversion-branch: /trunk/chocolate-doom
Subversion-revision: 427

--- a/src/i_video.c
+++ b/src/i_video.c
@@ -1,7 +1,7 @@
 // Emacs style mode select   -*- C++ -*- 
 //-----------------------------------------------------------------------------
 //
-// $Id: i_video.c 415 2006-03-10 01:49:25Z fraggle $
+// $Id: i_video.c 427 2006-03-18 23:42:03Z fraggle $
 //
 // Copyright(C) 1993-1996 Id Software, Inc.
 // Copyright(C) 2005 Simon Howard
@@ -175,7 +175,7 @@
 //-----------------------------------------------------------------------------
 
 static const char
-rcsid[] = "$Id: i_video.c 415 2006-03-10 01:49:25Z fraggle $";
+rcsid[] = "$Id: i_video.c 427 2006-03-18 23:42:03Z fraggle $";
 
 #include <SDL.h>
 #include <ctype.h>
@@ -880,6 +880,40 @@
     SDL_FreeSurface(surface);
 }
 
+// Check if a screen mode is in the list available
+// Not all machines support running in 320x200/640x400 (only support 4:3)
+// Some don't even support modes below 640x480.
+
+static boolean CheckValidFSMode(int w, int h)
+{
+    SDL_Rect **modes;
+    int i;
+
+    modes = SDL_ListModes(NULL, SDL_FULLSCREEN);
+
+    for (i=0; modes[i]; ++i)
+    {
+        if (w == modes[i]->w && h == modes[i]->h)
+            return true;
+    }
+
+    // not found
+
+    return false;
+}
+
+// Get window dimensions for the current settings
+
+static void GetWindowDimensions(int *windowwidth, int *windowheight)
+{
+    *windowwidth = SCREENWIDTH * screenmultiply;
+
+    if (fullscreen == FULLSCREEN_LETTERBOX)
+        *windowheight = LETTERBOX_SCREENHEIGHT * screenmultiply;
+    else
+        *windowheight = SCREENHEIGHT * screenmultiply;
+}
+
 void I_InitGraphics(void)
 {
     SDL_Event dummy;
@@ -933,12 +967,44 @@
     if (screenmultiply > 2)
         screenmultiply = 2;
 
-    windowwidth = SCREENWIDTH * screenmultiply;
+    GetWindowDimensions(&windowwidth, &windowheight);
 
-    if (fullscreen == FULLSCREEN_LETTERBOX)
-        windowheight = LETTERBOX_SCREENHEIGHT * screenmultiply;
-    else
-        windowheight = SCREENHEIGHT * screenmultiply;
+    if (fullscreen)
+    {
+        if (!CheckValidFSMode(windowwidth, windowheight) && screenmultiply == 1)
+        {
+            // This is not a valid video mode.  Try doubling up the screen
+            // if we are running at 320x200.
+
+            printf("I_InitGraphics: Invalid mode %ix%i: turning on "
+                   "scale x2 mode (screenmultiply=2)\n",
+                   windowwidth, windowheight);
+
+            screenmultiply = 2;
+
+            GetWindowDimensions(&windowwidth, &windowheight);
+        }
+
+        if (!CheckValidFSMode(windowwidth, windowheight) && fullscreen == 1)
+        {
+            // This is not a valid mode.  Try turning on letterbox mode
+            // (640x400 -> 640x480)
+ 
+            printf("I_InitGraphics: Invalid mode %ix%i: turning on "
+                   "letterbox mode (fullscreen=2)\n",
+                   windowwidth, windowheight);
+
+            fullscreen = 2;
+
+            GetWindowDimensions(&windowwidth, &windowheight);
+        }
+
+        if (!CheckValidFSMode(windowwidth, windowheight))
+        {
+            printf("I_InitGraphics: WARNING: Unable to find a valid "
+                   "fullscreen video mode to run in.\n");
+        }
+    }
 
     screen = SDL_SetVideoMode(windowwidth, windowheight, 8, flags);