From 29081acc94b73e7640c6ea4221bbd0dd609eb3fa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Mon, 15 Feb 2016 22:31:24 +0100 Subject: [PATCH] Platform: avoid window blinking with multiple context creation attempts. The window is only shown once we are sure that everything went smoothly. --- src/Magnum/Platform/Sdl2Application.cpp | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/src/Magnum/Platform/Sdl2Application.cpp b/src/Magnum/Platform/Sdl2Application.cpp index 361a522b1..0f579fa31 100644 --- a/src/Magnum/Platform/Sdl2Application.cpp +++ b/src/Magnum/Platform/Sdl2Application.cpp @@ -158,7 +158,8 @@ bool Sdl2Application::tryCreateContext(const Configuration& configuration) { #endif } - /* Create window */ + /* Create window. Hide it by default so we don't have distracting window + blinking in case we have to destroy it again right away */ if(!(_window = SDL_CreateWindow( #ifndef CORRADE_TARGET_IOS configuration.title().data(), @@ -167,7 +168,7 @@ bool Sdl2Application::tryCreateContext(const Configuration& configuration) { #endif SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, configuration.size().x(), configuration.size().y(), - SDL_WINDOW_OPENGL|Uint32(configuration.windowFlags())))) + SDL_WINDOW_OPENGL|SDL_WINDOW_HIDDEN|Uint32(configuration.windowFlags())))) { Error() << "Platform::Sdl2Application::tryCreateContext(): cannot create window:" << SDL_GetError(); return false; @@ -213,7 +214,7 @@ bool Sdl2Application::tryCreateContext(const Configuration& configuration) { if(!(_window = SDL_CreateWindow(configuration.title().data(), SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, configuration.size().x(), configuration.size().y(), - SDL_WINDOW_OPENGL|Uint32(configuration.windowFlags())))) + SDL_WINDOW_OPENGL|SDL_WINDOW_HIDDEN|Uint32(configuration.windowFlags())))) { Error() << "Platform::Sdl2Application::tryCreateContext(): cannot create window:" << SDL_GetError(); return false; @@ -251,7 +252,15 @@ bool Sdl2Application::tryCreateContext(const Configuration& configuration) { #endif /* Return true if the initialization succeeds */ - return _context->tryCreate(); + const bool created = _context->tryCreate(); + + #ifndef CORRADE_TARGET_EMSCRIPTEN + /* Show the window once we are sure that everything is okay */ + if(created && !(configuration.windowFlags() & Configuration::WindowFlag::Hidden)) + SDL_ShowWindow(_window); + #endif + + return created; } void Sdl2Application::swapBuffers() {