diff --git a/BBGE/Core.cpp b/BBGE/Core.cpp index 7f6e78e..200616f 100644 --- a/BBGE/Core.cpp +++ b/BBGE/Core.cpp @@ -156,6 +156,7 @@ void Core::setup_opengl() void Core::resizeWindow(int w, int h, int full, int bpp, int vsync, int display, int hz) { window->open(w, h, full, bpp, vsync, display, hz); + window->updateSize(); } void Core::updateWindowDrawSize(int w, int h) @@ -723,7 +724,7 @@ void Core::initGraphicsLibrary(int width, int height, bool fullscreen, bool vsyn enumerateScreenModes(window->getDisplayIndex()); - window->initSize(); + window->updateSize(); cacheRender(); // Clears the window bg to black early; prevents flickering lib_graphics = true; } diff --git a/BBGE/Window.cpp b/BBGE/Window.cpp index 195439a..de2e8ce 100644 --- a/BBGE/Window.cpp +++ b/BBGE/Window.cpp @@ -44,7 +44,7 @@ void Window::onQuit() void Window::setFullscreen(bool on) { - if(_full != on) + if(!!_full != on) open(-1, -1, on, -1, -1, -1, -1); } @@ -52,15 +52,17 @@ void Window::open(int w, int h, int full, int bpp, int vsync, int display, int h { _fixOpenParams(w, h, full, bpp, vsync, display, hz); - if(isOpen()) - _adjust(w, h, !!full, bpp, !!vsync, display, hz); - else - _open(w, h, !!full, bpp, !!vsync, display, hz); - _w = w; _h = h; _display = display; _bpp = bpp; + _full = !!full; + _vsync = !!vsync; + + if(isOpen()) + _adjust(w, h, !!full, bpp, !!vsync, display, hz); + else + _open(w, h, !!full, bpp, !!vsync, display, hz); } void Window::_fixOpenParams(int& w, int& h, int& full, int& bpp, int& vsync, int& display, int& hz) diff --git a/BBGE/Window.h b/BBGE/Window.h index bca6879..d3f35fd 100644 --- a/BBGE/Window.h +++ b/BBGE/Window.h @@ -23,7 +23,7 @@ public: int getDisplayIndex() const; // -1 on error/unsupported int getRefreshRate() const { return _hz; } void warpMouse(int x, int y); - void initSize(); + void updateSize(); inline bool isFullscreen() const { return _full; } bool isOpen() const; diff --git a/BBGE/Window_SDL1.cpp b/BBGE/Window_SDL1.cpp index a107e2c..b7d18b0 100644 --- a/BBGE/Window_SDL1.cpp +++ b/BBGE/Window_SDL1.cpp @@ -129,7 +129,7 @@ void Window::_onEventImpl(const SDL_Event& ev) } } -void Window::initSize() +void Window::updateSize() { onResize(WIN->w, WIN->h); } diff --git a/BBGE/Window_SDL2.cpp b/BBGE/Window_SDL2.cpp index 99240bc..1534527 100644 --- a/BBGE/Window_SDL2.cpp +++ b/BBGE/Window_SDL2.cpp @@ -100,31 +100,29 @@ void Window::_adjust(unsigned w, unsigned h, bool full, unsigned bpp, bool vsync const bool useDesktop = w == 0 || h == 0; SDL_DisplayMode displaymode; - if(SDL_GetDesktopDisplayMode(display, &displaymode) != 0) + if(useDesktop) { - // fail-safe - displaymode.w = 800; - displaymode.h = 600; - displaymode.driverdata = 0; - displaymode.refresh_rate = 0; - displaymode.format = 0; - display = 0; + if(SDL_GetDesktopDisplayMode(display, &displaymode) != 0) + { + // Failed to get this; use sane defaults + displaymode.w = 800; + displaymode.h = 600; + displaymode.driverdata = 0; + displaymode.refresh_rate = 0; + displaymode.format = 0; + display = 0; + } + w = displaymode.w; + h = displaymode.h; } setvsync(vsync); - if(useDesktop) - { - w = 800; - h = 600; - } - if(full) { int screenflags = useDesktop ? SDL_WINDOW_FULLSCREEN_DESKTOP : SDL_WINDOW_FULLSCREEN; - displaymode.w = w; - displaymode.h = h; // must not be already in fullscreen here, otherwise new display mode doesn't apply properly + SDL_SetWindowFullscreen(WIN, 0); SDL_SetWindowDisplayMode(WIN, &displaymode); SDL_SetWindowFullscreen(WIN, screenflags); } @@ -140,7 +138,7 @@ void Window::_adjust(unsigned w, unsigned h, bool full, unsigned bpp, bool vsync } } -void Window::initSize() +void Window::updateSize() { int ww, hh; SDL_GetWindowSize(WIN, &ww, &hh);