Make dhewm3 window resizable (when using SDL2)

is this really all that's needed?!
This commit is contained in:
Daniel Gibson 2024-06-07 20:50:48 +02:00
parent 28b753d50b
commit ab676878b9
4 changed files with 22 additions and 9 deletions

View file

@ -1115,6 +1115,9 @@ const int GRAB_RELATIVEMOUSE = (1 << 2);
void GLimp_GrabInput(int flags);
bool GLimp_SetSwapInterval( int swapInterval );
void GLimp_UpdateWindowSize();
/*
====================================================================

View file

@ -1156,6 +1156,9 @@ sysEvent_t Sys_GetEvent() {
case SDL_WINDOWEVENT_FOCUS_LOST:
in_hasFocus = false;
break;
case SDL_WINDOWEVENT_SIZE_CHANGED:
GLimp_UpdateWindowSize();
break;
}
continue; // handle next event

View file

@ -166,6 +166,7 @@ bool GLimp_Init(glimpParms_t parms) {
#if SDL_VERSION_ATLEAST(2, 0, 0)
flags |= SDL_WINDOW_ALLOW_HIGHDPI;
flags |= SDL_WINDOW_RESIZABLE;
/* Doom3 has the nasty habit of modifying the default framebuffer's alpha channel and then
* relying on those modifications in blending operations (using GL_DST_(ONE_MINUS_)ALPHA).
@ -410,21 +411,17 @@ try_again:
r_swapInterval.ClearModified();
// for HighDPI, window size and drawable size can differ
int ww=0, wh=0;
SDL_GetWindowSize(window, &ww, &wh);
glConfig.winWidth = ww;
glConfig.winHeight = wh;
SDL_GL_GetDrawableSize(window, &glConfig.vidWidth, &glConfig.vidHeight);
GLimp_UpdateWindowSize();
SetSDLIcon(); // for SDL2 this must be done after creating the window
glConfig.isFullscreen = (SDL_GetWindowFlags(window) & SDL_WINDOW_FULLSCREEN) == SDL_WINDOW_FULLSCREEN;
const char* fsStr = glConfig.isFullscreen ? "fullscreen " : "";
if ( ww != glConfig.vidWidth ) {
common->Printf( "Got a HighDPI %swindow with physical resolution %d x %d and virtual resolution %d x %d\n",
fsStr, glConfig.vidWidth, glConfig.vidHeight, ww, wh );
if ( (int)glConfig.winWidth != glConfig.vidWidth ) {
common->Printf( "Got a HighDPI %swindow with physical resolution %d x %d and virtual resolution %g x %g\n",
fsStr, glConfig.vidWidth, glConfig.vidHeight, glConfig.winWidth, glConfig.winHeight );
} else {
common->Printf( "Got a %swindow with resolution %d x %d\n", fsStr, ww, wh );
common->Printf( "Got a %swindow with resolution %g x %g\n", fsStr, glConfig.winWidth, glConfig.winHeight );
}
#else
SDL_WM_SetCaption(ENGINE_VERSION, ENGINE_VERSION);
@ -770,3 +767,12 @@ bool GLimp_SetSwapInterval( int swapInterval )
return false;
#endif
}
void GLimp_UpdateWindowSize()
{
int ww=0, wh=0;
SDL_GetWindowSize( window, &ww, &wh );
glConfig.winWidth = ww;
glConfig.winHeight = wh;
SDL_GL_GetDrawableSize( window, &glConfig.vidWidth, &glConfig.vidHeight );
}

View file

@ -398,6 +398,7 @@ void GLimp_ActivateContext() {};
void GLimp_DeactivateContext() {};
void GLimp_GrabInput(int flags) {};
bool GLimp_SetSwapInterval( int swapInterval ) { return false; }
void GLimp_UpdateWindowSize() {}
#ifdef _MSC_VER
#pragma warning(pop)