SDL: Support resizing the window when using the SDL1 GL renderer

This commit is contained in:
Cameron Cawley 2019-05-04 22:41:52 +01:00 committed by endrift
parent 3a6756b399
commit 36ad461ee0
5 changed files with 24 additions and 7 deletions

View File

@ -51,9 +51,9 @@ void mSDLGLCommonInit(struct mSDLRenderer* renderer) {
#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

View File

@ -52,14 +52,18 @@ void mSDLGLRunloop(struct mSDLRenderer* renderer, void* user) {
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) {

View File

@ -128,14 +128,18 @@ void mSDLGLES2Runloop(struct mSDLRenderer* renderer, void* user) {
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)) {

View File

@ -601,6 +601,12 @@ void mSDLHandleEvent(struct mCoreThread* context, struct mSDLPlayer* sdlContext,
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:

View File

@ -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 @@ struct mSDLPlayer {
float activeLevel;
struct CircleBuffer history;
} rumble;
#else
int newWidth;
int newHeight;
#endif
struct mSDLRotation {