Skip to content

Commit

Permalink
Add workarounds for widescreen.
Browse files Browse the repository at this point in the history
New cvars:
	- cl_widescreenHUD	-> project cgame pictures and scenes onto a 4:3 area in the center of the screen
	- cl_widescreenMenu	-> project ui pictures and scenes onto a 4:3 area in the center of the screen (set to 2 to disable in main menu)
	- cl_widescreenFOV	-> try to adjust cgame fullscreen scenes to use vertical fov when the aspect ratio is wider than 4:3
  • Loading branch information
Daggolin committed Sep 18, 2021
1 parent 09e7b61 commit 58689b3
Show file tree
Hide file tree
Showing 4 changed files with 88 additions and 2 deletions.
23 changes: 22 additions & 1 deletion code/client/cl_cgame.c
Original file line number Diff line number Diff line change
Expand Up @@ -596,13 +596,34 @@ intptr_t CL_CgameSystemCalls( intptr_t *args ) {
return 0;
#endif
case CG_R_RENDERSCENE:
refdef_t *ref = (refdef_t*)VMA(1);
if ( cl_widescreenHUD->integer && (ref->width != cls.glconfig.vidWidth || ref->height != cls.glconfig.vidHeight) )
{ // When not rendering a fullscreen scene scale it
ref->x = ref->x * cls.ws_xscale + cls.ws_xoffs;
ref->y = ref->y * cls.ws_yscale + cls.ws_yoffs;
ref->width *= cls.ws_xscale;
ref->height *= cls.ws_yscale;
}
else if ( cl_widescreenFOV->integer && (ref->width == cls.glconfig.vidWidth && ref->height == cls.glconfig.vidHeight) )
{ // Fullscreen scene: adjust FOV
// NOTE: This might break the underwater effect on the default cgame module and possible other effects added by custom cgame modules.
if ( cls.glconfig.vidWidth * 3 > cls.glconfig.vidHeight * 4 )
{ // Adjust fov (fau's algorithm used in mvsdk)
float x = cls.ws_width / tan(DEG2RAD(0.5f * ref->fov_x));
ref->fov_x = RAD2DEG(2 * atan2(ref->width, x));
ref->fov_y = RAD2DEG(2 * atan2(ref->height, x));
}
}
re.RenderScene( VMA(1) );
return 0;
case CG_R_SETCOLOR:
re.SetColor( VMA(1) );
return 0;
case CG_R_DRAWSTRETCHPIC:
re.DrawStretchPic( VMF(1), VMF(2), VMF(3), VMF(4), VMF(5), VMF(6), VMF(7), VMF(8), args[9] );
if ( cl_widescreenHUD->integer )
re.DrawStretchPic( VMF(1) * cls.ws_xscale + cls.ws_xoffs, VMF(2) * cls.ws_yscale + cls.ws_yoffs, VMF(3) * cls.ws_xscale, VMF(4) * cls.ws_yscale, VMF(5), VMF(6), VMF(7), VMF(8), args[9] );
else
re.DrawStretchPic( VMF(1), VMF(2), VMF(3), VMF(4), VMF(5), VMF(6), VMF(7), VMF(8), args[9] );
return 0;
case CG_R_MODELBOUNDS:
re.ModelBounds( args[1], VMA(2), VMA(3) );
Expand Down
40 changes: 40 additions & 0 deletions code/client/cl_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,10 @@ cvar_t *cl_consoleKeys;
cvar_t *cl_consoleUseScanCode;
cvar_t *cl_consoleShiftRequirement;

cvar_t *cl_widescreenHUD;
cvar_t *cl_widescreenMenu;
cvar_t *cl_widescreenFOV;

cvar_t *cl_rate;

clientActive_t cl;
Expand Down Expand Up @@ -3225,6 +3229,7 @@ CL_InitRenderer
void CL_InitRenderer( void ) {
// this sets up the renderer and calls R_Init
re.BeginRegistration( &cls.glconfig );
CL_UpdateAspectAdjust();

// load character sets
#ifdef ELITEFORCE
Expand Down Expand Up @@ -3729,6 +3734,10 @@ void CL_Init( void ) {
cl_consoleUseScanCode = Cvar_Get( "cl_consoleUseScanCode", "1", CVAR_ARCHIVE );
cl_consoleShiftRequirement = Cvar_Get( "cl_consoleShiftRequirement", "1", CVAR_ARCHIVE );

cl_widescreenHUD = Cvar_Get( "cl_widescreenHUD", "0", CVAR_ARCHIVE );
cl_widescreenMenu = Cvar_Get( "cl_widescreenMenu", "0", CVAR_ARCHIVE );
cl_widescreenFOV = Cvar_Get( "cl_widescreenFOV", "0", CVAR_ARCHIVE );

// userinfo
Cvar_Get ("name", "UnnamedPlayer", CVAR_USERINFO | CVAR_ARCHIVE );
cl_rate = Cvar_Get ("rate", "25000", CVAR_USERINFO | CVAR_ARCHIVE );
Expand Down Expand Up @@ -4870,3 +4879,34 @@ qboolean CL_CDKeyValidate( const char *key, const char *checksum ) {
return qfalse;
#endif
}

void CL_UpdateAspectAdjust( void )
{
if ( cls.glconfig.vidWidth * 3 > cls.glconfig.vidHeight * 4 )
{ // We want to build an artifical 4:3 area, using the height as base
cls.ws_width = cls.glconfig.vidHeight / 3.0f * 4.0f;
cls.ws_height = cls.glconfig.vidHeight;
cls.ws_xscale = cls.ws_width / cls.glconfig.vidWidth;
cls.ws_xoffs = ((cls.glconfig.vidWidth - cls.ws_width) / 2.0f);
cls.ws_yscale = 1.0f;
cls.ws_yoffs = 0.0f;
}
else if ( cls.glconfig.vidWidth * 3 < cls.glconfig.vidHeight * 4 )
{ // We want to build an artifical 4:3 area, using the width as base
cls.ws_width = cls.glconfig.vidWidth;
cls.ws_height = cls.glconfig.vidWidth / 4.0f * 3.0f;
cls.ws_xscale = 1.0f;
cls.ws_xoffs = 0.0f;
cls.ws_yscale = cls.ws_height / cls.glconfig.vidHeight;
cls.ws_yoffs = ((cls.glconfig.vidHeight - cls.ws_height) / 2.0f);
}
else
{
cls.ws_width = cls.glconfig.vidWidth;
cls.ws_height = cls.glconfig.vidHeight;
cls.ws_xscale = 1.0f;
cls.ws_xoffs = 0.0f;
cls.ws_yscale = 1.0f;
cls.ws_yoffs = 0.0f;
}
}
13 changes: 12 additions & 1 deletion code/client/cl_ui.c
Original file line number Diff line number Diff line change
Expand Up @@ -850,6 +850,14 @@ intptr_t CL_UISystemCalls( intptr_t *args ) {
return 0;

case UI_R_RENDERSCENE:
if ( (cl_widescreenMenu->integer == 1 || (cl_widescreenMenu->integer == 2 && cls.cgameStarted)) )
{ // We also scale fullscreen scenes for ui (we don't do that for cgame).
refdef_t *ref = VMA(1);
ref->x = ref->x * cls.ws_xscale + cls.ws_xoffs;
ref->y = ref->y * cls.ws_yscale + cls.ws_yoffs;
ref->width *= cls.ws_xscale;
ref->height *= cls.ws_yscale;
}
re.RenderScene( VMA(1) );
return 0;

Expand All @@ -858,7 +866,10 @@ intptr_t CL_UISystemCalls( intptr_t *args ) {
return 0;

case UI_R_DRAWSTRETCHPIC:
re.DrawStretchPic( VMF(1), VMF(2), VMF(3), VMF(4), VMF(5), VMF(6), VMF(7), VMF(8), args[9] );
if ( cl_widescreenMenu->integer == 1 || (cl_widescreenMenu->integer == 2 && cls.cgameStarted) )
re.DrawStretchPic( VMF(1) * cls.ws_xscale + cls.ws_xoffs, VMF(2) * cls.ws_yscale + cls.ws_yoffs, VMF(3) * cls.ws_xscale, VMF(4) * cls.ws_yscale, VMF(5), VMF(6), VMF(7), VMF(8), args[9] );
else
re.DrawStretchPic( VMF(1), VMF(2), VMF(3), VMF(4), VMF(5), VMF(6), VMF(7), VMF(8), args[9] );
return 0;

case UI_R_MODELBOUNDS:
Expand Down
14 changes: 14 additions & 0 deletions code/client/client.h
Original file line number Diff line number Diff line change
Expand Up @@ -351,6 +351,14 @@ typedef struct {
qhandle_t charSetShader;
qhandle_t whiteShader;
qhandle_t consoleShader;

// Widescreen workaround
float ws_width;
float ws_height;
float ws_xoffs;
float ws_yoffs;
float ws_xscale;
float ws_yscale;
} clientStatic_t;

extern clientStatic_t cls;
Expand Down Expand Up @@ -428,6 +436,10 @@ extern cvar_t *cl_consoleKeys;
extern cvar_t *cl_consoleUseScanCode;
extern cvar_t *cl_consoleShiftRequirement;

extern cvar_t *cl_widescreenHUD;
extern cvar_t *cl_widescreenMenu;
extern cvar_t *cl_widescreenFOV;

#ifdef USE_MUMBLE
extern cvar_t *cl_useMumble;
extern cvar_t *cl_mumbleScale;
Expand Down Expand Up @@ -489,6 +501,8 @@ int CL_ServerStatus( char *serverAddress, char *serverStatusString, int maxLen )

qboolean CL_CheckPaused(void);

void CL_UpdateAspectAdjust( void );

//
// cl_input
//
Expand Down

0 comments on commit 58689b3

Please sign in to comment.