More sprites are visible
authorunc0rr
Sun, 27 Jan 2008 15:02:12 +0000
changeset 762 5ecf042f6113
parent 761 63ae90011a52
child 763 6286afff6b87
More sprites are visible
hedgewars/GSHandlers.inc
hedgewars/hwengine.dpr
hedgewars/uGears.pas
hedgewars/uMisc.pas
hedgewars/uStore.pas
hedgewars/uTeams.pas
hedgewars/uWorld.pas
share/hedgewars/Data/Graphics/Hedgehog.png
--- a/hedgewars/GSHandlers.inc	Sun Jan 27 13:35:56 2008 +0000
+++ b/hedgewars/GSHandlers.inc	Sun Jan 27 15:02:12 2008 +0000
@@ -212,10 +212,10 @@
    end;
 
 str(Gear^.State, s);
-Gear^.Surf:= RenderString(s, PHedgehog(Gear^.Hedgehog)^.Team^.Clan^.Color, font);
+Gear^.Tex:= RenderStringTex(s, PHedgehog(Gear^.Hedgehog)^.Team^.Clan^.Color, font);
 if hwRound(Gear^.Y) < cWaterLine then Gear^.doStep:= @doStepHealthTagWork
                                  else Gear^.doStep:= @doStepHealthTagWorkUnderWater;
-Gear^.Y:= Gear^.Y - int2hwFloat(Gear^.Surf^.h)
+Gear^.Y:= Gear^.Y - int2hwFloat(Gear^.Tex^.h)
 end;
 
 ////////////////////////////////////////////////////////////////////////////////
--- a/hedgewars/hwengine.dpr	Sun Jan 27 13:35:56 2008 +0000
+++ b/hedgewars/hwengine.dpr	Sun Jan 27 15:02:12 2008 +0000
@@ -84,9 +84,6 @@
               InitPlaylistChunk(GetRandom(High(LongWord)));
               AssignHHCoords;
               AddMiscGears;
-              AdjustColor(cColorNearBlack);
-              AdjustColor(cWaterColor);
-              AdjustColor(cWhiteColor);
               StoreLoad;
               AdjustColor(cConsoleSplitterColor);
               ResetKbd;
--- a/hedgewars/uGears.pas	Sun Jan 27 13:35:56 2008 +0000
+++ b/hedgewars/uGears.pas	Sun Jan 27 15:02:12 2008 +0000
@@ -46,7 +46,7 @@
              Health, Damage: LongInt;
              CollisionIndex: LongInt;
              Tag: LongInt;
-             Surf: PSDL_Surface;
+             Tex: PTexture;
              Z: Longword;
              IntersectGear: PGear;
              TriggerId: Longword;
@@ -307,11 +307,13 @@
     t: Longword;
 begin
 DeleteCI(Gear);
-if Gear^.Surf <> nil then
+
+if Gear^.Tex <> nil then
    begin
-   SDL_FreeSurface(Gear^.Surf);
-   Gear^.Surf:= nil
+   FreeTexture(Gear^.Tex);
+   Gear^.Tex:= nil
    end;
+
 if Gear^.Kind = gtHedgehog then
    if CurAmmoGear <> nil then
       begin
@@ -469,18 +471,18 @@
         t:= hwRound(Gear^.Y) - cHHRadius - 10 + WorldDy;
         if (cTagsMask and 1) <> 0 then
            begin
-           dec(t, HealthTag^.h + 2);
-           DrawCentered(hwRound(Gear^.X) + WorldDx, t, HealthTag, Surface)
+           dec(t, HealthTagTex^.h + 2);
+           DrawCentered(hwRound(Gear^.X) + WorldDx, t, HealthTagTex)
            end;
         if (cTagsMask and 2) <> 0 then
            begin
-           dec(t, NameTag^.h + 2);
-           DrawCentered(hwRound(Gear^.X) + WorldDx, t, NameTag, Surface)
+           dec(t, NameTagTex^.h + 2);
+           DrawCentered(hwRound(Gear^.X) + WorldDx, t, NameTagTex)
            end;
         if (cTagsMask and 4) <> 0 then
            begin
