From bc0b5505a84596d6f4a437042dc57efda5c5957d Mon Sep 17 00:00:00 2001 From: Sryder13 Date: Mon, 8 Sep 2014 00:55:32 +0100 Subject: [PATCH] OpenGL: Fix sky drawing sky positioning and scaling more correct compared to software. --- src/hardware/hw_main.c | 59 ++++++++++++++++++++++++++---------------- 1 file changed, 36 insertions(+), 23 deletions(-) diff --git a/src/hardware/hw_main.c b/src/hardware/hw_main.c index e832457c0..77c56a734 100644 --- a/src/hardware/hw_main.c +++ b/src/hardware/hw_main.c @@ -4355,7 +4355,7 @@ static void HWR_DrawSkyBackground(player_t *player) { FOutVector v[4]; angle_t angle; - float f; + float dimensionmultiply; // 3--2 // | /| @@ -4377,36 +4377,49 @@ static void HWR_DrawSkyBackground(player_t *player) // X - if (textures[skytexture]->width > 256) - angle = (angle_t)((float)(dup_viewangle + gr_xtoviewangle[0]) - /((float)textures[skytexture]->width/256.0f)) - %(ANGLE_90-1); - else - angle = (dup_viewangle + gr_xtoviewangle[0])%(ANGLE_90-1); + // NOTE: This doesn't work right with texture widths greater than 1024 + // software doesn't draw any further than 1024 for skies anyway, but this doesn't overlap properly + // The only time this will probably be an issue is when a sky wider than 1024 is used as a sky AND a regular wall texture - f = (float)((textures[skytexture]->width/2) - * FIXED_TO_FLOAT(FINETANGENT((2048 - - ((INT32)angle>>(ANGLETOFINESHIFT + 1))) & FINEMASK))); + angle = (dup_viewangle + gr_xtoviewangle[0]); - v[0].sow = v[3].sow = 0.22f+(f)/(textures[skytexture]->width/2); - v[2].sow = v[1].sow = 0.22f+(f+(127))/(textures[skytexture]->width/2); + dimensionmultiply = ((float)textures[skytexture]->width/256.0f); + v[0].sow = v[3].sow = ((float) angle / ((ANGLE_90-1)*dimensionmultiply)); + v[2].sow = v[1].sow = (-1.0f/dimensionmultiply)+((float) angle / ((ANGLE_90-1)*dimensionmultiply)); // Y + angle = aimingangle; + + float aspectratio = (float)vid.width/(float)vid.height; + dimensionmultiply = ((float)textures[skytexture]->height/(128.0f*aspectratio)); + float angleturn = (((float)ANGLE_45-1.0f)*aspectratio)*dimensionmultiply; - if (textures[skytexture]->height > 256) - angle = (angle_t)((float)(aimingangle) - *(256.0f/(float)textures[skytexture]->height)) - %(ANGLE_90-1); // Just so that looking up and down scales right + // Middle of the sky should always be at angle 0 + // need to keep correct aspect ratio with X + if (atransform.flip) + { + // During vertical flip the sky should be flipped and it's y movement should also be flipped obviously + v[3].tow = v[2].tow = -(0.5f-(0.5f/dimensionmultiply)); + v[0].tow = v[1].tow = (-1.0f/dimensionmultiply)-(0.5f-(0.5f/dimensionmultiply)); + } else - angle = (aimingangle); + { + v[3].tow = v[2].tow = (-1.0f/dimensionmultiply)-(0.5f-(0.5f/dimensionmultiply)); + v[0].tow = v[1].tow = -(0.5f-(0.5f/dimensionmultiply)); + } - f = (float)((textures[skytexture]->height/2) - * FIXED_TO_FLOAT(FINETANGENT((2048 - - ((INT32)angle>>(ANGLETOFINESHIFT + 1))) & FINEMASK))); - - v[3].tow = v[2].tow = 0.22f+(f)/(textures[skytexture]->height/2); - v[0].tow = v[1].tow = 0.22f+(f+(127))/(textures[skytexture]->height/2); + if (angle > ANGLE_180) // Do this because we don't want the sky to suddenly teleport when crossing over 0 to 360 and vice versa + { + angle = InvAngle(angle); + v[3].tow = v[2].tow += ((float) angle / angleturn); + v[0].tow = v[1].tow += ((float) angle / angleturn); + } + else + { + v[3].tow = v[2].tow -= ((float) angle / angleturn); + v[0].tow = v[1].tow -= ((float) angle / angleturn); + } HWD.pfnDrawPolygon(NULL, v, 4, 0); }