# HG changeset patch # User Sam Lantinga # Date 1259080998 0 # Node ID 3d2f42580488560a7f45c4ccf0ae09061ee8cc2e # Parent 24d13328c44a7bc0cf1b09c0b9b5a5954a509d5b 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. diff -r 24d13328c44a -r 3d2f42580488 src/video/SDL_video.c --- 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); }