Skip to content

Commit

Permalink
Add r_windowResizable to configure if window is resizable
Browse files Browse the repository at this point in the history
incl. setting in SettingsMenu

With SDL 2.0.5 and newer this change is applied immediately,
2.0.0 to 2.0.4 need a vid_restart
(with SDL1.2 we don't support it at all)
  • Loading branch information
DanielGibson committed Jun 8, 2024
1 parent a6870ca commit 6f5f5ec
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 2 deletions.
1 change: 1 addition & 0 deletions neo/framework/Dhewm3SettingsMenu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1651,6 +1651,7 @@ static CVarOption videoOptionsImmediately[] = {
}
AddCVarOptionTooltips( cvar, descr );
} ),
CVarOption( "r_windowResizable", "Make dhewm3 window resizable", OT_BOOL ),
CVarOption( "r_brightness", "Brightness", OT_FLOAT, 0.5f, 2.0f ),
CVarOption( "r_gamma", "Gamma", OT_FLOAT, 0.5f, 3.0f ),
CVarOption( "r_gammaInShader", "Apply gamma and brightness in shaders", OT_BOOL ),
Expand Down
5 changes: 5 additions & 0 deletions neo/renderer/RenderSystem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,11 @@ static void R_CheckCvars( void ) {
GLimp_SetSwapInterval( r_swapInterval.GetInteger() );
r_swapInterval.ClearModified();
}

if ( r_windowResizable.IsModified() ) {
GLimp_SetWindowResizable( r_windowResizable.GetBool() );
r_windowResizable.ClearModified();
}
}

/*
Expand Down
2 changes: 2 additions & 0 deletions neo/renderer/RenderSystem_init.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,8 @@ idCVar r_useStencilOpSeparate( "r_useStencilOpSeparate", "1", CVAR_RENDERER | CV
idCVar r_screenshotFormat("r_screenshotFormat", "0", CVAR_RENDERER | CVAR_ARCHIVE | CVAR_INTEGER, "Screenshot format. 0 = TGA (default), 1 = BMP, 2 = PNG, 3 = JPG");
idCVar r_screenshotJpgQuality("r_screenshotJpgQuality", "75", CVAR_RENDERER | CVAR_ARCHIVE | CVAR_INTEGER, "Screenshot quality for JPG images (1-100). Lower value means smaller file but worse quality");
idCVar r_screenshotPngCompression("r_screenshotPngCompression", "3", CVAR_RENDERER | CVAR_ARCHIVE | CVAR_INTEGER, "Compression level when using PNG screenshots (0-9). Higher levels generate smaller files, but take noticeably longer");
// DG: allow freely resizing the window
idCVar r_windowResizable("r_windowResizable", "1", CVAR_RENDERER | CVAR_ARCHIVE | CVAR_BOOL, "Allow resizing (and maximizing) the window (needs SDL2; with 2.0.5 or newer it's applied immediately)" );

// define qgl functions
#define QGLPROC(name, rettype, args) rettype (APIENTRYP q##name) args;
Expand Down
3 changes: 2 additions & 1 deletion neo/renderer/tr_local.h
Original file line number Diff line number Diff line change
Expand Up @@ -818,6 +818,7 @@ extern idCVar r_displayRefresh; // optional display refresh rate option for vi
extern idCVar r_fullscreen; // 0 = windowed, 1 = full screen
extern idCVar r_fullscreenDesktop; // 0: 'real' fullscreen mode 1: keep resolution 'desktop' fullscreen mode
extern idCVar r_multiSamples; // number of antialiasing samples
extern idCVar r_windowResizable; // DG: allow resizing and maximizing the window

extern idCVar r_ignore; // used for random debugging without defining new vars
extern idCVar r_ignore2; // used for random debugging without defining new vars
Expand Down Expand Up @@ -1115,7 +1116,7 @@ const int GRAB_RELATIVEMOUSE = (1 << 2);
void GLimp_GrabInput(int flags);

bool GLimp_SetSwapInterval( int swapInterval );

bool GLimp_SetWindowResizable( bool enableResizable );
void GLimp_UpdateWindowSize();

/*
Expand Down
19 changes: 18 additions & 1 deletion neo/sys/glimp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -164,9 +164,13 @@ bool GLimp_Init(glimpParms_t parms) {
flags |= SDL_WINDOW_FULLSCREEN;
}

r_windowResizable.ClearModified();
#if SDL_VERSION_ATLEAST(2, 0, 0)
flags |= SDL_WINDOW_ALLOW_HIGHDPI;
flags |= SDL_WINDOW_RESIZABLE;

if ( r_windowResizable.GetBool() ) {
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).
Expand Down Expand Up @@ -768,11 +772,24 @@ bool GLimp_SetSwapInterval( int swapInterval )
#endif
}

bool GLimp_SetWindowResizable( bool enableResizable )
{
#if SDL_VERSION_ATLEAST(2, 0, 5)
SDL_SetWindowResizable( window, (SDL_bool)enableResizable );
return true;
#else
common->Warning( "dhewm3 must be built with SDL 2.0.5 or newer to change resizability of existing windows!" );
return false;
#endif
}

void GLimp_UpdateWindowSize()
{
#if SDL_VERSION_ATLEAST(2, 0, 0)
int ww=0, wh=0;
SDL_GetWindowSize( window, &ww, &wh );
glConfig.winWidth = ww;
glConfig.winHeight = wh;
SDL_GL_GetDrawableSize( window, &glConfig.vidWidth, &glConfig.vidHeight );
#endif
}
1 change: 1 addition & 0 deletions neo/sys/stub/stub_gl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -399,6 +399,7 @@ void GLimp_DeactivateContext() {};
void GLimp_GrabInput(int flags) {};
bool GLimp_SetSwapInterval( int swapInterval ) { return false; }
void GLimp_UpdateWindowSize() {}
bool GLimp_SetWindowResizable( bool enableResizable ) { return false; }

#ifdef _MSC_VER
#pragma warning(pop)
Expand Down

0 comments on commit 6f5f5ec

Please sign in to comment.