Now game looks almost like it did before switching to OpenGL
authorunc0rr
Sun, 27 Jan 2008 16:49:11 +0000
changeset 764 7513452b1d51
parent 763 6286afff6b87
child 765 a45111da760e
Now game looks almost like it did before switching to OpenGL
hedgewars/CCHandlers.inc
hedgewars/GSHandlers.inc
hedgewars/uGears.pas
hedgewars/uStore.pas
hedgewars/uTeams.pas
hedgewars/uWorld.pas
--- a/hedgewars/CCHandlers.inc	Sun Jan 27 15:07:31 2008 +0000
+++ b/hedgewars/CCHandlers.inc	Sun Jan 27 16:49:11 2008 +0000
@@ -56,6 +56,8 @@
    val(s, Color);
    TryDo(Color <> 0, 'Error: black team color', true);
 
+   Color:= Color or $FF000000;
+
    AddTeam(Color);
    CurrentTeam^.TeamName:= ts;
    if GameType in [gmtDemo, gmtSave] then CurrentTeam^.ExtDriven:= true
@@ -79,7 +81,7 @@
 
 procedure chFort(var s: shortstring);
 begin
-if CurrentTeam = nil then OutError(errmsgIncorrectUse + ' "/grave"', true);
+if CurrentTeam = nil then OutError(errmsgIncorrectUse + ' "/fort"', true);
 if s[1]='"' then Delete(s, 1, 1);
 if s[byte(s[0])]='"' then Delete(s, byte(s[0]), 1);
 CurrentTeam^.FortName:= s
--- a/hedgewars/GSHandlers.inc	Sun Jan 27 15:07:31 2008 +0000
+++ b/hedgewars/GSHandlers.inc	Sun Jan 27 16:49:11 2008 +0000
@@ -923,11 +923,11 @@
 for i:= 0 to Pred(TeamsCount) do
     with thexchar[i] do
          begin
-         dec(t, team^.HealthSurf^.h + 2);
+         dec(t, team^.HealthTex^.h + 2);
          ny:= t;
          dy:= dy - ny
          end;
-         
+
 Gear^.Timer:= cSorterWorkTime;
 Gear^.doStep:= @doStepTeamHealthSorterWork;
 currsorter:= Gear
--- a/hedgewars/uGears.pas	Sun Jan 27 15:07:31 2008 +0000
+++ b/hedgewars/uGears.pas	Sun Jan 27 16:49:11 2008 +0000
@@ -495,10 +495,10 @@
               DrawSprite(sprQuestion, hwRound(Gear^.X) - 10 + WorldDx, hwRound(Gear^.Y) - cHHRadius - 34 + WorldDy, 0, Surface)
               else
               if ShowCrosshair and ((Gear^.State and gstAttacked) = 0) then
-(*                 DrawSurfSprite(Round(hwRound(Gear^.X) + hwSign(Gear^.dX) * Sin(Gear^.Angle*pi/cMaxAngle)*60) + WorldDx - 11,
+                 DrawSurfSprite(Round(hwRound(Gear^.X) + hwSign(Gear^.dX) * Sin(Gear^.Angle*pi/cMaxAngle)*60) + WorldDx - 11,
                            Round(hwRound(Gear^.Y) - Cos(Gear^.Angle*pi/cMaxAngle)*60) + WorldDy - 12,
                            24, (18 + hwSign(Gear^.dX) * LongInt(((Gear^.Angle * 72 div cMaxAngle) + 1) div 2) mod 18) mod 18,
-                           Team^.CrosshairSurf, Surface);*)
+                           Team^.CrosshairTex, Surface);
         end;
 end;
 
@@ -580,7 +580,7 @@
     gtAmmo_Grenade: DrawSprite(sprGrenade , hwRound(Gear^.X) - 16 + WorldDx, hwRound(Gear^.Y) - 16 + WorldDy, DxDy2Angle32(Gear^.dY, Gear^.dX), Surface);
        gtHealthTag,
      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);