-           dec(t, Team^.NameTag^.h + 2);
-           DrawCentered(hwRound(Gear^.X) + WorldDx, t, Team^.NameTag, Surface)
+           dec(t, Team^.NameTagTex^.h + 2);
+           DrawCentered(hwRound(Gear^.X) + WorldDx, t, Team^.NameTagTex)
            end
         end else // Current hedgehog
       if (Gear^.State and gstHHDriven) <> 0 then
@@ -577,7 +579,7 @@
         gtHedgehog: DrawHH(Gear, Surface);
     gtAmmo_Grenade: DrawSprite(sprGrenade , hwRound(Gear^.X) - 16 + WorldDx, hwRound(Gear^.Y) - 16 + WorldDy, DxDy2Angle32(Gear^.dY, Gear^.dX), Surface);
        gtHealthTag,
-     gtSmallDamage: if Gear^.Surf <> nil then DrawCentered(hwRound(Gear^.X) + WorldDx, hwRound(Gear^.Y) + WorldDy, Gear^.Surf, Surface);
+     gtSmallDamage: if Gear^.Tex <> nil then DrawCentered(hwRound(Gear^.X) + WorldDx, hwRound(Gear^.Y) + WorldDy, Gear^.Tex);
            gtGrave: ;//DrawSurfSprite(hwRound(Gear^.X) + WorldDx - 16, hwRound(Gear^.Y) + WorldDy - 16, 32, (GameTicks shr 7) and 7, PHedgehog(Gear^.Hedgehog)^.Team^.GraveSurf, Surface);
              gtUFO: DrawSprite(sprUFO, hwRound(Gear^.X) - 16 + WorldDx, hwRound(Gear^.Y) - 16 + WorldDy, (GameTicks shr 7) mod 4, Surface);
             gtRope: begin
--- a/hedgewars/uMisc.pas	Sun Jan 27 13:35:56 2008 +0000
+++ b/hedgewars/uMisc.pas	Sun Jan 27 15:02:12 2008 +0000
@@ -55,10 +55,10 @@
     GameTicks     : LongWord = 0;
 
     cSkyColor     : Longword = 0;
-    cWaterColor   : Longword = $005ACE;
-    cWhiteColor   : Longword = $FFFFFF;
-    cConsoleSplitterColor : Longword = $FF0000;
-    cColorNearBlack       : Longword = 16;
+    cWaterColor   : Longword = $FF005ACE;
+    cWhiteColor   : Longword = $FFFFFFFF;
+    cConsoleSplitterColor : Longword = $FFFF0000;
+    cColorNearBlack       : Longword = $FF000010;
     cExplosionBorderColor : LongWord = $808080;
 
     cShowFPS      : boolean = true;
@@ -283,8 +283,8 @@
 if SDL_MustLock(surf) then
    SDL_UnlockSurface(surf);
 
-glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_NEAREST);
-glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR)
+glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
+glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR)
 end;
 
 procedure FreeTexture(tex: PTexture);
--- a/hedgewars/uStore.pas	Sun Jan 27 13:35:56 2008 +0000
+++ b/hedgewars/uStore.pas	Sun Jan 27 15:02:12 2008 +0000
@@ -28,12 +28,13 @@
 procedure DrawSprite (Sprite: TSprite; X, Y, Frame: LongInt; Surface: PSDL_Surface);
 procedure DrawSprite2(Sprite: TSprite; X, Y, FrameX, FrameY: LongInt; Surface: PSDL_Surface);
 procedure DrawSurfSprite(X, Y, Height, Frame: LongInt; Source: GLuint; Surface: PSDL_Surface);
