small tweak/hax for blurry land to make tile borders vanish (when clamping is off)
authorsheepluva
Sun, 19 Jan 2014 16:35:06 +0100
changeset 10020 67e127027af6
parent 10018 bdf75f0350bd
child 10021 7f36194af01c
small tweak/hax for blurry land to make tile borders vanish (when clamping is off)
hedgewars/uLandTexture.pas
hedgewars/uRender.pas
--- a/hedgewars/uLandTexture.pas	Sun Jan 19 14:58:54 2014 +0100
+++ b/hedgewars/uLandTexture.pas	Sun Jan 19 16:35:06 2014 +0100
@@ -33,6 +33,8 @@
 uses uConsts, GLunit, uTypes, uVariables, uTextures, uDebug, uRender;
 
 const TEXSIZE = 128;
+      // in avoid tile borders stretch the blurry texture by 1 pixel more
+      BLURRYLANDOVERLAP = 1 / TEXSIZE / 2.0; // 1 pixel divided by texsize and blurry land scale factor
 
 type TLandRecord = record
             shouldUpdate, landAdded: boolean;
@@ -181,9 +183,10 @@
             if tex <> nil then
                 if (cReducedQuality and rqBlurryLand) = 0 then
                     DrawTexture(dX + x * TEXSIZE, dY + y * TEXSIZE, tex)
-                else
+                else if (cReducedQuality and rqClampLess) = 0 then
                     DrawTexture(dX + x * TEXSIZE * 2, dY + y * TEXSIZE * 2, tex, 2.0)
-
+                else
+                    DrawTexture2(dX + x * TEXSIZE * 2, dY + y * TEXSIZE * 2, tex, 2.0, BLURRYLANDOVERLAP);
 end;
 
 procedure SetLandTexture;
--- a/hedgewars/uRender.pas	Sun Jan 19 14:58:54 2014 +0100
+++ b/hedgewars/uRender.pas	Sun Jan 19 16:35:06 2014 +0100
@@ -33,6 +33,7 @@
 
 procedure DrawTexture           (X, Y: LongInt; Texture: PTexture); inline;
 procedure DrawTexture           (X, Y: LongInt; Texture: PTexture; Scale: GLfloat);
+procedure DrawTexture2          (X, Y: LongInt; Texture: PTexture; Scale, Overlap: GLfloat);
 procedure DrawTextureFromRect   (X, Y: LongInt; r: PSDL_Rect; SourceTexture: PTexture); inline;
 procedure DrawTextureFromRect   (X, Y, W, H: LongInt; r: PSDL_Rect; SourceTexture: PTexture); inline;
 procedure DrawTextureFromRectDir(X, Y, W, H: LongInt; r: PSDL_Rect; SourceTexture: PTexture; Dir: LongInt);
@@ -167,6 +168,33 @@
 glPopMatrix
 end;
 
+{ this contains tweaks in order to avoid land tile borders in blurry land mode }
+procedure DrawTexture2(X, Y: LongInt; Texture: PTexture; Scale, Overlap: GLfloat);
+var
+    TextureBuffer: array [0..3] of TVertex2f;
+begin
+glPushMatrix();
+glTranslatef(X, Y, 0);
+glScalef(Scale, Scale, 1);
+
+glBindTexture(GL_TEXTURE_2D, Texture^.id);
+
+TextureBuffer[0].X:= Texture^.tb[0].X + Overlap;
+TextureBuffer[0].Y:= Texture^.tb[0].Y + Overlap;
+TextureBuffer[1].X:= Texture^.tb[1].X - Overlap;
+TextureBuffer[1].Y:= Texture^.tb[1].Y + Overlap;
+TextureBuffer[2].X:= Texture^.tb[2].X - Overlap;
+TextureBuffer[2].Y:= Texture^.tb[2].Y - Overlap;
+TextureBuffer[3].X:= Texture^.tb[3].X + Overlap;
+TextureBuffer[3].Y:= Texture^.tb[3].Y - Overlap;
+
+glVertexPointer(2, GL_FLOAT, 0, @Texture^.vb);
+glTexCoordPointer(2, GL_FLOAT, 0, @TextureBuffer);
+glDrawArrays(GL_TRIANGLE_FAN, 0, Length(Texture^.vb));
+
+glPopMatrix();
+end;
+
 procedure DrawTextureF(Texture: PTexture; Scale: GLfloat; X, Y, Frame, Dir, w, h: LongInt);
 begin
     DrawTextureRotatedF(Texture, Scale, 0, 0, X, Y, Frame, Dir, w, h, 0)