- Some optimizations
- Rotate grenade sprite using glRotatef (much better result)
--- a/hedgewars/uConsts.pas Mon Jan 28 17:51:18 2008 +0000
+++ b/hedgewars/uConsts.pas Mon Jan 28 18:22:35 2008 +0000
@@ -258,7 +258,7 @@
(FileName: 'Arrow'; Path: ptGraphics; AltPath: ptNone; Texture: nil; Surface: nil;
Width: 16; Height: 16; saveSurf: false),// sprCursor
(FileName: 'Grenade'; Path: ptGraphics; AltPath: ptNone; Texture: nil; Surface: nil;
- Width: 32; Height: 32; saveSurf: false),// sprGrenade
+ Width: 16; Height: 16; saveSurf: false),// sprGrenade
(FileName: 'Targetp'; Path: ptGraphics; AltPath: ptNone; Texture: nil; Surface: nil;
Width: 32; Height: 32; saveSurf: false),// sprTargetP
(FileName: 'UFO'; Path: ptGraphics; AltPath: ptNone; Texture: nil; Surface: nil;
--- a/hedgewars/uGears.pas Mon Jan 28 17:51:18 2008 +0000
+++ b/hedgewars/uGears.pas Mon Jan 28 18:22:35 2008 +0000
@@ -577,7 +577,7 @@
gtCloud: DrawSprite(sprCloud , hwRound(Gear^.X) + WorldDx, hwRound(Gear^.Y) + WorldDy, Gear^.State, Surface);
gtAmmo_Bomb: DrawSprite(sprBomb , hwRound(Gear^.X) - 8 + WorldDx, hwRound(Gear^.Y) - 8 + WorldDy, hwRound(Gear^.DirAngle), Surface);
gtHedgehog: DrawHH(Gear, Surface);
- gtAmmo_Grenade: DrawSprite(sprGrenade , hwRound(Gear^.X) - 16 + WorldDx, hwRound(Gear^.Y) - 16 + WorldDy, DxDy2Angle32(Gear^.dY, Gear^.dX), Surface);
+ gtAmmo_Grenade: DrawRotated(sprGrenade, hwRound(Gear^.X) + WorldDx, hwRound(Gear^.Y) + WorldDy, DxDy2Angle(Gear^.dY, Gear^.dX));//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^.GraveTex, Surface);
--- a/hedgewars/uMisc.pas Mon Jan 28 17:51:18 2008 +0000
+++ b/hedgewars/uMisc.pas Mon Jan 28 18:22:35 2008 +0000
@@ -104,6 +104,7 @@
procedure SDLTry(Assert: boolean; isFatal: boolean);
function IntToStr(n: LongInt): shortstring;
function FloatToStr(n: hwFloat): shortstring;
+function DxDy2Angle(const _dY, _dX: hwFloat): GLfloat;
function DxDy2Angle32(const _dY, _dX: hwFloat): LongInt;
function DxDy2AttackAngle(const _dY, _dX: hwFloat): LongInt;
procedure AdjustColor(var Color: Longword);
@@ -181,6 +182,16 @@
FloatToStr:= cstr(n)
end;
+function DxDy2Angle(const _dY, _dX: hwFloat): GLfloat;
+var dY, dX: Extended;
+begin
+dY:= _dY.QWordValue / $100000000;
+if _dY.isNegative then dY:= - dY;
+dX:= _dX.QWordValue / $100000000;
+if _dX.isNegative then dX:= - dX;
+DxDy2Angle:= arctan2(dY, dX) * 180 / pi
+end;
+
function DxDy2Angle32(const _dY, _dX: hwFloat): LongInt;
const _16divPI: Extended = 16/pi;
var dY, dX: Extended;
--- a/hedgewars/uStore.pas Mon Jan 28 17:51:18 2008 +0000
+++ b/hedgewars/uStore.pas Mon Jan 28 18:22:35 2008 +0000
@@ -30,6 +30,7 @@
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 DrawRotated(Sprite: TSprite; X, Y: LongInt; Angle: real);
procedure DXOutText(X, Y: LongInt; Font: THWFont; s: string; Surface: PSDL_Surface);
procedure DrawCentered(X, Top: LongInt; Source: PTexture);
procedure DrawFromRect(X, Y: LongInt; r: PSDL_Rect; SourceTexture: PTexture; DestSurface: PSDL_Surface);
@@ -326,7 +327,6 @@
_b:= (r^.y + r^.h) / SourceTexture^.h;
glBindTexture(GL_TEXTURE_2D, SourceTexture^.id);
-glEnable(GL_TEXTURE_2D);
glBegin(GL_QUADS);
@@ -348,7 +348,6 @@
procedure DrawTexture(X, Y: LongInt; Texture: PTexture);
begin
glBindTexture(GL_TEXTURE_2D, Texture^.id);
-glEnable(GL_TEXTURE_2D);
glBegin(GL_QUADS);
@@ -367,6 +366,37 @@
glEnd()
end;
+procedure DrawRotated(Sprite: TSprite; X, Y: LongInt; Angle: real);
+var hw, hh: LongInt;
+begin
+glPushMatrix;
+glTranslatef(X, Y, 0);
+glRotatef(Angle, 0, 0, 1);
+
+hw:= SpritesData[Sprite].Width;
+hh:= SpritesData[Sprite].Height;
+
+glBindTexture(GL_TEXTURE_2D, SpritesData[Sprite].Texture^.id);
+
+glBegin(GL_QUADS);
+
+glTexCoord2f(0, 0);
+glVertex2i(-hw, -hh);
+
+glTexCoord2f(1, 0);
+glVertex2i(hw, -hh);
+
+glTexCoord2f(1, 1);
+glVertex2i(hw, hh);
+
+glTexCoord2f(0, 1);
+glVertex2i(-hw, hh);
+
+glEnd();
+
+glPopMatrix
+end;
+
procedure DrawSpriteFromRect(Sprite: TSprite; r: TSDL_Rect; X, Y, Height, Position: LongInt; Surface: PSDL_Surface);
begin
r.y:= r.y + Height * Position;
@@ -452,7 +482,6 @@
end;
glBindTexture(GL_TEXTURE_2D, HHTexture^.id);
-glEnable(GL_TEXTURE_2D);
glBegin(GL_QUADS);
@@ -565,12 +594,14 @@
SDL_FreeSurface(texsurf)
end;
glClear(GL_COLOR_BUFFER_BIT);
+glEnable(GL_TEXTURE_2D);
r.x:= 0;
r.w:= ProgrTex^.w;
r.h:= ProgrTex^.w;
r.y:= (Step mod (ProgrTex^.h div ProgrTex^.w)) * ProgrTex^.w;
DrawFromRect((cScreenWidth - ProgrTex^.w) div 2,
(cScreenHeight - ProgrTex^.w) div 2, @r, ProgrTex, SDLPrimSurface);
+glDisable(GL_TEXTURE_2D);
SDL_GL_SwapBuffers();
inc(Step);
end;
--- a/hedgewars/uWorld.pas Mon Jan 28 17:51:18 2008 +0000
+++ b/hedgewars/uWorld.pas Mon Jan 28 18:22:35 2008 +0000
@@ -173,6 +173,7 @@
// Sky
glClear(GL_COLOR_BUFFER_BIT);
glEnable(GL_BLEND);
+glEnable(GL_TEXTURE_2D);
if not isPaused then MoveCamera;
@@ -371,6 +372,7 @@
end
end;
+glDisable(GL_TEXTURE_2D);
glDisable(GL_BLEND)
end;
Binary file share/hedgewars/Data/Graphics/Grenade.png has changed