-procedure DrawLand (X, Y: LongInt; Surface: PSDL_Surface);
+procedure DrawLand (X, Y: LongInt);
+procedure DrawTexture(X, Y: LongInt; Texture: PTexture);
 procedure DXOutText(X, Y: LongInt; Font: THWFont; s: string; Surface: PSDL_Surface);
-procedure DrawCentered(X, Top: LongInt; Source, Surface: PSDL_Surface);
+procedure DrawCentered(X, Top: LongInt; Source: PTexture);
 procedure DrawFromRect(X, Y: LongInt; r: PSDL_Rect; SourceTexture: PTexture; DestSurface: PSDL_Surface);
 procedure DrawHedgehog(X, Y: LongInt; Dir: LongInt; Pos, Step: LongWord; Surface: PSDL_Surface);
-function  RenderString(s: string; Color: Longword; font: THWFont): PSDL_Surface;
+function  RenderStringTex(s: string; Color: Longword; font: THWFont): PTexture;
 procedure RenderHealth(var Hedgehog: THedgehog);
 procedure AddProgress;
 procedure FinishProgress;
@@ -42,7 +43,7 @@
 
 var PixelFormat: PSDL_PixelFormat;
  SDLPrimSurface: PSDL_Surface;
-   PauseSurface: PSDL_Surface;
+   PauseTexture: PTexture;
 
 implementation
 uses uMisc, uConsole, uLand, uLocale, GLU;
@@ -126,10 +127,10 @@
     for t:= 0 to Pred(TeamsCount) do
      with TeamsArray[t]^ do
       begin
-      NameTag:= RenderString(TeamName, Clan^.Color, Font);
+      NameTagTex:= RenderStringTex(TeamName, Clan^.Color, Font);
 
       r.w:= cTeamHealthWidth + 5;
-      r.h:= NameTag^.h;
+      r.h:= NameTagTex^.h;
 
       HealthSurf:= SDL_CreateRGBSurface(SDL_HWSURFACE, r.w, r.h, cBits, PixelFormat^.RMask, PixelFormat^.GMask, PixelFormat^.BMask, PixelFormat^.AMask);
       TryDo(HealthSurf <> nil, errmsgCreateSurface, true);
@@ -145,7 +146,7 @@
       for i:= 0 to 7 do
           with Hedgehogs[i] do
                if Gear <> nil then
-                  NameTag:= RenderString(Name, Clan^.Color, fnt16);
+                  NameTagTex:= RenderStringTex(Name, Clan^.Color, fnt16);
       end;
     end;
 
@@ -291,7 +292,7 @@
 
 InitHealth;
 
-PauseSurface:= RenderString(trmsg[sidPaused], $FFFF00, fntBig);
+PauseTexture:= RenderStringTex(trmsg[sidPaused], $FFFF00, fntBig);
 
 {$IFDEF DUMP}
 SDL_SaveBMP_RW(LandSurface, SDL_RWFromFile('LandSurface.bmp', 'wb'), 1);
@@ -329,7 +330,29 @@
 glTexCoord2f(0, b);
 glVertex2i(X, rr.h + Y);
 
-glEnd();
+glEnd()
+end;
+
+procedure DrawTexture(X, Y: LongInt; Texture: PTexture);
+begin
+glBindTexture(GL_TEXTURE_2D, Texture^.id);
+glEnable(GL_TEXTURE_2D);
+
+glBegin(GL_QUADS);
+
+glTexCoord2f(0, 0);
+glVertex2i(X, Y);
+
+glTexCoord2f(1, 0);
+glVertex2i(Texture^.w + X, Y);
+
+glTexCoord2f(1, 1);
+glVertex2i(Texture^.w + X, Texture^.h + Y);
+
+glTexCoord2f(0, 1);
+glVertex2i(X, Texture^.h + Y);
+
+glEnd()
 end;
 
 procedure DrawSpriteFromRect(Sprite: TSprite; r: TSDL_Rect; X, Y, Height, Position: LongInt; Surface: PSDL_Surface);
@@ -389,38 +412,14 @@
 SDL_FreeSurface(tmpsurf)
 end;
 
