We are currently migrating Bugzilla to GitHub issues.
Any changes made to the bug tracker now will be lost, so please do not post new bugs or make changes to them.
When we're done, all bug URLs will redirect to their equivalent location on the new bug tracker.

Bug 771

Summary: Patch to ensure that a GL window gets a GL renderer
Product: SDL Reporter: Mason Wheeler <masonwheeler>
Component: videoAssignee: Ryan C. Gordon <icculus>
Status: RESOLVED FIXED QA Contact: Sam Lantinga <slouken>
Severity: normal    
Priority: P2    
Version: 2.0.0   
Hardware: x86   
OS: Windows Vista   

Description Mason Wheeler 2009-07-19 22:34:35 UTC
Due to the way SDL_CreateRenderer works, it's quite possible for a window created with the OpenGL flag to end up with a non-OpenGL renderer.  This patch corrects that.

===================================================================
--- C:/Users/Mason/Documents/SDL-1.3/SDL-1.3.0-4423/src/video/SDL_video.c	(revision 4624)
+++ C:/Users/Mason/Documents/SDL-1.3/SDL-1.3.0-4423/src/video/SDL_video.c	(working copy)
@@ -1473,8 +1473,11 @@
         return -1;
     }
     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";
+        }
         for (index = 0; index < n; ++index) {
             SDL_RenderDriver *driver =
                 &SDL_CurrentDisplay.render_drivers[index];
Comment 1 Mason Wheeler 2009-11-24 03:29:31 UTC
(In reply to comment #0)
Updated the patch code to work with newer revisions:

--- \src\video\SDL_video.c	2009-11-24 03:22:58.000000000 -0800
+++ \src\video\SDL_video.c	2009-11-24 03:20:38.000000000 -0800
@@ -1487,27 +1487,28 @@
     }
 
     /* Free any existing renderer */
     SDL_DestroyRenderer(windowID);
 
     if (index < 0) {
-        const char *override = SDL_getenv("SDL_VIDEO_RENDERER");
-        if (override) {
-            int i, n = SDL_GetNumRenderDrivers();
+        char *override = SDL_getenv("SDL_VIDEO_RENDERER");
+        int n = SDL_GetNumRenderDrivers();
+		if ((!override) && (window->flags & SDL_WINDOW_OPENGL)){
+			override = "opengl";
+		}
+		if (override) {
+            int i;
             for (i = 0; i < n; ++i) {
                 SDL_RenderDriver *driver =
                     &SDL_CurrentDisplay.render_drivers[i];
                 if (SDL_strcasecmp(override, driver->info.name) == 0) {
                     index = i;
                     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 */
Comment 2 Sam Lantinga 2009-11-24 08:43:47 UTC
I cleaned up the code a bit and committed it.  Can you make sure it still solves your bug?

Thanks!