Fix for HUD scaling with new projections

This commit is contained in:
Simon 2023-07-31 22:42:04 +01:00
parent 67e1d61214
commit 2290193a95
7 changed files with 77 additions and 52 deletions

View file

@ -4247,6 +4247,7 @@ static void CG_Draw2D( void )
}
was_in_vehicle = vr->in_vehicle;
cg.drawingHUD = CG_HUD_ZOOM;
if (cg.zoomMode == 4)
{
CG_DrawWeapReticle();

View file

@ -27,19 +27,19 @@ along with this program; if not, see <http://www.gnu.org/licenses/>.
#include <VrClientInfo.h>
void CG_AdjustFrom640( float *x, float *y, float *w, float *h ) {
void CG_AdjustFrom640(float* x, float* y, float* w, float* h) {
if (cg.drawingHUD && (!vr->cin_camera || vr->immersive_cinematics) && !vr->using_screen_layer)
{
float screenXScale = 1.0f / (cg.drawingHUD == CG_HUD_SCALED ? cg_hudScale.value : 1.0f);
float screenYScale = 1.0f / (cg.drawingHUD == CG_HUD_SCALED ? cg_hudScale.value : 1.25f);
float screenYScale = 1.0f / (cg.drawingHUD == CG_HUD_SCALED ? cg_hudScale.value : 1.0f);
float xoffset = cg.drawingHUD == CG_HUD_SCALED ? -cg_hudStereo.value : 0;
if (cg.stereoView == STEREO_LEFT) {
xoffset *= -1;
}
//We need to add an offset due to the effect of the compositor projection for asymmetric FOVs
xoffset += vr->off_center_fov * 640;
//We need to add an offset due to the effect of the compositor projection for asymmetric FOVs
xoffset += vr->off_center_fov * 640;
*x *= screenXScale;
*y *= screenYScale;
@ -51,7 +51,7 @@ void CG_AdjustFrom640( float *x, float *y, float *w, float *h ) {
}
*x += (640 - (640 * screenXScale)) / 2.0f + xoffset;
*y += (480 - (480 * screenYScale)) / 2.0f - cg_hudYOffset.value;
*y += (480 - (480 * screenYScale)) / 2.0f - ((cg.drawingHUD != CG_HUD_ZOOM) ? cg_hudYOffset.value : 0);
}
}
@ -91,14 +91,12 @@ Coords are virtual 640x480
*/
void CG_DrawSides(float x, float y, float w, float h, float size) {
//size *= cgs.screenXScale;
CG_AdjustFrom640(&x, &y, &w, &h);
cgi_R_DrawStretchPic( x, y, size, h, 0, 0, 0, 0, cgs.media.whiteShader );
cgi_R_DrawStretchPic( x + w - size, y, size, h, 0, 0, 0, 0, cgs.media.whiteShader );
}
void CG_DrawTopBottom(float x, float y, float w, float h, float size) {
//size *= cgs.screenYScale;
CG_AdjustFrom640(&x, &y, &w, &h);
cgi_R_DrawStretchPic( x, y, w, size, 0, 0, 0, 0, cgs.media.whiteShader );
cgi_R_DrawStretchPic( x, y + h - size, w, size, 0, 0, 0, 0, cgs.media.whiteShader );
}
@ -113,7 +111,6 @@ Coordinates are 640*480 virtual values
void CG_DrawRect( float x, float y, float width, float height, float size, const float *color ) {
cgi_R_SetColor( color );
CG_AdjustFrom640(&x, &y, &width, &height);
CG_DrawTopBottom(x, y, width, height, size);
CG_DrawSides(x, y, width, height, size);
@ -129,7 +126,6 @@ Coordinates are 640*480 virtual values
*/
void CG_FillRect( float x, float y, float width, float height, const float *color ) {
cgi_R_SetColor( color );
CG_AdjustFrom640(&x, &y, &width, &height);
cgi_R_DrawStretchPic( x, y, width, height, 0, 0, 0, 0, cgs.media.whiteShader);
cgi_R_SetColor( NULL );
}
@ -145,7 +141,6 @@ Coordinates are 640*480 virtual values
void CG_Scissor( float x, float y, float width, float height)
{
CG_AdjustFrom640(&x, &y, &width, &height);
cgi_R_Scissor( x, y, width, height);
}
@ -160,7 +155,6 @@ A width of 0 will draw with the original image width
=================
*/
void CG_DrawPic( float x, float y, float width, float height, qhandle_t hShader ) {
CG_AdjustFrom640(&x, &y, &width, &height);
cgi_R_DrawStretchPic( x, y, width, height, 0, 0, 1, 1, hShader );
}
@ -175,7 +169,6 @@ Can also specify the exact texture coordinates
*/
void CG_DrawPic2( float x, float y, float width, float height, float s1, float t1, float s2, float t2, qhandle_t hShader )
{
CG_AdjustFrom640(&x, &y, &width, &height);
cgi_R_DrawStretchPic( x, y, width, height, s1, t1, s2, t2, hShader );
}
@ -189,7 +182,6 @@ rotates around the upper right corner of the passed in point
=================
*/
void CG_DrawRotatePic( float x, float y, float width, float height,float angle, qhandle_t hShader ) {
CG_AdjustFrom640(&x, &y, &width, &height);
cgi_R_DrawRotatePic( x, y, width, height, 0, 0, 1, 1, angle, hShader );
}
@ -203,7 +195,6 @@ Actually rotates around the center point of the passed in coordinates
=================
*/
void CG_DrawRotatePic2( float x, float y, float width, float height,float angle, qhandle_t hShader ) {
CG_AdjustFrom640(&x, &y, &width, &height);
cgi_R_DrawRotatePic2( x, y, width, height, 0, 0, 1, 1, angle, hShader );
}
@ -251,7 +242,6 @@ void CG_DrawChar( int x, int y, int width, int height, int ch ) {
size = 0.03125;
size2 = 0.0625;
CG_AdjustFrom640(&ax, &ay, &aw, &ah);
cgi_R_DrawStretchPic( ax, ay, aw, ah, fcol, frow, fcol + size, frow + size2,
cgs.media.charsetShader );
@ -317,7 +307,6 @@ void CG_DrawStringExt( int x, int y, const char *string, const float *setColor,
void CG_DrawSmallStringColor( int x, int y, const char *s, vec4_t color ) {
auto fx = (float)x;
auto fy = (float)y;
CG_AdjustFrom640(&fx, &fy, NULL, NULL);
CG_DrawStringExt( (int)fx, (int)fy, s, color, qtrue, qfalse, SMALLCHAR_WIDTH, SMALLCHAR_HEIGHT );
}
@ -355,8 +344,6 @@ refresh window.
static void CG_TileClearBox( int x, int y, int w, int h, qhandle_t hShader ) {
float s1, t1, s2, t2;
// CG_AdjustFrom640Int(&x, &y, &w, &h);
s1 = x/64.0;
t1 = y/64.0;
s2 = (x+w)/64.0;
@ -506,7 +493,6 @@ void CG_DrawNumField (int x, int y, int width, int value,int charWidth,int charH
int _y = y;
int _charWidth = charWidth;
int _charHeight = charHeight;
//CG_AdjustFrom640Int(&_x, &_y, &_charWidth, &_charHeight);
switch(style)
{
case NUM_FONT_SMALL:
@ -540,7 +526,6 @@ void CG_DrawNumField (int x, int y, int width, int value,int charWidth,int charH
int _y = y;
int _charWidth = charWidth;
int _charHeight = charHeight;
//CG_AdjustFrom640Int(&_x, &_y, &_charWidth, &_charHeight);
switch(style)
{
case NUM_FONT_SMALL:
@ -571,6 +556,5 @@ CG_DrawProportionalString
void CG_DrawProportionalString( int x, int y, const char* str, int style, vec4_t color )
{
//assert(!style);//call this directly if you need style (OR it into the font handle)
CG_AdjustFrom640Int(&x, &y, NULL, NULL);
cgi_R_Font_DrawString (x, y, str, color, cgs.media.qhFontMedium, -1, 1.0f);
}

View file

@ -295,7 +295,11 @@ unsigned int cgi_AnyLanguage_ReadCharFromString( const char *psText, int *piAdva
}
void cgi_R_Font_DrawString(int ox, int oy, const char *text, const float *rgba, const int setIndex, int iMaxPixelWidth, const float scale /*= 1.0f*/) {
Q_syscall (CG_R_FONTDRAWSTRING, ox, oy, text, rgba, setIndex, iMaxPixelWidth, PASSFLOAT(scale) );
int xx = ox;
int yy = oy;
CG_AdjustFrom640Int(&xx, &yy, NULL, NULL);
Q_syscall (CG_R_FONTDRAWSTRING, xx, yy, text, rgba, setIndex, iMaxPixelWidth, PASSFLOAT(scale) );
}
//set some properties for the draw layer for my refractive effect (here primarily for mod authors) -rww
@ -340,7 +344,13 @@ void cgi_R_SetColor( const float *rgba ) {
void cgi_R_DrawStretchPic( float x, float y, float w, float h,
float s1, float t1, float s2, float t2, qhandle_t hShader ) {
Q_syscall( CG_R_DRAWSTRETCHPIC, PASSFLOAT(x), PASSFLOAT(y), PASSFLOAT(w), PASSFLOAT(h), PASSFLOAT(s1), PASSFLOAT(t1), PASSFLOAT(s2), PASSFLOAT(t2), hShader );
float xx = x;
float yy = y;
float ww = w;
float hh = h;
CG_AdjustFrom640(&xx, &yy, &ww, &hh);
Q_syscall( CG_R_DRAWSTRETCHPIC, PASSFLOAT(xx), PASSFLOAT(yy), PASSFLOAT(ww), PASSFLOAT(hh), PASSFLOAT(s1), PASSFLOAT(t1), PASSFLOAT(s2), PASSFLOAT(t2), hShader );
}
void cgi_R_ModelBounds( qhandle_t model, vec3_t mins, vec3_t maxs ) {
@ -355,13 +365,25 @@ void cgi_R_LerpTag( orientation_t *tag, qhandle_t mod, int startFrame, int endFr
void cgi_R_DrawRotatePic( float x, float y, float w, float h,
float s1, float t1, float s2, float t2,float a, qhandle_t hShader )
{
Q_syscall( CG_R_DRAWROTATEPIC, PASSFLOAT(x), PASSFLOAT(y), PASSFLOAT(w), PASSFLOAT(h), PASSFLOAT(s1), PASSFLOAT(t1), PASSFLOAT(s2), PASSFLOAT(t2), PASSFLOAT(a), hShader );
float xx = x;
float yy = y;
float ww = w;
float hh = h;
CG_AdjustFrom640(&xx, &yy, &ww, &hh);
Q_syscall( CG_R_DRAWROTATEPIC, PASSFLOAT(xx), PASSFLOAT(yy), PASSFLOAT(ww), PASSFLOAT(hh), PASSFLOAT(s1), PASSFLOAT(t1), PASSFLOAT(s2), PASSFLOAT(t2), PASSFLOAT(a), hShader );
}
void cgi_R_DrawRotatePic2( float x, float y, float w, float h,
float s1, float t1, float s2, float t2,float a, qhandle_t hShader )
{
Q_syscall( CG_R_DRAWROTATEPIC2, PASSFLOAT(x), PASSFLOAT(y), PASSFLOAT(w), PASSFLOAT(h), PASSFLOAT(s1), PASSFLOAT(t1), PASSFLOAT(s2), PASSFLOAT(t2), PASSFLOAT(a), hShader );
float xx = x;
float yy = y;
float ww = w;
float hh = h;
CG_AdjustFrom640(&xx, &yy, &ww, &hh);
Q_syscall( CG_R_DRAWROTATEPIC2, PASSFLOAT(xx), PASSFLOAT(yy), PASSFLOAT(ww), PASSFLOAT(hh), PASSFLOAT(s1), PASSFLOAT(t1), PASSFLOAT(s2), PASSFLOAT(t2), PASSFLOAT(a), hShader );
}
//linear fogging, with settable range -rww
@ -377,7 +399,13 @@ void cgi_R_LAGoggles( void )
void cgi_R_Scissor( float x, float y, float w, float h)
{
Q_syscall( CG_R_SCISSOR, PASSFLOAT(x), PASSFLOAT(y), PASSFLOAT(w), PASSFLOAT(h));
float xx = x;
float yy = y;
float ww = w;
float hh = h;
CG_AdjustFrom640(&xx, &yy, &ww, &hh);
Q_syscall( CG_R_SCISSOR, PASSFLOAT(xx), PASSFLOAT(yy), PASSFLOAT(ww), PASSFLOAT(hh));
}
void cgi_GetGlconfig( glconfig_t *glconfig ) {

View file

@ -23,7 +23,7 @@ along with this program; if not, see <http://www.gnu.org/licenses/>.
// Current version of the single player game
#include "../win32/AutoVersion.h"
#define JKXR_VERSION "1.1.14-ea"
#define JKXR_VERSION "1.1.16-ea"
#ifdef _DEBUG
#define Q3_VERSION "(debug)OpenJK: v" VERSION_STRING_DOTTED " JKXR: " JKXR_VERSION

View file

@ -2723,7 +2723,8 @@ static void CG_Draw2D( void )
CGCam_DrawWideScreen();
}
if (cg.zoomMode == 4)
cg.drawingHUD = CG_HUD_ZOOM;
if (cg.zoomMode == 4)
{
CG_DrawWeapReticle();
}

View file

@ -30,7 +30,7 @@ void CG_AdjustFrom640( float *x, float *y, float *w, float *h ) {
if (cg.drawingHUD && (!vr->cin_camera || vr->immersive_cinematics) && !vr->using_screen_layer)
{
float screenXScale = 1.0f / (cg.drawingHUD == CG_HUD_SCALED ? cg_hudScale.value : 1.0f);
float screenYScale = 1.0f / (cg.drawingHUD == CG_HUD_SCALED ? cg_hudScale.value : 1.25f);
float screenYScale = 1.0f / (cg.drawingHUD == CG_HUD_SCALED ? cg_hudScale.value : 1.0f);
float xoffset = cg.drawingHUD == CG_HUD_SCALED ? -cg_hudStereo.value : 0;
if (cg.stereoView == STEREO_LEFT) {
@ -50,7 +50,7 @@ void CG_AdjustFrom640( float *x, float *y, float *w, float *h ) {
}
*x += (640 - (640 * screenXScale)) / 2.0f + xoffset;
*y += (480 - (480 * screenYScale)) / 2.0f - cg_hudYOffset.value;
*y += (480 - (480 * screenYScale)) / 2.0f - ((cg.drawingHUD != CG_HUD_ZOOM) ? cg_hudYOffset.value : 0);
}
}
@ -90,14 +90,12 @@ Coords are virtual 640x480
*/
void CG_DrawSides(float x, float y, float w, float h, float size) {
//size *= cgs.screenXScale;
CG_AdjustFrom640(&x, &y, &w, &h);
cgi_R_DrawStretchPic( x, y, size, h, 0, 0, 0, 0, cgs.media.whiteShader );
cgi_R_DrawStretchPic( x + w - size, y, size, h, 0, 0, 0, 0, cgs.media.whiteShader );
}
void CG_DrawTopBottom(float x, float y, float w, float h, float size) {
//size *= cgs.screenYScale;
CG_AdjustFrom640(&x, &y, &w, &h);
cgi_R_DrawStretchPic( x, y, w, size, 0, 0, 0, 0, cgs.media.whiteShader );
cgi_R_DrawStretchPic( x, y + h - size, w, size, 0, 0, 0, 0, cgs.media.whiteShader );
}
@ -112,7 +110,6 @@ Coordinates are 640*480 virtual values
void CG_DrawRect( float x, float y, float width, float height, float size, const float *color ) {
cgi_R_SetColor( color );
CG_AdjustFrom640(&x, &y, &width, &height);
CG_DrawTopBottom(x, y, width, height, size);
CG_DrawSides(x, y, width, height, size);
@ -128,7 +125,6 @@ Coordinates are 640*480 virtual values
*/
void CG_FillRect( float x, float y, float width, float height, const float *color ) {
cgi_R_SetColor( color );
CG_AdjustFrom640(&x, &y, &width, &height);
cgi_R_DrawStretchPic( x, y, width, height, 0, 0, 0, 0, cgs.media.whiteShader);
cgi_R_SetColor( NULL );
}
@ -143,8 +139,6 @@ Coordinates are 640*480 virtual values
*/
void CG_Scissor( float x, float y, float width, float height)
{
CG_AdjustFrom640(&x, &y, &width, &height);
cgi_R_Scissor( x, y, width, height);
}
@ -159,7 +153,6 @@ A width of 0 will draw with the original image width
=================
*/
void CG_DrawPic( float x, float y, float width, float height, qhandle_t hShader ) {
CG_AdjustFrom640(&x, &y, &width, &height);
cgi_R_DrawStretchPic( x, y, width, height, 0, 0, 1, 1, hShader );
}
@ -174,7 +167,6 @@ Can also specify the exact texture coordinates
*/
void CG_DrawPic2( float x, float y, float width, float height, float s1, float t1, float s2, float t2, qhandle_t hShader )
{
CG_AdjustFrom640(&x, &y, &width, &height);
cgi_R_DrawStretchPic( x, y, width, height, s1, t1, s2, t2, hShader );
}
@ -188,7 +180,6 @@ rotates around the upper right corner of the passed in point
=================
*/
void CG_DrawRotatePic( float x, float y, float width, float height,float angle, qhandle_t hShader ) {
CG_AdjustFrom640(&x, &y, &width, &height);
cgi_R_DrawRotatePic( x, y, width, height, 0, 0, 1, 1, angle, hShader );
}
@ -202,7 +193,6 @@ Actually rotates around the center point of the passed in coordinates
=================
*/
void CG_DrawRotatePic2( float x, float y, float width, float height,float angle, qhandle_t hShader ) {
CG_AdjustFrom640(&x, &y, &width, &height);
cgi_R_DrawRotatePic2( x, y, width, height, 0, 0, 1, 1, angle, hShader );
}
@ -250,7 +240,6 @@ void CG_DrawChar( int x, int y, int width, int height, int ch ) {
size = 0.03125;
size2 = 0.0625;
CG_AdjustFrom640(&ax, &ay, &aw, &ah);
cgi_R_DrawStretchPic( ax, ay, aw, ah, fcol, frow, fcol + size, frow + size2,
cgs.media.charsetShader );
@ -316,7 +305,6 @@ void CG_DrawStringExt( int x, int y, const char *string, const float *setColor,
void CG_DrawSmallStringColor( int x, int y, const char *s, vec4_t color ) {
auto fx = (float)x;
auto fy = (float)y;
CG_AdjustFrom640(&fx, &fy, NULL, NULL);
CG_DrawStringExt( (int)fx, (int)fy, s, color, qtrue, qfalse, SMALLCHAR_WIDTH, SMALLCHAR_HEIGHT );
}
@ -354,8 +342,6 @@ refresh window.
static void CG_TileClearBox( int x, int y, int w, int h, qhandle_t hShader ) {
float s1, t1, s2, t2;
// CG_AdjustFrom640Int(&x, &y, &w, &h);
s1 = x/64.0;
t1 = y/64.0;
s2 = (x+w)/64.0;
@ -505,7 +491,6 @@ void CG_DrawNumField (int x, int y, int width, int value,int charWidth,int charH
int _y = y;
int _charWidth = charWidth;
int _charHeight = charHeight;
//CG_AdjustFrom640Int(&_x, &_y, &_charWidth, &_charHeight);
switch(style)
{
case NUM_FONT_SMALL:
@ -539,7 +524,6 @@ void CG_DrawNumField (int x, int y, int width, int value,int charWidth,int charH
int _y = y;
int _charWidth = charWidth;
int _charHeight = charHeight;
//CG_AdjustFrom640Int(&_x, &_y, &_charWidth, &_charHeight);
switch(style)
{
case NUM_FONT_SMALL:
@ -570,6 +554,5 @@ CG_DrawProportionalString
void CG_DrawProportionalString( int x, int y, const char* str, int style, vec4_t color )
{
//assert(!style);//call this directly if you need style (OR it into the font handle)
CG_AdjustFrom640Int(&x, &y, NULL, NULL);
cgi_R_Font_DrawString (x, y, str, color, cgs.media.qhFontMedium, -1, FONT_SCALE);
}

View file

@ -278,7 +278,11 @@ unsigned int cgi_AnyLanguage_ReadCharFromString( const char **ppText, int *ppos,
}
void cgi_R_Font_DrawString(int ox, int oy, const char *text, const float *rgba, const int setIndex, int iMaxPixelWidth, const float scale /*= 1.0f*/) {
Q_syscall (CG_R_FONTDRAWSTRING, ox, oy, text, rgba, setIndex, iMaxPixelWidth, PASSFLOAT(scale) );
int xx = ox;
int yy = oy;
CG_AdjustFrom640Int(&xx, &yy, NULL, NULL);
Q_syscall (CG_R_FONTDRAWSTRING, xx, yy, text, rgba, setIndex, iMaxPixelWidth, PASSFLOAT(scale) );
}
void cgi_R_ClearScene( void ) {
@ -311,7 +315,13 @@ void cgi_R_SetColor( const float *rgba ) {
void cgi_R_DrawStretchPic( float x, float y, float w, float h,
float s1, float t1, float s2, float t2, qhandle_t hShader ) {
Q_syscall( CG_R_DRAWSTRETCHPIC, PASSFLOAT(x), PASSFLOAT(y), PASSFLOAT(w), PASSFLOAT(h), PASSFLOAT(s1), PASSFLOAT(t1), PASSFLOAT(s2), PASSFLOAT(t2), hShader );
float xx = x;
float yy = y;
float ww = w;
float hh = h;
CG_AdjustFrom640(&xx, &yy, &ww, &hh);
Q_syscall( CG_R_DRAWSTRETCHPIC, PASSFLOAT(xx), PASSFLOAT(yy), PASSFLOAT(ww), PASSFLOAT(hh), PASSFLOAT(s1), PASSFLOAT(t1), PASSFLOAT(s2), PASSFLOAT(t2), hShader );
}
void cgi_R_DrawScreenShot( float x, float y, float w, float h){
@ -330,13 +340,25 @@ void cgi_R_LerpTag( orientation_t *tag, qhandle_t mod, int startFrame, int endFr
void cgi_R_DrawRotatePic( float x, float y, float w, float h,
float s1, float t1, float s2, float t2,float a, qhandle_t hShader )
{
Q_syscall( CG_R_DRAWROTATEPIC, PASSFLOAT(x), PASSFLOAT(y), PASSFLOAT(w), PASSFLOAT(h), PASSFLOAT(s1), PASSFLOAT(t1), PASSFLOAT(s2), PASSFLOAT(t2), PASSFLOAT(a), hShader );
float xx = x;
float yy = y;
float ww = w;
float hh = h;
CG_AdjustFrom640(&xx, &yy, &ww, &hh);
Q_syscall( CG_R_DRAWROTATEPIC, PASSFLOAT(xx), PASSFLOAT(yy), PASSFLOAT(ww), PASSFLOAT(hh), PASSFLOAT(s1), PASSFLOAT(t1), PASSFLOAT(s2), PASSFLOAT(t2), PASSFLOAT(a), hShader );
}
void cgi_R_DrawRotatePic2( float x, float y, float w, float h,
float s1, float t1, float s2, float t2,float a, qhandle_t hShader )
{
Q_syscall( CG_R_DRAWROTATEPIC2, PASSFLOAT(x), PASSFLOAT(y), PASSFLOAT(w), PASSFLOAT(h), PASSFLOAT(s1), PASSFLOAT(t1), PASSFLOAT(s2), PASSFLOAT(t2), PASSFLOAT(a), hShader );
float xx = x;
float yy = y;
float ww = w;
float hh = h;
CG_AdjustFrom640(&xx, &yy, &ww, &hh);
Q_syscall( CG_R_DRAWROTATEPIC2, PASSFLOAT(xx), PASSFLOAT(yy), PASSFLOAT(ww), PASSFLOAT(hh), PASSFLOAT(s1), PASSFLOAT(t1), PASSFLOAT(s2), PASSFLOAT(t2), PASSFLOAT(a), hShader );
}
void cgi_R_LAGoggles( void )
@ -346,7 +368,13 @@ void cgi_R_LAGoggles( void )
void cgi_R_Scissor( float x, float y, float w, float h)
{
Q_syscall( CG_R_SCISSOR, PASSFLOAT(x), PASSFLOAT(y), PASSFLOAT(w), PASSFLOAT(h));
float xx = x;
float yy = y;
float ww = w;
float hh = h;
CG_AdjustFrom640(&xx, &yy, &ww, &hh);
Q_syscall( CG_R_SCISSOR, PASSFLOAT(xx), PASSFLOAT(yy), PASSFLOAT(ww), PASSFLOAT(hh));
}
void cgi_GetGlconfig( glconfig_t *glconfig ) {