-procedure DrawLand(X, Y: LongInt; Surface: PSDL_Surface);
-//const r: TSDL_Rect = (x: 0; y: 0; w: 2048; h: 1024);
+procedure DrawLand(X, Y: LongInt);
 begin
-glBindTexture(GL_TEXTURE_2D, LandTexture^.id);
-glEnable(GL_TEXTURE_2D);
-
-glBegin(GL_QUADS);
-
-glTexCoord2i(0, 0);
-glVertex2i(X, Y);
-
-glTexCoord2i(1, 0);
-glVertex2i(2048 + X, Y);
-
-glTexCoord2i(1, 1);
-glVertex2i(2048 + X, 1024 + Y);
-
-glTexCoord2i(0, 1);
-glVertex2i(X, 1024 + Y);
-
-glEnd();
-//DrawFromRect(X, Y, @r, LandSurface, Surface)
+DrawTexture(X, Y, LandTexture)
 end;
 
-procedure DrawCentered(X, Top: LongInt; Source, Surface: PSDL_Surface);
-var r: TSDL_Rect;
+procedure DrawCentered(X, Top: LongInt; Source: PTexture);
 begin
-r.x:= X - Source^.w div 2;
-r.y:= Top;
-r.w:= Source^.w;
-r.h:= Source^.h;
-SDL_UpperBlit(Source, nil, Surface, @r)
+DrawTexture(X - Source^.w div 2, Top, Source)
 end;
 
 procedure DrawHedgehog(X, Y: LongInt; Dir: LongInt; Pos, Step: LongWord; Surface: PSDL_Surface);
@@ -473,25 +472,26 @@
 SDL_FreeSurface(LandSurface)
 end;
 
-function  RenderString(s: string; Color: Longword; font: THWFont): PSDL_Surface;
+function  RenderStringTex(s: string; Color: Longword; font: THWFont): PTexture;
 var w, h: LongInt;
     Result: PSDL_Surface;
 begin
 TTF_SizeUTF8(Fontz[font].Handle, Str2PChar(s), w, h);
-Result:= SDL_CreateRGBSurface(SDL_HWSURFACE, w + FontBorder * 2 + 4, h + FontBorder * 2,
-         cBits, PixelFormat^.RMask, PixelFormat^.GMask, PixelFormat^.BMask, PixelFormat^.AMask);
+Result:= SDL_CreateRGBSurface(SDL_SWSURFACE, w + FontBorder * 2 + 4, h + FontBorder * 2,
+         32, RMask, GMask, BMask, AMask);
 TryDo(Result <> nil, 'RenderString: fail to create surface', true);
 WriteInRoundRect(Result, 0, 0, Color, font, s);
-TryDo(SDL_SetColorKey(Result, SDL_SRCCOLORKEY or SDL_RLEACCEL, 0) = 0, errmsgTransparentSet, true);
-RenderString:= Result
+TryDo(SDL_SetColorKey(Result, SDL_SRCCOLORKEY, 0) = 0, errmsgTransparentSet, true);
+RenderStringTex:= Surface2Tex(Result);
+SDL_FreeSurface(Result)
 end;
 
 procedure RenderHealth(var Hedgehog: THedgehog);
 var s: shortstring;
 begin
 str(Hedgehog.Gear^.Health, s);
-if Hedgehog.HealthTag <> nil then SDL_FreeSurface(Hedgehog.HealthTag);
-Hedgehog.HealthTag:= RenderString(s, Hedgehog.Team^.Clan^.Color, fnt16)
+if Hedgehog.HealthTagTex <> nil then FreeTexture(Hedgehog.HealthTagTex);
+Hedgehog.HealthTagTex:= RenderStringTex(s, Hedgehog.Team^.Clan^.Color, fnt16)
 end;
 
 function  LoadImage(const filename: string; hasAlpha: boolean; critical, setTransparent: boolean): PSDL_Surface;