+           gtGrave: DrawSurfSprite(hwRound(Gear^.X) + WorldDx - 16, hwRound(Gear^.Y) + WorldDy - 16, 32, (GameTicks shr 7) and 7, PHedgehog(Gear^.Hedgehog)^.Team^.GraveTex, Surface);
              gtUFO: DrawSprite(sprUFO, hwRound(Gear^.X) - 16 + WorldDx, hwRound(Gear^.Y) - 16 + WorldDy, (GameTicks shr 7) mod 4, Surface);
             gtRope: begin
                     roplen:= 0;
--- a/hedgewars/uStore.pas	Sun Jan 27 15:07:31 2008 +0000
+++ b/hedgewars/uStore.pas	Sun Jan 27 16:49:11 2008 +0000
@@ -27,7 +27,7 @@
 procedure DrawSpriteFromRect(Sprite: TSprite; r: TSDL_Rect; X, Y, Height, Position: LongInt; Surface: PSDL_Surface);
 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 DrawSurfSprite(X, Y, Height, Frame: LongInt; Source: PTexture; 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);
@@ -61,6 +61,10 @@
 begin
 r:= rect^;
 if Clear then SDL_FillRect(Surface, @r, 0);
+
+BorderColor:= SDL_MapRGB(Surface^.format, BorderColor shr 16, BorderColor shr 8, BorderColor and $FF);
+FillColor:= SDL_MapRGB(Surface^.format, FillColor shr 16, FillColor shr 8, FillColor and $FF);
+
 r.y:= rect^.y + 1;
 r.h:= rect^.h - 2;
 SDL_FillRect(Surface, @r, BorderColor);
@@ -120,6 +124,7 @@
         i: LongInt;
         r, rr: TSDL_Rect;
         drY: LongInt;
+        texsurf: PSDL_Surface;
     begin
     r.x:= 0;
     r.y:= 0;
@@ -132,14 +137,16 @@
       r.w:= cTeamHealthWidth + 5;
       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);
-      TryDo(SDL_SetColorKey(HealthSurf, SDL_SRCCOLORKEY or SDL_RLEACCEL, 0) = 0, errmsgTransparentSet, true);
+      texsurf:= SDL_CreateRGBSurface(SDL_SWSURFACE, r.w, r.h, 32, RMask, GMask, BMask, AMask);
+      TryDo(texsurf <> nil, errmsgCreateSurface, true);
+      TryDo(SDL_SetColorKey(texsurf, SDL_SRCCOLORKEY, 0) = 0, errmsgTransparentSet, true);
 
-      DrawRoundRect(@r, cWhiteColor, cColorNearBlack, HealthSurf, true);
+      DrawRoundRect(@r, cWhiteColor, cColorNearBlack, texsurf, true);
       rr:= r;
       inc(rr.x, 2); dec(rr.w, 4); inc(rr.y, 2); dec(rr.h, 4);
-      DrawRoundRect(@rr, Clan^.AdjColor, Clan^.AdjColor, HealthSurf, false);
+      DrawRoundRect(@rr, Clan^.Color, Clan^.Color, texsurf, false);
+      HealthTex:= Surface2Tex(texsurf);
+      SDL_FreeSurface(texsurf);
 
       dec(drY, r.h + 2);
       DrawHealthY:= drY;
@@ -152,8 +159,9 @@
 
     procedure MakeCrossHairs;
     var t: LongInt;
-        tmpsurf: PSDL_Surface;
+        tmpsurf, texsurf: PSDL_Surface;
         s: string;
+        Color: Longword;
     begin
     s:= Pathz[ptGraphics] + '/' + cCHFileName;
     tmpsurf:= LoadImage(s, true, true, false);
@@ -161,11 +169,18 @@
     for t:= 0 to Pred(TeamsCount) do
       with TeamsArray[t]^ do
       begin
