# HG changeset patch # User Wolfgang Steffens # Date 1337017714 -7200 # Node ID 17b0892ac79426e7ab2777d439d7ef9d27814a46 # Parent dbf43c07a507e698f933e92ed5bdc80b814fdb2e Replaced FFP code that sets up orthogonal projection with explicit matrix calculation. Storing the orthogonal projection in the projection matrix for legacy GL (1.x) rather than in the modelview matrix. diff -r dbf43c07a507 -r 17b0892ac794 hedgewars/uStore.pas --- a/hedgewars/uStore.pas Mon May 14 19:26:50 2012 +0200 +++ b/hedgewars/uStore.pas Mon May 14 19:48:34 2012 +0200 @@ -43,6 +43,7 @@ procedure WarpMouse(x, y: Word); inline; procedure SwapBuffers; inline; +procedure UpdateProjection; implementation uses uMisc, uConsole, uMobile, uVariables, uUtils, uTextures, uRender, uRenderUtils, uCommands, @@ -729,9 +730,7 @@ glMatrixMode(GL_MODELVIEW); // prepare default translation/scaling - glLoadIdentity(); - glScalef(2.0 / cScreenWidth, -2.0 / cScreenHeight, 1.0); - glTranslatef(0, -cScreenHeight / 2, 0); + SetScale(2.0); // enable alpha blending glEnable(GL_BLEND); @@ -746,23 +745,24 @@ glEnableClientState(GL_TEXTURE_COORD_ARRAY); end; +procedure UpdateProjection; +var mat: array[0..15] of GLfloat; + s: GLfloat; +begin + s:=cScaleFactor; + glMatrixMode(GL_PROJECTION); + mat[ 0]:= s/cScreenWidth; mat[ 1]:= 0.0; mat[ 2]:=0.0; mat[ 3]:= 0.0; + mat[ 4]:= 0.0; mat[ 5]:= -s/cScreenHeight; mat[ 6]:=0.0; mat[ 7]:= 0.0; + mat[ 8]:= 0.0; mat[ 9]:= 0.0; mat[10]:=1.0; mat[11]:= 0.0; + mat[12]:= cStereoDepth; mat[13]:= s/2; mat[14]:=0.0; mat[15]:= 1.0; + glLoadMatrixf(@mat); + glMatrixMode(GL_MODELVIEW); +end; + procedure SetScale(f: GLfloat); begin -// leave immediately if scale factor did not change - if f = cScaleFactor then - exit; - - if f = cDefaultZoomLevel then - glPopMatrix // "return" to default scaling - else // other scaling - begin - glPushMatrix; // save default scaling - glLoadIdentity; - glScalef(f / cScreenWidth, -f / cScreenHeight, 1.0); - glTranslatef(0, -cScreenHeight / 2, 0); - end; - - cScaleFactor:= f; + cScaleFactor:=f; + UpdateProjection; end; //////////////////////////////////////////////////////////////////////////////// @@ -1033,11 +1033,7 @@ // chFullScr is called when there is a rotation event and needs the SetScale and SetupOpenGL to set up the new resolution // this 6 gl functions are the relevant ones and are hacked together here for optimisation glMatrixMode(GL_MODELVIEW); - glPopMatrix; - glLoadIdentity(); - glScalef(2.0 / cScreenWidth, -2.0 / cScreenHeight, 1.0); - glTranslatef(0, -cScreenHeight / 2, 0); - glViewport(0, 0, cScreenWidth, cScreenHeight); + SetScale(2.0); exit; {$ELSE} SetScale(cDefaultZoomLevel); diff -r dbf43c07a507 -r 17b0892ac794 hedgewars/uVariables.pas --- a/hedgewars/uVariables.pas Mon May 14 19:26:50 2012 +0200 +++ b/hedgewars/uVariables.pas Mon May 14 19:48:34 2012 +0200 @@ -2425,6 +2425,7 @@ SyncTexture, ConfirmTexture: PTexture; cScaleFactor: GLfloat; + cStereoDepth: GLfloat; SupportNPOTT: Boolean; Step: LongInt; squaresize : LongInt; diff -r dbf43c07a507 -r 17b0892ac794 hedgewars/uWorld.pas --- a/hedgewars/uWorld.pas Mon May 14 19:26:50 2012 +0200 +++ b/hedgewars/uWorld.pas Mon May 14 19:48:34 2012 +0200 @@ -77,7 +77,6 @@ amSel: TAmmoType = amNothing; missionTex: PTexture; missionTimer: LongInt; - stereoDepth: GLfloat; isFirstFrame: boolean; AMAnimType: LongInt; @@ -1080,10 +1079,8 @@ exit else if rm = rmLeftEye then d:= -d; - stereoDepth:= stereoDepth + d; - glMatrixMode(GL_PROJECTION); - glTranslatef(d, 0, 0); - glMatrixMode(GL_MODELVIEW); + cStereoDepth:= cStereoDepth + d; + UpdateProjection; {$ENDIF} end; @@ -1095,10 +1092,8 @@ {$ELSE} if rm = rmDefault then exit; - glMatrixMode(GL_PROJECTION); - glTranslatef(-stereoDepth, 0, 0); - glMatrixMode(GL_MODELVIEW); - stereoDepth:= 0; + cStereoDepth:= 0; + UpdateProjection; {$ENDIF} end; @@ -1819,14 +1814,13 @@ missionTimer:= 0; missionTex:= nil; cOffsetY:= 0; - stereoDepth:= 0; + cStereoDepth:= 0; AMState:= AMHidden; isFirstFrame:= true; end; procedure freeModule; begin - stereoDepth:= stereoDepth; // avoid hint FreeTexture(fpsTexture); fpsTexture:= nil; FreeTexture(timeTexture);