@@ -525,9 +525,9 @@
 end;
 
 procedure SetupOpenGL;
-var aspect: real;
+//var aspect: real;
 begin
-aspect:= cScreenWidth / cScreenHeight;
+//aspect:= cScreenWidth / cScreenHeight;
 
 glLoadIdentity;
 glViewport(0, 0, cScreenWidth, cScreenHeight);
--- a/hedgewars/uTeams.pas	Sun Jan 27 13:35:56 2008 +0000
+++ b/hedgewars/uTeams.pas	Sun Jan 27 15:02:12 2008 +0000
@@ -30,7 +30,8 @@
      THedgehog = record
                  Name: string[MAXNAMELEN];
                  Gear: PGear;
-                 NameTag, HealthTag: PSDL_Surface;
+                 NameTagTex: PTexture;
+                 HealthTagTex: PTexture;
                  Ammo: PHHAmmo;
                  AmmoStore: Longword;
                  CurSlot, CurAmmo: LongWord;
@@ -49,7 +50,7 @@
              Binds: TBinds;
              Hedgehogs: array[0..cMaxHHIndex] of THedgehog;
              CurrHedgehog: LongWord;
-             NameTag: PSDL_Surface;
+             NameTagTex: PTexture;
              CrosshairSurf,
              GraveSurf,
              HealthSurf: PSDL_Surface;
--- a/hedgewars/uWorld.pas	Sun Jan 27 13:35:56 2008 +0000
+++ b/hedgewars/uWorld.pas	Sun Jan 27 15:02:12 2008 +0000
@@ -45,7 +45,7 @@
       prevPoint: TPoint = (X: 0; Y: 0);
 
 type TCaptionStr = record
-                   Surf: PSDL_Surface;
+                   Tex: PTexture;
                    EndTime: LongWord;
                    end;
 
@@ -195,7 +195,7 @@
 for i:= -1 to cWaterSprCount do DrawSprite(sprWater,  i * 256  + ((WorldDx - (RealTicks shr 6) + 192) and $FF), cWaterLine + WorldDy - 48, 0, Surface);
 {$WARNINGS ON}
 
-DrawLand(WorldDx, WorldDy, Surface);
+DrawLand(WorldDx, WorldDy);
 // Water
 r.y:= WorldDy + cWaterLine + 32;
 if r.y < cScreenHeight then
@@ -248,27 +248,27 @@
                 tdx:= hwSign(Gear^.dX) * Sin(Gear^.Angle * Pi / cMaxAngle);
                 tdy:= - Cos(Gear^.Angle * Pi / cMaxAngle);
                 for i:= (Gear^.Power * 24) div cPowerDivisor downto 0 do
-//                    DrawSprite(sprPower, hwRound(Gear^.X) + system.round(WorldDx + tdx * (24 + i * 2)) - 16,
-//                                         hwRound(Gear^.Y) + system.round(WorldDy + tdy * (24 + i * 2)) - 12,
-//                                         i, Surface)
+                    DrawSprite(sprPower, hwRound(Gear^.X) + system.round(WorldDx + tdx * (24 + i * 2)) - 16,
+                                         hwRound(Gear^.Y) + system.round(WorldDy + tdy * (24 + i * 2)) - 12,
+                                         i, Surface)
                 end
         end;
 
 // Target
-//if TargetPoint.X <> NoPointX then DrawSprite(sprTargetP, TargetPoint.X + WorldDx - 16, TargetPoint.Y + WorldDy - 16, 0, Surface);
+if TargetPoint.X <> NoPointX then DrawSprite(sprTargetP, TargetPoint.X + WorldDx - 16, TargetPoint.Y + WorldDy - 16, 0, Surface);
 
 // Captions
 i:= 8;
 for grp:= Low(TCapGroup) to High(TCapGroup) do
     with Captions[grp] do
-         if Surf <> nil then
+         if Tex <> nil then
             begin