-      CrosshairSurf:= SDL_CreateRGBSurface(SDL_HWSURFACE, tmpsurf^.w, tmpsurf^.h, cBits, PixelFormat^.RMask, PixelFormat^.GMask, PixelFormat^.BMask, PixelFormat^.AMask);
-      TryDo(CrosshairSurf <> nil, errmsgCreateSurface, true);
-      SDL_FillRect(CrosshairSurf, nil, Clan^.AdjColor);
-      SDL_UpperBlit(tmpsurf, nil, CrosshairSurf, nil);
-      TryDo(SDL_SetColorKey(CrosshairSurf, SDL_SRCCOLORKEY or SDL_RLEACCEL, 0) = 0, errmsgTransparentSet, true);
+      texsurf:= SDL_CreateRGBSurface(SDL_SWSURFACE, tmpsurf^.w, tmpsurf^.h, 32, RMask, GMask, BMask, AMask);
+      TryDo(texsurf <> nil, errmsgCreateSurface, true);
+
+      Color:= Clan^.Color;
+      Color:= SDL_MapRGB(texsurf^.format, Color shr 16, Color shr 8, Color and $FF);
+      SDL_FillRect(texsurf, nil, Color);
+
+      SDL_UpperBlit(tmpsurf, nil, texsurf, nil);
+      TryDo(SDL_SetColorKey(texsurf, SDL_SRCCOLORKEY, 0) = 0, errmsgTransparentSet, true);
+
+      CrosshairTex:= Surface2Tex(texsurf);
+      SDL_FreeSurface(texsurf)
       end;
 
     SDL_FreeSurface(tmpsurf)
@@ -186,13 +201,16 @@
 
     procedure LoadGraves;
     var t: LongInt;
+        texsurf: PSDL_Surface;
     begin
     for t:= 0 to Pred(TeamsCount) do
      if TeamsArray[t] <> nil then
       with TeamsArray[t]^ do
           begin
           if GraveName = '' then GraveName:= 'Simple';
-          GraveSurf:= LoadImage(Pathz[ptGraves] + '/' + GraveName, false, true, true);
+          texsurf:= LoadImage(Pathz[ptGraves] + '/' + GraveName, false, true, true);
+          GraveTex:= Surface2Tex(texsurf);
+          SDL_FreeSurface(tmpsurf)
           end
     end;
 
@@ -302,7 +320,7 @@
 
 procedure DrawFromRect(X, Y: LongInt; r: PSDL_Rect; SourceTexture: PTexture; DestSurface: PSDL_Surface);
 var rr: TSDL_Rect;
-    t, b: real;
+    _l, _r, _t, _b: real;
 begin
 if SourceTexture^.h = 0 then exit;
 rr.x:= X;
@@ -310,24 +328,26 @@
 rr.w:= r^.w;
 rr.h:= r^.h;
 
-t:= r^.y / SourceTexture^.h;
-b:= (r^.y + r^.h) / SourceTexture^.h;
+_l:= r^.x / SourceTexture^.w;
+_r:= (r^.x + r^.w) / SourceTexture^.w;
+_t:= r^.y / SourceTexture^.h;
+_b:= (r^.y + r^.h) / SourceTexture^.h;
 
 glBindTexture(GL_TEXTURE_2D, SourceTexture^.id);
 glEnable(GL_TEXTURE_2D);
 
 glBegin(GL_QUADS);
 
-glTexCoord2f(0, t);
+glTexCoord2f(_l, _t);
 glVertex2i(X, Y);
 
-glTexCoord2f(1, t);
+glTexCoord2f(_r, _t);
 glVertex2i(rr.w + X, Y);
 
-glTexCoord2f(1, b);
+glTexCoord2f(_r, _b);
 glVertex2i(rr.w + X, rr.h + Y);
 
-glTexCoord2f(0, b);
+glTexCoord2f(_l, _b);
 glVertex2i(X, rr.h + Y);
 
 glEnd()
@@ -382,14 +402,14 @@
 DrawFromRect(X, Y, @r, SpritesData[Sprite].Texture, Surface)
 end;
 
-procedure DrawSurfSprite(X, Y, Height, Frame: LongInt; Source: GLuint; Surface: PSDL_Surface);
-//var r: TSDL_Rect;
+procedure DrawSurfSprite(X, Y, Height, Frame: LongInt; Source: PTexture; Surface: PSDL_Surface);
+var r: TSDL_Rect;
 begin
-//r.x:= 0;
-//r.w:= Source^.w;
-//r.y:= Frame * Height;
-//r.h:= Height;
-//DrawFromRect(X, Y, @r, Source, Surface)
+r.x:= 0;
+r.w:= Source^.w;
+r.y:= Frame * Height;
+r.h:= Height;
+DrawFromRect(X, Y, @r, Source, Surface)
 end;
 
 procedure DXOutText(X, Y: LongInt; Font: THWFont; s: string; Surface: PSDL_Surface);
