From: Ingo Ruhnke Date: Thu, 31 Jul 2014 04:02:55 +0000 (+0200) Subject: Fixed window resize in OpenGL and added window resize to SDL renderer X-Git-Url: https://git.verplant.org/?a=commitdiff_plain;h=66d9193318e1ac804d0c32505b6715acbdce3301;p=supertux.git Fixed window resize in OpenGL and added window resize to SDL renderer --- diff --git a/src/supertux/main.cpp b/src/supertux/main.cpp index 3749a5cf0..15ac35b78 100644 --- a/src/supertux/main.cpp +++ b/src/supertux/main.cpp @@ -464,12 +464,6 @@ Main::init_rand() void Main::init_video() { - SCREEN_WIDTH = 800; - SCREEN_HEIGHT = 600; - - PHYSICAL_SCREEN_WIDTH = SCREEN_WIDTH; - PHYSICAL_SCREEN_HEIGHT = SCREEN_HEIGHT; - SDL_SetWindowTitle(Renderer::instance()->get_window(), PACKAGE_NAME " " PACKAGE_VERSION); const char* icon_fname = "images/engine/icons/supertux-256x256.png"; diff --git a/src/supertux/screen_manager.cpp b/src/supertux/screen_manager.cpp index add990f65..e1e7f124a 100644 --- a/src/supertux/screen_manager.cpp +++ b/src/supertux/screen_manager.cpp @@ -206,7 +206,7 @@ ScreenManager::process_events() break; case SDL_WINDOWEVENT: - switch(event.window.type) + switch(event.window.event) { case SDL_WINDOWEVENT_RESIZED: Renderer::instance()->resize(event.window.data1, diff --git a/src/video/gl/gl_renderer.cpp b/src/video/gl/gl_renderer.cpp index ba3a60165..ca7a477d1 100644 --- a/src/video/gl/gl_renderer.cpp +++ b/src/video/gl/gl_renderer.cpp @@ -21,8 +21,6 @@ #include #include #include "SDL.h" -//#include "SDL/SDL.h" -//#include "SDL/SDL_opengl.h" #include "supertux/gameconfig.hpp" #include "supertux/globals.hpp" @@ -36,6 +34,7 @@ #endif GLRenderer::GLRenderer() : + window(), desktop_size(-1, -1), screen_size(-1, -1), fullscreen_active(false), @@ -472,12 +471,11 @@ GLRenderer::flip() void GLRenderer::resize(int w, int h) { -#ifdef OLD_SDL1 - SDL_CreateWindow(SDL_GL_CreateContext(w, h, 0, SDL_WINDOW_OPENGL | SDL_WINDOW_RESIZABLE)); -#endif - g_config->window_size = Size(w, h); + PHYSICAL_SCREEN_WIDTH = w; + PHYSICAL_SCREEN_HEIGHT = h; + apply_config(); } @@ -607,35 +605,60 @@ GLRenderer::apply_config() void GLRenderer::apply_video_mode(const Size& size, bool fullscreen) { - // Only change video mode when its different from the current one - if (screen_size != size || fullscreen_active != fullscreen) + if (window) { - int flags = SDL_WINDOW_OPENGL; + SDL_SetWindowSize(window, size.width, size.height); if (fullscreen) { - flags |= SDL_WINDOW_FULLSCREEN; + int fullscreen_flags = SDL_WINDOW_FULLSCREEN; // SDL_WINDOW_FULLSCREEN_DESKTOP or 0 + SDL_SetWindowDisplayMode(window, NULL); + SDL_SetWindowFullscreen(window, fullscreen_flags); } else { - flags |= SDL_WINDOW_RESIZABLE; + SDL_SetWindowFullscreen(window, 0); } - - window = SDL_CreateWindow("SuperTux", - SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, - size.width, size.height, - flags); - if (!window) - { - std::ostringstream msg; - msg << "Couldn't set video mode " << size.width << "x" << size.height << ": " << SDL_GetError(); - throw std::runtime_error(msg.str()); - } - else + } + else + { + // Only change video mode when its different from the current one + if (screen_size != size || fullscreen_active != fullscreen) { - glcontext = SDL_GL_CreateContext(window); - screen_size = size; - fullscreen_active = fullscreen; + int flags = SDL_WINDOW_OPENGL; + + if (fullscreen) + { + flags |= SDL_WINDOW_FULLSCREEN; + } + else + { + flags |= SDL_WINDOW_RESIZABLE; + } + + window = SDL_CreateWindow("SuperTux", + SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, + size.width, size.height, + flags); + if (!window) + { + std::ostringstream msg; + msg << "Couldn't set video mode " << size.width << "x" << size.height << ": " << SDL_GetError(); + throw std::runtime_error(msg.str()); + } + else + { + glcontext = SDL_GL_CreateContext(window); + screen_size = size; + + PHYSICAL_SCREEN_WIDTH = size.width; + PHYSICAL_SCREEN_HEIGHT = size.height; + + SCREEN_WIDTH = size.width; + SCREEN_HEIGHT = size.height; + + fullscreen_active = fullscreen; + } } } } diff --git a/src/video/sdl/sdl_renderer.cpp b/src/video/sdl/sdl_renderer.cpp index ec15d307b..eb8a03129 100644 --- a/src/video/sdl/sdl_renderer.cpp +++ b/src/video/sdl/sdl_renderer.cpp @@ -39,7 +39,7 @@ SDLRenderer::SDLRenderer() : int width = g_config->window_size.width; int height = g_config->window_size.height; - int flags = 0; + int flags = SDL_WINDOW_RESIZABLE; if(g_config->use_fullscreen) { flags |= SDL_WINDOW_FULLSCREEN; @@ -47,6 +47,12 @@ SDLRenderer::SDLRenderer() : height = g_config->fullscreen_size.height; } + SCREEN_WIDTH = width; + SCREEN_HEIGHT = height; + + PHYSICAL_SCREEN_WIDTH = width; + PHYSICAL_SCREEN_HEIGHT = height; + int ret = SDL_CreateWindowAndRenderer(width, height, flags, &window, &renderer); @@ -432,9 +438,13 @@ SDLRenderer::flip() } void -SDLRenderer::resize(int, int) +SDLRenderer::resize(int w , int h) { - + SCREEN_WIDTH = w; + SCREEN_HEIGHT = h; + + PHYSICAL_SCREEN_WIDTH = w; + PHYSICAL_SCREEN_HEIGHT = h; } void