SDL: Support resizing the window when using the SDL1 GL renderer
Cameron Cawley ccawley2011@gmail.com
Sat, 04 May 2019 22:41:52 +0100
5 files changed,
24 insertions(+),
7 deletions(-)
M
src/platform/sdl/gl-common.c
→
src/platform/sdl/gl-common.c
@@ -51,9 +51,9 @@ }
#else SDL_GL_SetAttribute(SDL_GL_SWAP_CONTROL, 1); #ifdef COLOR_16_BIT - SDL_SetVideoMode(renderer->viewportWidth, renderer->viewportHeight, 16, SDL_OPENGL | (SDL_FULLSCREEN * renderer->fullscreen)); + SDL_SetVideoMode(renderer->viewportWidth, renderer->viewportHeight, 16, SDL_OPENGL | SDL_RESIZABLE | (SDL_FULLSCREEN * renderer->fullscreen)); #else - SDL_SetVideoMode(renderer->viewportWidth, renderer->viewportHeight, 32, SDL_OPENGL | (SDL_FULLSCREEN * renderer->fullscreen)); + SDL_SetVideoMode(renderer->viewportWidth, renderer->viewportHeight, 32, SDL_OPENGL | SDL_RESIZABLE | (SDL_FULLSCREEN * renderer->fullscreen)); #endif SDL_WM_SetCaption(projectName, ""); #endif
M
src/platform/sdl/gl-sdl.c
→
src/platform/sdl/gl-sdl.c
@@ -52,14 +52,18 @@
while (mCoreThreadIsActive(context)) { while (SDL_PollEvent(&event)) { mSDLHandleEvent(context, &renderer->player, &event); -#if SDL_VERSION_ATLEAST(2, 0, 0) // Event handling can change the size of the screen if (renderer->player.windowUpdated) { +#if SDL_VERSION_ATLEAST(2, 0, 0) SDL_GetWindowSize(renderer->window, &renderer->viewportWidth, &renderer->viewportHeight); +#else + renderer->viewportWidth = renderer->player.newWidth; + renderer->viewportHeight = renderer->player.newHeight; + mSDLGLCommonInit(renderer); +#endif mSDLGLDoViewport(renderer->viewportWidth, renderer->viewportHeight, v); renderer->player.windowUpdated = 0; } -#endif } renderer->core->desiredVideoDimensions(renderer->core, &renderer->width, &renderer->height); if (renderer->width != v->width || renderer->height != v->height) {
M
src/platform/sdl/gles2-sdl.c
→
src/platform/sdl/gles2-sdl.c
@@ -128,14 +128,18 @@
while (mCoreThreadIsActive(context)) { while (SDL_PollEvent(&event)) { mSDLHandleEvent(context, &renderer->player, &event); -#if SDL_VERSION_ATLEAST(2, 0, 0) // Event handling can change the size of the screen if (renderer->player.windowUpdated) { +#if SDL_VERSION_ATLEAST(2, 0, 0) SDL_GetWindowSize(renderer->window, &renderer->viewportWidth, &renderer->viewportHeight); +#else + renderer->viewportWidth = renderer->player.newWidth; + renderer->viewportHeight = renderer->player.newHeight; + mSDLGLCommonInit(renderer); +#endif mSDLGLDoViewport(renderer->viewportWidth, renderer->viewportHeight, v); renderer->player.windowUpdated = 0; } -#endif } if (mCoreSyncWaitFrameStart(&context->impl->sync)) {
M
src/platform/sdl/sdl-events.c
→
src/platform/sdl/sdl-events.c
@@ -601,6 +601,12 @@ #if SDL_VERSION_ATLEAST(2, 0, 0)
case SDL_WINDOWEVENT: _mSDLHandleWindowEvent(sdlContext, &event->window); break; +#else + case SDL_VIDEORESIZE: + sdlContext->newWidth = event->resize.w; + sdlContext->newHeight = event->resize.h; + sdlContext->windowUpdated = 1; + break; #endif case SDL_KEYDOWN: case SDL_KEYUP:
M
src/platform/sdl/sdl-events.h
→
src/platform/sdl/sdl-events.h
@@ -63,10 +63,10 @@ struct mSDLPlayer {
size_t playerId; struct mInputMap* bindings; struct SDL_JoystickCombo* joystick; + int windowUpdated; #if SDL_VERSION_ATLEAST(2, 0, 0) SDL_Window* window; int fullscreen; - int windowUpdated; struct mSDLRumble { struct mRumble d;@@ -76,6 +76,9 @@ int level;
float activeLevel; struct CircleBuffer history; } rumble; +#else + int newWidth; + int newHeight; #endif struct mSDLRotation {