Now show sprites too
authorunc0rr
Fri, 25 Jan 2008 23:33:35 +0000
changeset 755 edf26e9554ac
parent 754 94ac14829085
child 756 2b307457fd68
Now show sprites too
hedgewars/uConsts.pas
hedgewars/uGears.pas
hedgewars/uLand.pas
hedgewars/uLandGraphics.pas
hedgewars/uMisc.pas
hedgewars/uStore.pas
hedgewars/uWorld.pas
--- a/hedgewars/uConsts.pas	Fri Jan 25 21:55:48 2008 +0000
+++ b/hedgewars/uConsts.pas	Fri Jan 25 23:33:35 2008 +0000
@@ -18,7 +18,7 @@
 
 unit uConsts;
 interface
-uses SDLh, uLocale;
+uses SDLh, GL, uLocale;
 {$INCLUDE options.inc}
 {$INCLUDE proto.inc}
 type
@@ -83,6 +83,11 @@
              Pos: LongWord;
              AmmoType: TAmmoType;
              end;
+     TTexture = record
+                id: GLuint;
+                w, h: LongInt;
+                end;
+     PTexture = ^TTexture;
 
 
 const
@@ -233,101 +238,101 @@
       SpritesData: array[TSprite] of record
                      FileName: String[31];
                      Path, AltPath: TPathType;
