From d0d02502eab2470bb107fb384c809f0d57b955f0 Mon Sep 17 00:00:00 2001
From: Allanis <allanis@saracraft.net>
Date: Sat, 17 May 2014 14:45:11 +0100
Subject: [PATCH] [Change] Never try to create a screen aboe the players
 resolution unless she forces it to.

---
 src/opengl.c | 21 ++++++++++++++++++---
 1 file changed, 18 insertions(+), 3 deletions(-)

diff --git a/src/opengl.c b/src/opengl.c
index 72163b9..d37cc21 100644
--- a/src/opengl.c
+++ b/src/opengl.c
@@ -1040,10 +1040,12 @@ void gl_checkErr(void) {
 int gl_init(void) {
   int doublebuf, depth, i, j, off, toff, supported, fsaa;
   SDL_Rect** modes;
-  int flags = SDL_OPENGL;
-  flags |= SDL_FULLSCREEN * (gl_has(OPENGL_FULLSCREEN) ? 1: 0);
+  int flags;
 
+  /* Defaults. */
   supported  = 0;
+  flags = SDL_OPENGL;
+  flags |= SDL_FULLSCREEN * (gl_has(OPENGL_FULLSCREEN) ? 1 : 0);
 
   /* Initializes video. */
   if(SDL_InitSubSystem(SDL_INIT_VIDEO) < 0) {
@@ -1051,6 +1053,9 @@ int gl_init(void) {
     return -1;
   }
 
+  /* Get the video information. */
+  const SDL_VideoInfo* vidinfo = SDL_GetVideoInfo();
+
   /* Set opengl flags. */
   SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1); /* Ideally want double buffering. */
   if(gl_has(OPENGL_FSAA)) {
@@ -1064,7 +1069,6 @@ int gl_init(void) {
     /* Try to use desktop resolution if nothing is specifically set. */
 #if SDL_VERSION_ATLEAST(1,2,10)
     if(!gl_has(OPENGL_DIM_DEF)) {
-      const SDL_VideoInfo* vidinfo = SDL_GetVideoInfo();
       gl_screen.w = vidinfo->current_w;
       gl_screen.h = vidinfo->current_h;
     }
@@ -1112,6 +1116,17 @@ int gl_init(void) {
     }
   }
 
+  /*
+   * Check to see if trying to create above screen resolution without player
+   * asking for such a large size.
+   */
+#if SDL_VERSION_ATLEAST(1, 2, 10)
+  if(!gl_has(OPENGL_DIM_DEF)) {
+    gl_screen.w = MIN(gl_screen.w, vidinfo->current_w);
+    gl_screen.h = MIN(gl_screen.h, vidinfo->current_h);
+  }
+#endif
+
   /* Test the setup - aim for 32. */
   gl_screen.depth = 32;
   depth = SDL_VideoModeOK(SCREEN_W, SCREEN_H, gl_screen.depth, flags);