@@ -516,7 +536,7 @@
       exit(nil)
       end;
 
-if setTransparent then TryDo(SDL_SetColorKey(tmpsurf, SDL_SRCCOLORKEY or SDL_RLEACCEL, 0) = 0, errmsgTransparentSet, true);
+if setTransparent then TryDo(SDL_SetColorKey(tmpsurf, SDL_SRCCOLORKEY, 0) = 0, errmsgTransparentSet, true);
 //if hasAlpha then Result:= SDL_DisplayFormatAlpha(tmpsurf)
 //            else Result:= SDL_DisplayFormat(tmpsurf);
 {$IFDEF DEBUGFILE}WriteLnToConsole('(' + inttostr(tmpsurf^.w) + ',' + inttostr(tmpsurf^.h) + ') ');{$ENDIF}
--- a/hedgewars/uTeams.pas	Sun Jan 27 15:07:31 2008 +0000
+++ b/hedgewars/uTeams.pas	Sun Jan 27 16:49:11 2008 +0000
@@ -51,9 +51,9 @@
              Hedgehogs: array[0..cMaxHHIndex] of THedgehog;
              CurrHedgehog: LongWord;
              NameTagTex: PTexture;
-             CrosshairSurf,
-             GraveSurf,
-             HealthSurf: PSDL_Surface;
+             CrosshairTex,
+             GraveTex,
+             HealthTex: PTexture;
              GraveName: string;
              FortName: string;
              TeamHealth: LongInt;
@@ -64,7 +64,7 @@
              HedgehogsNumber: Longword;
              end;
      TClan = record
-             Color, AdjColor: Longword;
+             Color: Longword;
              Teams: array[0..Pred(cMaxTeams)] of PTeam;
              TeamsNumber: Longword;
              CurrTeam: LongWord;
@@ -223,9 +223,7 @@
    with Result^.Clan^ do
         begin
         ClanIndex:= Pred(ClansCount);
-        Color:= TeamColor;
-        AdjColor:= Color;
-        AdjustColor(AdjColor);
+        Color:= TeamColor
         end
    end else
    begin
--- a/hedgewars/uWorld.pas	Sun Jan 27 15:07:31 2008 +0000
+++ b/hedgewars/uWorld.pas	Sun Jan 27 16:49:11 2008 +0000
@@ -282,18 +282,18 @@
       r.x:= 0;
       r.y:= 0;
       r.w:= 2 + TeamHealthBarWidth;
-      r.h:= HealthSurf^.h;
+      r.h:= HealthTex^.h;
 
-//      DrawFromRect(cScreenWidth div 2,
-//                        DrawHealthY,
-//                        @r, HealthSurf, Surface);
+      DrawFromRect(cScreenWidth div 2,
+                        DrawHealthY,
+                        @r, HealthTex, Surface);
 
       inc(r.x, cTeamHealthWidth + 2);
       r.w:= 3;
 
-//      DrawFromRect(cScreenWidth div 2 + TeamHealthBarWidth + 2,
-//                        DrawHealthY,
-//                        @r, HealthSurf, Surface);
+      DrawFromRect(cScreenWidth div 2 + TeamHealthBarWidth + 2,
+                        DrawHealthY,
+                        @r, HealthTex, Surface);
       end;
 
 // Lag alert
@@ -309,7 +309,7 @@
    r.y:= 0;
    r.w:= WindBarWidth;
    r.h:= 13;
-//   DrawSpriteFromRect(sprWindR, r, cScreenWidth - 103, cScreenHeight - 28, 13, 0, Surface);
+   DrawSpriteFromRect(sprWindR, r, cScreenWidth - 103, cScreenHeight - 28, 13, 0, Surface);
    end else
  if WindBarWidth < 0 then
    begin
@@ -319,7 +319,7 @@
    r.y:= 0;
    r.w:= - WindBarWidth;
    r.h:= 13;
-//   DrawSpriteFromRect(sprWindL, r, cScreenWidth - 106 + WindBarWidth, cScreenHeight - 28, 13, 0, Surface);
+   DrawSpriteFromRect(sprWindL, r, cScreenWidth - 106 + WindBarWidth, cScreenHeight - 28, 13, 0, Surface);
    end;
 
 // AmmoMenu