-                     Surface : PSDL_Surface;
+                     Texture: PTexture;
                      Width, Height: LongInt;
                      hasAlpha: boolean;
                      end = (
-                     (FileName:  'BlueWater'; Path: ptGraphics; AltPath: ptNone; Surface: nil;
+                     (FileName:  'BlueWater'; Path: ptGraphics; AltPath: ptNone; Texture: nil;
                       Width: 256; Height: 48; hasAlpha: false),// sprWater
-                     (FileName:     'Clouds'; Path: ptCurrTheme; AltPath: ptGraphics; Surface: nil;
+                     (FileName:     'Clouds'; Path: ptCurrTheme;AltPath: ptGraphics; Texture: nil;
                       Width: 256; Height:128; hasAlpha: false),// sprCloud
-                     (FileName:       'Bomb'; Path: ptGraphics; AltPath: ptNone; Surface: nil;
+                     (FileName:       'Bomb'; Path: ptGraphics; AltPath: ptNone; Texture: nil;
                       Width:  16; Height: 16; hasAlpha: false),// sprBomb
-                     (FileName:  'BigDigits'; Path: ptGraphics; AltPath: ptNone; Surface: nil;
+                     (FileName:  'BigDigits'; Path: ptGraphics; AltPath: ptNone; Texture: nil;
                       Width:  32; Height: 32; hasAlpha:  true),// sprBigDigit
-                     (FileName:      'Frame'; Path: ptGraphics; AltPath: ptNone; Surface: nil;
+                     (FileName:      'Frame'; Path: ptGraphics; AltPath: ptNone; Texture: nil;
                       Width:   4; Height: 32; hasAlpha:  true),// sprFrame
-                     (FileName:        'Lag'; Path: ptGraphics; AltPath: ptNone; Surface: nil;
+                     (FileName:        'Lag'; Path: ptGraphics; AltPath: ptNone; Texture: nil;
                       Width:  65; Height: 65; hasAlpha:  true),// sprLag
-                     (FileName:      'Arrow'; Path: ptGraphics; AltPath: ptNone; Surface: nil;
+                     (FileName:      'Arrow'; Path: ptGraphics; AltPath: ptNone; Texture: nil;
                       Width:  16; Height: 16; hasAlpha: false),// sprCursor
-                     (FileName:    'Grenade'; Path: ptGraphics; AltPath: ptNone; Surface: nil;
+                     (FileName:    'Grenade'; Path: ptGraphics; AltPath: ptNone; Texture: nil;
                       Width:  32; Height: 32; hasAlpha: false),// sprGrenade
-                     (FileName:    'Targetp'; Path: ptGraphics; AltPath: ptNone; Surface: nil;
+                     (FileName:    'Targetp'; Path: ptGraphics; AltPath: ptNone; Texture: nil;
                       Width:  32; Height: 32; hasAlpha: false),// sprTargetP
-                     (FileName:        'UFO'; Path: ptGraphics; AltPath: ptNone; Surface: nil;
+                     (FileName:        'UFO'; Path: ptGraphics; AltPath: ptNone; Texture: nil;
                       Width:  32; Height: 32; hasAlpha: false),// sprUFO
-                     (FileName: 'SmokeTrace'; Path: ptGraphics; AltPath: ptNone; Surface: nil;
+                     (FileName: 'SmokeTrace'; Path: ptGraphics; AltPath: ptNone; Texture: nil;
                       Width:  32; Height: 32; hasAlpha:  true),// sprSmokeTrace
-                     (FileName:   'RopeHook'; Path: ptGraphics; AltPath: ptNone; Surface: nil;
+                     (FileName:   'RopeHook'; Path: ptGraphics; AltPath: ptNone; Texture: nil;
                       Width:  32; Height: 32; hasAlpha: false),// sprRopeHook
-                     (FileName:     'Expl50'; Path: ptGraphics; AltPath: ptNone; Surface: nil;
+                     (FileName:     'Expl50'; Path: ptGraphics; AltPath: ptNone; Texture: nil;
                       Width:  64; Height: 64; hasAlpha: false),// sprExplosion50
-                     (FileName:    'MineOff'; Path: ptGraphics; AltPath: ptNone; Surface: nil;
+                     (FileName:    'MineOff'; Path: ptGraphics; AltPath: ptNone; Texture: nil;
                       Width:  16; Height: 16; hasAlpha: false),// sprMineOff
-                     (FileName:     'MineOn'; Path: ptGraphics; AltPath: ptNone; Surface: nil;
+                     (FileName:     'MineOn'; Path: ptGraphics; AltPath: ptNone; Texture: nil;
                       Width:  16; Height: 16; hasAlpha: false),// sprMineOn
-                     (FileName:       'Case'; Path: ptGraphics; AltPath: ptNone; Surface: nil;
+                     (FileName:       'Case'; Path: ptGraphics; AltPath: ptNone; Texture: nil;
                       Width:  32; Height: 32; hasAlpha: false),// sprCase
-                     (FileName:   'FirstAid'; Path: ptGraphics; AltPath: ptNone; Surface: nil;
+                     (FileName:   'FirstAid'; Path: ptGraphics; AltPath: ptNone; Texture: nil;
                       Width:  48; Height: 48; hasAlpha: false),// sprFAid
-                     (FileName:   'dynamite'; Path: ptGraphics; AltPath: ptNone; Surface: nil;
+                     (FileName:   'dynamite'; Path: ptGraphics; AltPath: ptNone; Texture: nil;
                       Width:  32; Height: 32; hasAlpha: false),// sprDynamite
-                     (FileName:      'Power'; Path: ptGraphics; AltPath: ptNone; Surface: nil;
+                     (FileName:      'Power'; Path: ptGraphics; AltPath: ptNone; Texture: nil;
                       Width:  32; Height: 32; hasAlpha:  true),// sprPower
-                     (FileName:     'ClBomb'; Path: ptGraphics; AltPath: ptNone; Surface: nil;
+                     (FileName:     'ClBomb'; Path: ptGraphics; AltPath: ptNone; Texture: nil;
                       Width:  16; Height: 16; hasAlpha: false),// sprClusterBomb
-                     (FileName: 'ClParticle'; Path: ptGraphics; AltPath: ptNone; Surface: nil;
+                     (FileName: 'ClParticle'; Path: ptGraphics; AltPath: ptNone; Texture: nil;
                       Width:  16; Height: 16; hasAlpha: false),// sprClusterParticle
-                     (FileName:      'Flame'; Path: ptGraphics; AltPath: ptNone; Surface: nil;
+                     (FileName:      'Flame'; Path: ptGraphics; AltPath: ptNone; Texture: nil;
                       Width:  16; Height: 16; hasAlpha: false),// sprFlame
-                     (FileName:   'horizont'; Path: ptCurrTheme; AltPath: ptNone; Surface: nil;
+                     (FileName:   'horizont'; Path: ptCurrTheme; AltPath: ptNone; Texture: nil;
                       Width:   0; Height:  0; hasAlpha: false),// sprHorizont
-                     (FileName:        'Sky'; Path: ptCurrTheme; AltPath: ptNone; Surface: nil;
+                     (FileName:        'Sky'; Path: ptCurrTheme; AltPath: ptNone; Texture: nil;
                       Width:   0; Height:  0; hasAlpha: false),// sprSky
-                     (FileName:  'BrdrLines'; Path: ptAmmoMenu; AltPath: ptNone; Surface: nil;
+                     (FileName:  'BrdrLines'; Path: ptAmmoMenu; AltPath: ptNone; Texture: nil;
                       Width: 202; Height:  1; hasAlpha: false),// sprAMBorders
-                     (FileName:       'Slot'; Path: ptAmmoMenu; AltPath: ptNone; Surface: nil;
+                     (FileName:       'Slot'; Path: ptAmmoMenu; AltPath: ptNone; Texture: nil;
                       Width: 202; Height: 33; hasAlpha: false),// sprAMSlot
-                     (FileName:   'AmmoName'; Path: ptAmmoMenu; AltPath: ptNone; Surface: nil;
+                     (FileName:   'AmmoName'; Path: ptAmmoMenu; AltPath: ptNone; Texture: nil;
                       Width: 202; Height: 33; hasAlpha: false),// sprAMSlotName
-                     (FileName:      'Ammos'; Path: ptAmmoMenu; AltPath: ptNone; Surface: nil;
+                     (FileName:      'Ammos'; Path: ptAmmoMenu; AltPath: ptNone; Texture: nil;
                       Width:  32; Height: 32; hasAlpha: false),// sprAMAmmos
-                     (FileName:   'SlotKeys'; Path: ptAmmoMenu; AltPath: ptNone; Surface: nil;
+                     (FileName:   'SlotKeys'; Path: ptAmmoMenu; AltPath: ptNone; Texture: nil;
                       Width:  32; Height: 32; hasAlpha: false),// sprAMSlotKeys
-                     (FileName:  'Selection'; Path: ptAmmoMenu; AltPath: ptNone; Surface: nil;
+                     (FileName:  'Selection'; Path: ptAmmoMenu; AltPath: ptNone; Texture: nil;
                       Width:  32; Height: 32; hasAlpha: false),// sprAMSelection
-                     (FileName:     'Finger'; Path: ptGraphics; AltPath: ptNone; Surface: nil;
+                     (FileName:     'Finger'; Path: ptGraphics; AltPath: ptNone; Texture: nil;
                       Width:  32; Height: 48; hasAlpha: false),// sprFinger
-                     (FileName:    'AirBomb'; Path: ptGraphics; AltPath: ptNone; Surface: nil;
+                     (FileName:    'AirBomb'; Path: ptGraphics; AltPath: ptNone; Texture: nil;
                       Width:  32; Height: 32; hasAlpha: false),// sprAirBomb
-                     (FileName:   'Airplane'; Path: ptGraphics; AltPath: ptNone; Surface: nil;
+                     (FileName:   'Airplane'; Path: ptGraphics; AltPath: ptNone; Texture: nil;
                       Width: 125; Height: 42; hasAlpha: false),// sprAirplane
-                     (FileName: 'amAirplane'; Path: ptGraphics; AltPath: ptNone; Surface: nil;
+                     (FileName: 'amAirplane'; Path: ptGraphics; AltPath: ptNone; Texture: nil;
                       Width:  64; Height: 32; hasAlpha:  true),// sprAirplane
-                     (FileName:   'amGirder'; Path: ptGraphics; AltPath: ptNone; Surface: nil;
+                     (FileName:   'amGirder'; Path: ptGraphics; AltPath: ptNone; Texture: nil;
                       Width: 160; Height:160; hasAlpha: false),// sprAmGirder
-                     (FileName:     'hhMask'; Path: ptGraphics; AltPath: ptNone; Surface: nil;
+                     (FileName:     'hhMask'; Path: ptGraphics; AltPath: ptNone; Texture: nil;
                       Width:  32; Height: 32; hasAlpha: false),// sprHHTelepMask
-                     (FileName:     'Switch'; Path: ptGraphics; AltPath: ptNone; Surface: nil;
+                     (FileName:     'Switch'; Path: ptGraphics; AltPath: ptNone; Texture: nil;
                       Width:  32; Height: 32; hasAlpha:  true),// sprSwitch
-                     (FileName:  'Parachute'; Path: ptGraphics; AltPath: ptNone; Surface: nil;
+                     (FileName:  'Parachute'; Path: ptGraphics; AltPath: ptNone; Texture: nil;
                       Width:  48; Height: 48; hasAlpha:  true),// sprParachute
-                     (FileName:     'Target'; Path: ptGraphics; AltPath: ptNone; Surface: nil;
+                     (FileName:     'Target'; Path: ptGraphics; AltPath: ptNone; Texture: nil;
                       Width:  32; Height: 32; hasAlpha: false),// sprTarget
-                     (FileName:   'RopeNode'; Path: ptGraphics; AltPath: ptNone; Surface: nil;
+                     (FileName:   'RopeNode'; Path: ptGraphics; AltPath: ptNone; Texture: nil;
                       Width:   6; Height:  6; hasAlpha: false),// sprRopeNode
-                     (FileName:    'Console'; Path: ptGraphics; AltPath: ptNone; Surface: nil;
+                     (FileName:    'Console'; Path: ptGraphics; AltPath: ptNone; Texture: nil;
                       Width: 256; Height:256; hasAlpha: false),// sprConsoleBG
-                     (FileName:   'thinking'; Path: ptGraphics; AltPath: ptNone; Surface: nil;
+                     (FileName:   'thinking'; Path: ptGraphics; AltPath: ptNone; Texture: nil;
                       Width:  32; Height: 32; hasAlpha: false),// sprQuestion
-                     (FileName:   'PowerBar'; Path: ptGraphics; AltPath: ptNone; Surface: nil;
+                     (FileName:   'PowerBar'; Path: ptGraphics; AltPath: ptNone; Texture: nil;
                       Width: 256; Height: 32; hasAlpha: false),// sprPowerBar
-                     (FileName:    'WindBar'; Path: ptGraphics; AltPath: ptNone; Surface: nil;
+                     (FileName:    'WindBar'; Path: ptGraphics; AltPath: ptNone; Texture: nil;
                       Width: 151; Height: 17; hasAlpha: false),// sprWindBar
-                     (FileName:      'WindL'; Path: ptGraphics; AltPath: ptNone; Surface: nil;
+                     (FileName:      'WindL'; Path: ptGraphics; AltPath: ptNone; Texture: nil;
                       Width:  80; Height: 13; hasAlpha: false),// sprWindL
-                     (FileName:      'WindR'; Path: ptGraphics; AltPath: ptNone; Surface: nil;
+                     (FileName:      'WindR'; Path: ptGraphics; AltPath: ptNone; Texture: nil;
                       Width:  80; Height: 13; hasAlpha: false) // sprWindR
                      );
 
--- a/hedgewars/uGears.pas	Fri Jan 25 21:55:48 2008 +0000
+++ b/hedgewars/uGears.pas	Fri Jan 25 23:33:35 2008 +0000
@@ -493,10 +493,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^.CrosshairSurf, Surface);*)
         end;
 end;
 
@@ -578,7 +578,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^.Surf <> nil then DrawCentered(hwRound(Gear^.X) + WorldDx, hwRound(Gear^.Y) + WorldDy, Gear^.Surf, Surface);
-           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^.GraveSurf, 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/uLand.pas	Fri Jan 25 21:55:48 2008 +0000
+++ b/hedgewars/uLand.pas	Fri Jan 25 23:33:35 2008 +0000
@@ -18,21 +18,21 @@
 
 unit uLand;
 interface
-uses SDLh, uLandTemplates, uFloat, GL;
+uses SDLh, uLandTemplates, uFloat, GL, uConsts;
 {$include options.inc}
 type TLandArray = packed array[0..1023, 0..2047] of LongWord;
      TPreview = packed array[0..127, 0..31] of byte;
 
 var  Land: TLandArray;
      LandSurface: PSDL_Surface;
-     LandTexture: GLuint;
+     LandTexture: PTexture;
 
 procedure GenMap;
 function GenPreview: TPreview;
 procedure CheckLandDigest(s: shortstring);
 
 implementation
-uses uConsole, uStore, uMisc, uConsts, uRandom, uTeams, uLandObjects, uSHA, uIO;
+uses uConsole, uStore, uMisc, uRandom, uTeams, uLandObjects, uSHA, uIO;
 
 type TPixAr = record
               Count: Longword;
--- a/hedgewars/uLandGraphics.pas	Fri Jan 25 21:55:48 2008 +0000
+++ b/hedgewars/uLandGraphics.pas	Fri Jan 25 23:33:35 2008 +0000
@@ -321,12 +321,12 @@
 end;
 
 function TryPlaceOnLand(cpX, cpY: LongInt; Obj: TSprite; Frame: LongInt; doPlace: boolean): boolean;
-var X, Y, bpp, h, w: LongInt;
+(*var X, Y, bpp, h, w: LongInt;
     p: PByteArray;
     r, rr: TSDL_Rect;
-    Image: PSDL_Surface;
+    Image: PSDL_Surface;*)
 begin
-Image:= SpritesData[Obj].Surface;
+(*Image:= SpritesData[Obj].Surface;
 w:= SpritesData[Obj].Width;
 h:= SpritesData[Obj].Height; 
 
@@ -421,7 +421,7 @@
 r.h:= SpritesData[Obj].Height;
 rr.x:= cpX;
 rr.y:= cpY;
-SDL_UpperBlit(Image, @r, LandSurface, @rr)
+SDL_UpperBlit(Image, @r, LandSurface, @rr)*)
 end;
 
 
--- a/hedgewars/uMisc.pas	Fri Jan 25 21:55:48 2008 +0000
+++ b/hedgewars/uMisc.pas	Fri Jan 25 23:33:35 2008 +0000
@@ -116,7 +116,7 @@
 procedure SetLittle(var r: hwFloat);
 procedure SendStat(sit: TStatInfoType; s: shortstring);
 function  Str2PChar(const s: shortstring): PChar;
-function  Surface2Tex(surf: PSDL_Surface): GLuint;
+function  Surface2Tex(surf: PSDL_Surface): PTexture;
 
 var CursorPoint: TPoint;
     TargetPoint: TPoint = (X: NoPointX; Y: 0);
@@ -254,24 +254,28 @@
 RectToStr:= '(x: ' + inttostr(rect.x) + '; y: ' + inttostr(rect.y) + '; w: ' + inttostr(rect.w) + '; h: ' + inttostr(rect.h) + ')'
 end;
 
-function Surface2Tex(surf: PSDL_Surface): GLuint;
+function Surface2Tex(surf: PSDL_Surface): PTexture;
 var mode: LongInt;
     texId: GLuint;
 begin
 if SDL_MustLock(surf) then
    SDLTry(SDL_LockSurface(surf) >= 0, true);
 
+new(Surface2Tex);
+Surface2Tex^.w:= surf^.w;
+Surface2Tex^.h:= surf^.h;
+
 if (surf^.format^.BytesPerPixel = 3) then mode:= GL_RGB else
 if (surf^.format^.BytesPerPixel = 4) then mode:= GL_RGBA else
    begin
-   TryDo(false, 'Surface2Tex: BytePerPixel not in [3, 4]', true);
-   Surface2Tex:= 0;
+   TryDo(false, 'Surface2Tex: BytePerPixel not in [3, 4]', false);
+   Surface2Tex^.id:= 0;
    exit
    end;
 
-glGenTextures(1, @texId);
+glGenTextures(1, @Surface2Tex^.id);
 
-glBindTexture(GL_TEXTURE_2D, texId);
+glBindTexture(GL_TEXTURE_2D, Surface2Tex^.id);
 
 glTexImage2D(GL_TEXTURE_2D, 0, mode, surf^.w, surf^.h, 0, mode, GL_UNSIGNED_BYTE, surf^.pixels);
 
@@ -279,9 +283,7 @@
    SDL_UnlockSurface(surf);
 
 glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_NEAREST);
-glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);
-
-Surface2Tex:= texId
+glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR)
 end;
 
 
--- a/hedgewars/uStore.pas	Fri Jan 25 21:55:48 2008 +0000
+++ b/hedgewars/uStore.pas	Fri Jan 25 23:33:35 2008 +0000
@@ -18,7 +18,7 @@
 
 unit uStore;
 interface
-uses uConsts, uTeams, SDLh, uFloat;
+uses uConsts, uTeams, SDLh, uFloat, GL;
 {$INCLUDE options.inc}
 
 procedure StoreInit;
@@ -27,11 +27,11 @@
 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, Surface: PSDL_Surface);
+procedure DrawSurfSprite(X, Y, Height, Frame: LongInt; Source: GLuint; Surface: PSDL_Surface);
 procedure DrawLand (X, Y: LongInt; Surface: PSDL_Surface);
 procedure DXOutText(X, Y: LongInt; Font: THWFont; s: string; Surface: PSDL_Surface);
 procedure DrawCentered(X, Top: LongInt; Source, Surface: PSDL_Surface);
-procedure DrawFromRect(X, Y: LongInt; r: PSDL_Rect; SourceSurface, DestSurface: PSDL_Surface);
+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;
 procedure RenderHealth(var Hedgehog: THedgehog);
@@ -45,7 +45,7 @@
    PauseSurface: PSDL_Surface;
 
 implementation
-uses uMisc, uConsole, uLand, uLocale, GL, GLU;
+uses uMisc, uConsole, uLand, uLocale, GLU;
 
 var
     HHSurface: PSDL_Surface;
@@ -196,9 +196,9 @@
     end;
 
     procedure GetSkyColor;
-    var p: PByteArray;
+//    var p: PByteArray;
     begin
-    if SDL_MustLock(SpritesData[sprSky].Surface) then
+(*    if SDL_MustLock(SpritesData[sprSky].Surface) then
        SDLTry(SDL_LockSurface(SpritesData[sprSky].Surface) >= 0, true);
     p:= SpritesData[sprSky].Surface^.pixels;
     case SpritesData[sprSky].Surface^.format^.BytesPerPixel of
@@ -206,11 +206,12 @@
          2: cSkyColor:= PWord(p)^;
          3: cSkyColor:= (p^[0]) or (p^[1] shl 8) or (p^[2] shl 16);
          4: cSkyColor:= PLongword(p)^;
-         end;
+         end;*)
+    cSkyColor:= $3030A0;
     glClearColor((cSkyColor shr 16) / 255, ((cSkyColor shr 8) and $FF) / 255, (cSkyColor and $FF) / 255, 0);
 
-    if SDL_MustLock(SpritesData[sprSky].Surface) then
-       SDL_UnlockSurface(SpritesData[sprSky].Surface)
+//    if SDL_MustLock(SpritesData[sprSky].Surface) then
+//       SDL_UnlockSurface(SpritesData[sprSky].Surface)
     end;
 
     procedure GetExplosionBorderColor;
@@ -268,14 +269,15 @@
     with SpritesData[ii] do
          begin
          if AltPath = ptNone then
-            Surface:= LoadImage(Pathz[Path] + '/' + FileName, hasAlpha, true, true)
+            tmpsurf:= LoadImage(Pathz[Path] + '/' + FileName, hasAlpha, true, true)
          else begin
-            Surface:= LoadImage(Pathz[Path] + '/' + FileName, hasAlpha, false, true);
-            if Surface = nil then
-               Surface:= LoadImage(Pathz[AltPath] + '/' + FileName, hasAlpha, true, true)
+            tmpsurf:= LoadImage(Pathz[Path] + '/' + FileName, hasAlpha, false, true);
+            if tmpsurf = nil then
+               tmpsurf:= LoadImage(Pathz[AltPath] + '/' + FileName, hasAlpha, true, true)
             end;
-         if Width = 0 then Width:= Surface^.w;
-         if Height = 0 then Height:= Surface^.h
+         if Width = 0 then Width:= tmpsurf^.w;
+         if Height = 0 then Height:= tmpsurf^.h;
+         Texture:= Surface2Tex(tmpsurf)
          end;
 
 GetSkyColor;
@@ -294,30 +296,53 @@
 {$ENDIF}
 end;
 
-procedure DrawFromRect(X, Y: LongInt; r: PSDL_Rect; SourceSurface, DestSurface: PSDL_Surface);
+procedure DrawFromRect(X, Y: LongInt; r: PSDL_Rect; SourceTexture: PTexture; DestSurface: PSDL_Surface);
 var rr: TSDL_Rect;
+    t, b: real;
 begin
 rr.x:= X;
 rr.y:= Y;
 rr.w:= r^.w;
 rr.h:= r^.h;
-if SDL_UpperBlit(SourceSurface, r, DestSurface, @rr) < 0 then
-   begin
-   OutError('Blit: ' + SDL_GetError, true);
-   exit
-   end;
+
+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);
+glVertex2i(X, Y);
+
+glTexCoord2f(1, t);
+glVertex2i(rr.w + X, Y);
+
+glTexCoord2f(1, b);
+glVertex2i(rr.w + X, rr.h + Y);
+
+glTexCoord2f(0, b);
+glVertex2i(X, rr.h + Y);
+
+glEnd();
 end;
 
 procedure DrawSpriteFromRect(Sprite: TSprite; r: TSDL_Rect; X, Y, Height, Position: LongInt; Surface: PSDL_Surface);
 begin
 r.y:= r.y + Height * Position;
 r.h:= Height;
-DrawFromRect(X, Y, @r, SpritesData[Sprite].Surface, Surface)
+DrawFromRect(X, Y, @r, SpritesData[Sprite].Texture, Surface)
 end;
 
 procedure DrawSprite (Sprite: TSprite; X, Y, Frame: LongInt; Surface: PSDL_Surface);
+var r: TSDL_Rect;
 begin
-DrawSurfSprite(X, Y, SpritesData[Sprite].Height, Frame, SpritesData[Sprite].Surface, Surface)
+r.x:= 0;
+r.w:= SpritesData[Sprite].Width;
+r.y:= Frame * SpritesData[Sprite].Height;
+r.h:= SpritesData[Sprite].Height;
+DrawFromRect(X, Y, @r, SpritesData[Sprite].Texture, Surface)
 end;
 
 procedure DrawSprite2(Sprite: TSprite; X, Y, FrameX, FrameY: LongInt; Surface: PSDL_Surface);
@@ -327,17 +352,17 @@
 r.w:= SpritesData[Sprite].Width;
 r.y:= FrameY * SpritesData[Sprite].Height;
 r.h:= SpritesData[Sprite].Height;
-DrawFromRect(X, Y, @r, SpritesData[Sprite].Surface, Surface)
+DrawFromRect(X, Y, @r, SpritesData[Sprite].Texture, Surface)
 end;
 
-procedure DrawSurfSprite(X, Y, Height, Frame: LongInt; Source, Surface: PSDL_Surface);
-var r: TSDL_Rect;
+procedure DrawSurfSprite(X, Y, Height, Frame: LongInt; Source: GLuint; 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);
@@ -361,30 +386,26 @@
 end;
 
 procedure DrawLand(X, Y: LongInt; Surface: PSDL_Surface);
-const r: TSDL_Rect = (x: 0; y: 0; w: 2048; h: 1024);
+//const r: TSDL_Rect = (x: 0; y: 0; w: 2048; h: 1024);
 begin
-glBindTexture(GL_TEXTURE_2D, LandTexture);
+glBindTexture(GL_TEXTURE_2D, LandTexture^.id);
 glEnable(GL_TEXTURE_2D);
 
-        glBegin(GL_QUADS);
+glBegin(GL_QUADS);
 
-        // top left
-        glTexCoord2i(0, 0);
-        glVertex2i(X, Y);
+glTexCoord2i(0, 0);
+glVertex2i(X, Y);
 
-        // top right
-        glTexCoord2i(1, 0);
-        glVertex2i(2048 + X, Y);
+glTexCoord2i(1, 0);
+glVertex2i(2048 + X, Y);
 
-        // bottom right
-        glTexCoord2i(1, 1);
-        glVertex2i(2048 + X, 1024 + Y);
+glTexCoord2i(1, 1);
+glVertex2i(2048 + X, 1024 + Y);
 
-        // bottom left
-        glTexCoord2i(0, 1);
-        glVertex2i(X, 1024 + Y);
+glTexCoord2i(0, 1);
+glVertex2i(X, 1024 + Y);
 
-        glEnd();
+glEnd();
 //DrawFromRect(X, Y, @r, LandSurface, Surface)
 end;
 
@@ -406,14 +427,14 @@
 if Dir = -1 then r.x:= HHSurface^.w - 32 - r.x;
 r.w:= 32;
 r.h:= 32;
-DrawFromRect(X, Y, @r, HHSurface, Surface)
+//DrawFromRect(X, Y, @r, HHSurface, Surface)
 end;
 
 procedure StoreRelease;
 var ii: TSprite;
 begin
 for ii:= Low(TSprite) to High(TSprite) do
-    SDL_FreeSurface(SpritesData[ii].Surface);
+    glDeleteTextures(1, @SpritesData[ii].Texture);
 SDL_FreeSurface(  HHSurface  );
 SDL_FreeSurface(LandSurface  )
 end;
@@ -502,8 +523,8 @@
 r.w:= ProgrSurf^.w;
 r.h:= ProgrSurf^.w;
 r.y:= (Step mod (ProgrSurf^.h div ProgrSurf^.w)) * ProgrSurf^.w;
-DrawFromRect((cScreenWidth - ProgrSurf^.w) div 2,
-             (cScreenHeight - ProgrSurf^.w) div 2, @r, ProgrSurf, SDLPrimSurface);
+//DrawFromRect((cScreenWidth - ProgrSurf^.w) div 2,
+//             (cScreenHeight - ProgrSurf^.w) div 2, @r, ProgrSurf, SDLPrimSurface);
 SDL_Flip(SDLPrimSurface);
 inc(Step);
 end;
--- a/hedgewars/uWorld.pas	Fri Jan 25 21:55:48 2008 +0000
+++ b/hedgewars/uWorld.pas	Fri Jan 25 23:33:35 2008 +0000
@@ -182,8 +182,8 @@
 //   SDL_FillRect(Surface, @r, cSkyColor)
    end;
 // background
-//DrawRepeated(sprSky, WorldDx * 3 div 8);
-//DrawRepeated(sprHorizont, WorldDx * 3 div 5);
+DrawRepeated(sprSky, WorldDx * 3 div 8);
+DrawRepeated(sprHorizont, WorldDx * 3 div 5);
 
 // Waves
 {$WARNINGS OFF}
@@ -203,7 +203,7 @@
 //   SDL_FillRect(Surface, @r, cWaterColor)
    end;
 
-//DrawGears(Surface);
+DrawGears(Surface);
 
 // Waves
 {$WARNINGS OFF}