From d28e99d91376e338c5c7c63772ba9a5914f91bfc Mon Sep 17 00:00:00 2001 From: ehofman Date: Wed, 6 Apr 2005 08:46:39 +0000 Subject: [PATCH] Melchior FRANZ: Make SDL window resizable; This exposes the same problem that many GLUT users have: resizing up may cause a temporary switch to software rendering if the card is low on memory. Resizing down again switches back to HW rendering. (KSFO is texture intensive, but there are no problems in LOWL, and elsewhere.) Less and less users will have the problem as cards become better, and it's no reason not to allow resizing altogether. --- src/Main/fg_os_sdl.cxx | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/src/Main/fg_os_sdl.cxx b/src/Main/fg_os_sdl.cxx index 318c7d3b9..16ab62d22 100644 --- a/src/Main/fg_os_sdl.cxx +++ b/src/Main/fg_os_sdl.cxx @@ -15,6 +15,7 @@ static fgIdleHandler IdleHandler = 0; static fgDrawHandler DrawHandler = 0; +static fgWindowResizeHandler WindowResizeHandler = 0; static fgKeyHandler KeyHandler = 0; static fgMouseClickHandler MouseClickHandler = 0; static fgMouseMotionHandler MouseMotionHandler = 0; @@ -24,6 +25,7 @@ static int CurrentMouseX = 0; static int CurrentMouseY = 0; static int CurrentMouseCursor = MOUSE_CURSOR_POINTER; static bool NeedRedraw = false; +static int VidMask = SDL_OPENGL|SDL_RESIZABLE; void fgRegisterIdleHandler(fgIdleHandler func) { @@ -38,7 +40,7 @@ void fgRegisterDrawHandler(fgDrawHandler func) void fgRegisterWindowResizeHandler(fgWindowResizeHandler func) { - // Noop. SDL does not support window resize. + WindowResizeHandler = func; } void fgRegisterKeyHandler(fgKeyHandler func) @@ -84,11 +86,10 @@ void fgOSOpenWindow(int w, int h, int bpp, SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, zbits); SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1); - int vidmask = SDL_OPENGL; if(fullscreen) { - vidmask |= SDL_FULLSCREEN; + VidMask |= SDL_FULLSCREEN; } - if (SDL_SetVideoMode(w, h, 16, vidmask) == 0) + if (SDL_SetVideoMode(w, h, 16, VidMask) == 0) throw sg_throwable(string("Failed to set SDL video mode: ") + SDL_GetError()); @@ -214,6 +215,14 @@ void fgOSMainLoop() if(MouseMotionHandler) (*MouseMotionHandler)(e.motion.x, e.motion.y); break; + case SDL_VIDEORESIZE: + if (SDL_SetVideoMode(e.resize.w, e.resize.h, 16, VidMask) == 0) + throw sg_throwable(string("Failed to set SDL video mode: ") + + SDL_GetError()); + + if (WindowResizeHandler) + (*WindowResizeHandler)(e.resize.w, e.resize.h); + break; } } if(IdleHandler) (*IdleHandler)(); -- 2.39.5