-//            DrawCentered(cScreenWidth div 2, i + cConsoleYAdd, Surf, Surface);
-            inc(i, Surf^.h + 2);
+            DrawCentered(cScreenWidth div 2, i + cConsoleYAdd, Tex);
+            inc(i, Tex^.h + 2);
             if EndTime <= RealTicks then
                begin
-               SDL_FreeSurface(Surf);
-               Surf:= nil;
+               FreeTexture(Tex);
+               Tex:= nil;
                EndTime:= 0
                end
             end;
@@ -277,11 +277,7 @@
 for t:= 0 to Pred(TeamsCount) do
    with TeamsArray[t]^ do
       begin
-      r.x:= cScreenWidth div 2 - NameTag^.w - 3;
-      r.y:= DrawHealthY;
-      r.w:= NameTag^.w;
-      r.h:= NameTag^.h;
-//      SDL_UpperBlit(NameTag, nil, Surface, @r);
+      DrawTexture(cScreenWidth div 2 - NameTagTex^.w - 3, DrawHealthY, NameTagTex);
 
       r.x:= 0;
       r.y:= 0;
@@ -301,10 +297,10 @@
       end;
 
 // Lag alert
-//if isInLag then DrawSprite(sprLag, 32, 32  + cConsoleYAdd, (RealTicks shr 7) mod 12, Surface);
+if isInLag then DrawSprite(sprLag, 32, 32  + cConsoleYAdd, (RealTicks shr 7) mod 12, Surface);
 
 // Wind bar
-//DrawSprite(sprWindBar, cScreenWidth - 180, cScreenHeight - 30, 0, Surface);
+DrawSprite(sprWindBar, cScreenWidth - 180, cScreenHeight - 30, 0, Surface);
 if WindBarWidth > 0 then
    begin
    {$WARNINGS OFF}
@@ -339,18 +335,18 @@
          i:= Ammo^[CurSlot, CurAmmo].Pos;
          with Ammoz[Ammo^[CurSlot, CurAmmo].AmmoType] do
            if PosCount > 1 then
-//             DrawSprite(PosSprite, CursorPoint.X - SpritesData[PosSprite].Width div 2,
-//                                   CursorPoint.Y - SpritesData[PosSprite].Height div 2,
-//                                   i, Surface);
+              DrawSprite(PosSprite, CursorPoint.X - SpritesData[PosSprite].Width div 2,
+                                    CursorPoint.Y - SpritesData[PosSprite].Height div 2,
+                                    i, Surface);
          end;
-//   DrawSprite(sprArrow, CursorPoint.X, CursorPoint.Y, (RealTicks shr 6) mod 8, Surface)
+   DrawSprite(sprArrow, CursorPoint.X, CursorPoint.Y, (RealTicks shr 6) mod 8, Surface)
    end;
 
 {$IFDEF COUNTTICKS}
 //DXOutText(10, 10, fnt16, inttostr(cntTicks), Surface);
 {$ENDIF}
 
-//if isPaused then DrawCentered(cScreenWidth div 2, cScreenHeight div 2, PauseSurface, Surface);
+if isPaused then DrawCentered(cScreenWidth div 2, cScreenHeight div 2, PauseTexture);
 
 inc(Frames);
 if cShowFPS then
@@ -394,9 +390,9 @@
 procedure AddCaption(s: string; Color: Longword; Group: TCapGroup);
 begin
 if Group in [capgrpGameState, capgrpNetSay] then WriteLnToConsole(s);
-if Captions[Group].Surf <> nil then SDL_FreeSurface(Captions[Group].Surf);
+if Captions[Group].Tex <> nil then FreeTexture(Captions[Group].Tex);
 
-Captions[Group].Surf:= RenderString(s, Color, fntBig);
+Captions[Group].Tex:= RenderStringTex(s, Color, fntBig);
 Captions[Group].EndTime:= RealTicks + 1500
 end;
 
Binary file share/hedgewars/Data/Graphics/Hedgehog.png has changed