From 22785c4e7eb0be49a795f4b2bcdf5cbda1626a5a Mon Sep 17 00:00:00 2001 From: Stijn Buys Date: Tue, 6 Jan 2015 21:12:09 +0000 Subject: Corrected a window resize issue. --- src/client/input.cc | 2 +- src/client/video.cc | 31 ++++++++++++++++++++----------- src/client/video.h | 4 +++- 3 files changed, 24 insertions(+), 13 deletions(-) diff --git a/src/client/input.cc b/src/client/input.cc index 9b2521e..0ffffad 100644 --- a/src/client/input.cc +++ b/src/client/input.cc @@ -790,7 +790,7 @@ void frame() case SDL_WINDOWEVENT: if (event.window.event == SDL_WINDOWEVENT_RESIZED) { - video::resize(event.window.data1, event.window.data2); + video::resize(event.window.windowID, event.window.data1, event.window.data2); } break; diff --git a/src/client/video.cc b/src/client/video.cc index f3ba136..b7eb325 100644 --- a/src/client/video.cc +++ b/src/client/video.cc @@ -52,6 +52,7 @@ const int height_default = 768; SDL_Window* sdlwindow = 0; Uint32 sdlwindow_flags = 0; +SDL_GLContext glcontext = 0; std::string loader_message; bool is_loading = false; @@ -167,7 +168,7 @@ bool init() } else { - if (r_windowwidth->value() && r_windowheight->value()) + if ((r_windowwidth->value() > 0.0f) && (r_windowheight->value() > 0.0f)) { width = (int) r_windowwidth->value(); height = (int) r_windowheight->value(); @@ -177,10 +178,7 @@ bool init() width = width_default; height = height_default; } - sdlwindow_flags = SDL_WINDOW_OPENGL; -#ifndef _WIN32 - sdlwindow_flags |= SDL_WINDOW_RESIZABLE; -#endif + sdlwindow_flags = SDL_WINDOW_OPENGL | SDL_WINDOW_RESIZABLE; sdlwindow = SDL_CreateWindow(sdlwindow_title.c_str(), SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, width, height, sdlwindow_flags); } @@ -190,7 +188,7 @@ bool init() return false; } - SDL_GLContext glcontext = SDL_GL_CreateContext(sdlwindow); + glcontext = SDL_GL_CreateContext(sdlwindow); if (!glcontext) { con_error << "Failed to initialize OpenGL context: " << SDL_GetError() << std::endl; @@ -204,8 +202,8 @@ bool init() (*r_width) = width; (*r_height) = height; } else { - (*r_windowwidth) = width; - (*r_windowwidth) = height; + (*r_windowwidth) = (float) width; + (*r_windowheight) = (float) height; } // resize user interface ui::root()->set_size((float) width, (float) height); @@ -234,11 +232,18 @@ bool init() return true; } -void resize(int w, int h) +void resize(const Uint32 sdlwindow_id, int w, int h) { if (fullscreen) + { return; + } + if (SDL_GetWindowID(sdlwindow) != sdlwindow_id) + { + return; + } + if (w < 320) w = 320; if (h < 200) h = 200; @@ -246,8 +251,8 @@ void resize(int w, int h) ui::root()->set_size(w, h); ui::root()->event_resize(); - (*r_windowwidth) = w; - (*r_windowwidth) = h; + (*r_windowwidth) = (float) w; + (*r_windowheight) = (float) h; } void restart() @@ -377,7 +382,11 @@ void shutdown() SDL_SetRelativeMouseMode(SDL_FALSE); + SDL_GL_DeleteContext(glcontext); + glcontext = 0; + SDL_DestroyWindow(sdlwindow); + sdlwindow = 0; SDL_QuitSubSystem(SDL_INIT_VIDEO); diff --git a/src/client/video.h b/src/client/video.h index 195fd2d..4d408ba 100644 --- a/src/client/video.h +++ b/src/client/video.h @@ -9,6 +9,8 @@ #include "core/cvar.h" +#include "SDL2/SDL.h" + namespace client { @@ -28,7 +30,7 @@ void shutdown(); void restart(); /// application window resize event in windowed mode -void resize(int w, int h); +void resize(const Uint32 sdlwindow_id, int w, int h); /// draw the next client video frame void frame(float elapsed); -- cgit v1.2.3