changeset 3488:3d2f42580488

Fixed bug #771 Cleaned up the code a bit and made sure that an OpenGL window gets the OpenGL renderer. Inspired by a patch from Mason Wheeler.
author Sam Lantinga <slouken@libsdl.org>
date Tue, 24 Nov 2009 16:43:18 +0000
parents 24d13328c44a
children e1bd98b56e94
files src/video/SDL_video.c
diffstat 1 files changed, 23 insertions(+), 20 deletions(-) [+]
line wrap: on
line diff
--- a/src/video/SDL_video.c	Tue Nov 24 08:12:32 2009 +0000
+++ b/src/video/SDL_video.c	Tue Nov 24 16:43:18 2009 +0000
@@ -1490,31 +1490,35 @@
     SDL_DestroyRenderer(windowID);
 
     if (index < 0) {
-        const char *override = SDL_getenv("SDL_VIDEO_RENDERER");
+        char *override = SDL_getenv("SDL_VIDEO_RENDERER");
+        int n = SDL_GetNumRenderDrivers();
+
+        if (!override && (window->flags & SDL_WINDOW_OPENGL)) {
+            override = "opengl";
+        }
         if (override) {
-            int i, n = SDL_GetNumRenderDrivers();
-            for (i = 0; i < n; ++i) {
+            for (index = 0; index < n; ++index) {
                 SDL_RenderDriver *driver =
-                    &SDL_CurrentDisplay.render_drivers[i];
+                    &SDL_CurrentDisplay.render_drivers[index];
+
                 if (SDL_strcasecmp(override, driver->info.name) == 0) {
-                    index = i;
+                    /* Create a new renderer instance */
+                    window->renderer = driver->CreateRenderer(window, flags);
                     break;
                 }
             }
-        }
-    }
-    if (index < 0) {
-        int n = SDL_GetNumRenderDrivers();
-        for (index = 0; index < n; ++index) {
-            SDL_RenderDriver *driver =
-                &SDL_CurrentDisplay.render_drivers[index];
-
-            if ((driver->info.flags & flags) == flags) {
-                /* Create a new renderer instance */
-                window->renderer = SDL_CurrentDisplay.render_drivers[index].CreateRenderer(window, flags);
-                if (window->renderer) {
-                    /* Yay, we got one! */
-                    break;
+        } else {
+            for (index = 0; index < n; ++index) {
+                SDL_RenderDriver *driver =
+                    &SDL_CurrentDisplay.render_drivers[index];
+
+                if ((driver->info.flags & flags) == flags) {
+                    /* Create a new renderer instance */
+                    window->renderer = driver->CreateRenderer(window, flags);
+                    if (window->renderer) {
+                        /* Yay, we got one! */
+                        break;
+                    }
                 }
             }
         }
@@ -1528,7 +1532,6 @@
                          SDL_GetNumRenderDrivers() - 1);
             return -1;
         }
-
         /* Create a new renderer instance */
         window->renderer = SDL_CurrentDisplay.render_drivers[index].CreateRenderer(window, flags);
     }