--- a/hedgewars/uAtlas.pas Tue Jul 10 11:09:38 2012 +0200
+++ b/hedgewars/uAtlas.pas Tue Jul 10 16:38:50 2012 +0200
@@ -128,18 +128,8 @@
procedure writefunc(png: png_structp; buffer: png_bytep; size: QWord); cdecl;
-var
- p: Pbyte;
- i: Integer;
begin
- //TStream(png_get_io_ptr(png)).Write(buffer^, size);
BlockWrite(DumpFile, buffer^, size);
-{ p:= PByte(buffer^);
- for i:=0 to pred(size) do
- begin
- Write(DumpFile, p^);
- inc(p);
- end;}
end;
function IntToStrPad(i: Integer): string;
@@ -397,9 +387,6 @@
begin
sz:= surf^.w * surf^.h;
p:= surf^.pixels;
- //randr:=Random;
- //randg:=Random;
- //randb:=1 - min(randr, randg);
randh:=Random;
HSVToRGB(randh, 1.0, 1.0, randr, randg, randb);
for i:=0 to pred(sz) do
@@ -422,6 +409,50 @@
end;
end;
+procedure DebugChecker(surf: PSDL_Surface);
+var
+ sz: Integer;
+ p, q: PByte;
+ randr, randg, randb: Single;
+ randrb, randgb, randbb: Byte;
+ randh: Single;
+ x, y: Integer;
+begin
+ sz:= surf^.w * surf^.h;
+ p:= surf^.pixels;
+ randh:=Random;
+ HSVToRGB(randh, 1.0, 1.0, randr, randg, randb);
+ randrb:= Trunc(255*randr);
+ randgb:= Trunc(255*randg);
+ randbb:= Trunc(255*randb);
+
+ p:= surf^.pixels;
+ for y:=0 to Pred(surf^.h) do
+ begin
+ q:= p;
+ for x:=0 to Pred(surf^.w) do
+ begin
+ if ((x xor y) and 1) = 1 then
+ begin
+ q[0]:= randrb;
+ q[1]:= randgb;
+ q[2]:= randbb;
+ q[3]:= 255;
+ end else
+ begin
+ q[0]:= 0;
+ q[1]:= 0;
+ q[2]:= 0;
+ q[3]:= 255;
+ end;
+ inc(q, 4);
+ end;
+ inc(p, surf^.pitch);
+ end;
+
+end;
+
+
procedure Upload(var info: AtlasInfo; sprite: Rectangle; surf: PSDL_Surface);
var
sp: PTexture;
@@ -442,6 +473,7 @@
//if GrayScale then
// Surface2GrayScale(surf);
//DebugColorize(surf);
+ DebugChecker(surf);
glBindTexture(GL_TEXTURE_2D, info.TextureInfo.id);
if (sp^.isRotated) then
--- a/hedgewars/uRender.pas Tue Jul 10 11:09:38 2012 +0200
+++ b/hedgewars/uRender.pas Tue Jul 10 16:38:50 2012 +0200
@@ -122,14 +122,14 @@
procedure DrawSpriteFromRect(Sprite: TSprite; r: TSDL_Rect; X, Y, Height, Position: LongInt);
begin
-r.y:= r.y + Height * Position;
-r.h:= Height;
-DrawTextureFromRect(X, Y, @r, SpritesData[Sprite].Texture)
+ r.y:= r.y + Height * Position;
+ r.h:= Height;
+ DrawTextureFromRect(X, Y, @r, SpritesData[Sprite].Texture)
end;
procedure DrawTextureFromRect(X, Y: LongInt; r: PSDL_Rect; SourceTexture: PTexture);
begin
-DrawTextureFromRect(X, Y, r^.w, r^.h, r, SourceTexture)
+ DrawTextureFromRect(X, Y, r^.w, r^.h, r, SourceTexture)
end;
procedure DrawTextureFromRect(X, Y, W, H: LongInt; r: PSDL_Rect; SourceTexture: PTexture);
@@ -174,7 +174,7 @@
SetVertexPointer(@VertexBuffer[0]);
//SetTexCoordPointer(@TextureBuffer[0]);
SetTexCoordPointer(@SourceTexture^.tb[0]);
- glDrawArrays(GL_TRIANGLE_FAN, 0, Length(VertexBuffer));
+ //glDrawArrays(GL_TRIANGLE_FAN, 0, Length(VertexBuffer));
end;
procedure DrawTexture(X, Y: LongInt; Texture: PTexture); inline;
@@ -184,17 +184,18 @@
procedure DrawTexture(X, Y: LongInt; Texture: PTexture; Scale: GLfloat);
begin
-SetOffset(X, Y);
-ResetRotation;
-SetScale(Scale);
-UpdateModelview;
+ SetOffset(X, Y);
+ ResetRotation;
+ SetScale(Scale);
+ UpdateModelview;
-glBindTexture(GL_TEXTURE_2D, Texture^.atlas^.id);
+ glBindTexture(GL_TEXTURE_2D, Texture^.atlas^.id);
+ SetVertexPointer(@Texture^.vb);
+ SetTexCoordPointer(@Texture^.tb);
+ //glDrawArrays(GL_TRIANGLE_FAN, 0, Length(Texture^.vb));
+ glBindTexture(GL_TEXTURE_2D, 0); // DEBUG
-SetVertexPointer(@Texture^.vb);
-SetTexCoordPointer(@Texture^.tb);
-glDrawArrays(GL_TRIANGLE_FAN, 0, Length(Texture^.vb));
-ResetModelview;
+ ResetModelview;
end;
procedure DrawTextureF(Texture: PTexture; Scale: GLfloat; X, Y, Frame, Dir, w, h: LongInt);
@@ -218,53 +219,57 @@
if Texture = nil then
exit;
-// do not draw anything outside the visible screen space (first check fixes some sprite drawing, e.g. hedgehogs)
-if (abs(X) > W) and ((abs(X + dir * OffsetX) - W / 2) * cScaleFactor > cScreenWidth) then
- exit;
-if (abs(Y) > H) and ((abs(Y + OffsetY - (0.5 * cScreenHeight)) - W / 2) * cScaleFactor > cScreenHeight) then
- exit;
+ // do not draw anything outside the visible screen space (first check fixes some sprite drawing, e.g. hedgehogs)
+ if (abs(X) > W) and ((abs(X + dir * OffsetX) - W / 2) * cScaleFactor > cScreenWidth) then
+ exit;
+ if (abs(Y) > H) and ((abs(Y + OffsetY - (0.5 * cScreenHeight)) - W / 2) * cScaleFactor > cScreenHeight) then
+ exit;
+
-SetOffset(X, Y);
-if Dir = 0 then Dir:= 1;
+ SetOffset(X, Y);
+ if Dir = 0 then
+ Dir:= 1;
-SetRotation(Angle, Dir);
-AddOffset(Dir*OffsetX, OffsetY);
-AddScale(Scale);
-UpdateModelview;
+ SetRotation(Angle, Dir);
+ AddOffset(Dir*OffsetX, OffsetY);
+ AddScale(Scale);
+ UpdateModelview;
// Any reason for this call? And why only in t direction, not s?
//glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
-hw:= w div (2 div Dir);
+ hw:= w div (2 div Dir);
-r.y:=0;
-r.x:=0;
-r.w:=w;
-r.h:=h;
-ComputeTexcoords(Texture, @r, @TextureBuffer);
+ r.y:=0;
+ r.x:=0;
+ r.w:=w;
+ r.h:=h;
+ ComputeTexcoords(Texture, @r, @TextureBuffer);
-glBindTexture(GL_TEXTURE_2D, Texture^.atlas^.id);
+ glBindTexture(GL_TEXTURE_2D, Texture^.atlas^.id);
-_l:= -hw + Texture^.cropInfo.l;
-_t:= w/-2 + Texture^.cropInfo.t;
-_r:= hw - Texture^.cropInfo.l - Texture^.cropInfo.r;
-_b:= w/2 - Texture^.cropInfo.t - Texture^.cropInfo.b;
+ _l:= -hw + Texture^.cropInfo.l;
+ _t:= w/-2 + Texture^.cropInfo.t;
+ _r:= hw - Texture^.cropInfo.l - Texture^.cropInfo.r;
+ _b:= w/2 - Texture^.cropInfo.t - Texture^.cropInfo.b;
-VertexBuffer[0].X:= _l;
-VertexBuffer[0].Y:= _t;
-VertexBuffer[1].X:= _r;
-VertexBuffer[1].Y:= _t;
-VertexBuffer[2].X:= _r;
-VertexBuffer[2].Y:= _b;
-VertexBuffer[3].X:= _l;
-VertexBuffer[3].Y:= _b;
+ VertexBuffer[0].X:= _l;
+ VertexBuffer[0].Y:= _t;
+ VertexBuffer[1].X:= _r;
+ VertexBuffer[1].Y:= _t;
+ VertexBuffer[2].X:= _r;
+ VertexBuffer[2].Y:= _b;
+ VertexBuffer[3].X:= _l;
+ VertexBuffer[3].Y:= _b;
-SetVertexPointer(@VertexBuffer[0]);
-//SetTexCoordPointer(@TextureBuffer[0]);
-SetTexCoordPointer(@Texture^.tb[0]);
-glDrawArrays(GL_TRIANGLE_FAN, 0, Length(VertexBuffer));
+ //SetVertexPointer(@VertexBuffer[0]);
+ //SetTexCoordPointer(@TextureBuffer[0]);
-ResetModelview;
+ SetVertexPointer(@Texture^.vb[0]);
+ SetTexCoordPointer(@Texture^.tb[0]);
+ //glDrawArrays(GL_TRIANGLE_FAN, 0, Length(VertexBuffer));
+
+ ResetModelview;
end;
procedure DrawSpriteRotated(Sprite: TSprite; X, Y, Dir: LongInt; Angle: real);
@@ -275,22 +280,6 @@
X, Y, Dir, Angle)
end;
-procedure DrawSpriteRotatedF(Sprite: TSprite; X, Y, Frame, Dir: LongInt; Angle: real);
-begin
-SetOffset(X, Y);
-if Dir < 0 then
- SetRotation(Angle, -1.0)
-else
- SetRotation(Angle, 1.0);
-if Dir < 0 then
- AddScale(-1.0, 1.0);
-UpdateModelview;
-
-DrawSprite(Sprite, -SpritesData[Sprite].Width div 2, -SpritesData[Sprite].Height div 2, Frame);
-
-ResetModelview;
-end;
-
procedure DrawTextureRotated(Texture: PTexture; hw, hh, X, Y, Dir: LongInt; Angle: real);
var VertexBuffer: array [0..3] of TVertex2f;
_l, _r, _t, _b: GLfloat;
@@ -330,14 +319,15 @@
SetVertexPointer(@VertexBuffer[0]);
SetTexCoordPointer(@Texture^.tb);
-glDrawArrays(GL_TRIANGLE_FAN, 0, Length(VertexBuffer));
+//glDrawArrays(GL_TRIANGLE_FAN, 0, Length(VertexBuffer));
ResetModelview;
end;
-procedure DrawSprite(Sprite: TSprite; X, Y, Frame: LongInt);
-var
- r: TSDL_Rect;
+
+
+procedure DrawSpriteRotatedF(Sprite: TSprite; X, Y, Frame, Dir: LongInt; Angle: real);
+var
tex: PTexture;
begin
if SpritesData[Sprite].imageHeight = 0 then
@@ -354,11 +344,31 @@
if (tex = nil) or (tex^.w = 0) or (tex^.h = 0) then
exit;
- r.x:= 0;
- r.w:= SpritesData[Sprite].Width;
- r.y:= 0;
- r.h:= SpritesData[Sprite].Height;
- DrawTextureFromRect(X, Y, @r, tex)
+ SetOffset(X, Y);
+
+ if Dir < 0 then
+ begin
+ SetRotation(Angle, -1.0);
+ AddScale(-1.0, 1.0);
+ end
+ else
+ SetRotation(Angle, 1.0);
+
+ UpdateModelview;
+
+ glBindTexture(GL_TEXTURE_2D, tex^.atlas^.id);
+ SetVertexPointer(@tex^.vb);
+ SetTexCoordPointer(@tex^.tb);
+ glDrawArrays(GL_TRIANGLE_FAN, 0, Length(tex^.vb));
+ glBindTexture(GL_TEXTURE_2D, 0); // DEBUG
+
+ ResetModelview;
+end;
+
+
+procedure DrawSprite(Sprite: TSprite; X, Y, Frame: LongInt);
+begin
+ DrawSpriteRotatedF(Sprite, X, Y, Frame, 1, 0.0);
end;
procedure DrawSpriteClipped(Sprite: TSprite; X, Y, TopY, RightX, BottomY, LeftX: LongInt);
@@ -413,7 +423,7 @@
VertexBuffer[1].Y:= Y1;
SetVertexPointer(@VertexBuffer[0]);
- glDrawArrays(GL_LINES, 0, Length(VertexBuffer));
+ //glDrawArrays(GL_LINES, 0, Length(VertexBuffer));
Tint($FF, $FF, $FF, $FF);
ResetModelview;
@@ -449,7 +459,7 @@
VertexBuffer[3].Y:= r.y + r.h;
SetVertexPointer(@VertexBuffer[0]);
-glDrawArrays(GL_TRIANGLE_FAN, 0, Length(VertexBuffer));
+//glDrawArrays(GL_TRIANGLE_FAN, 0, Length(VertexBuffer));
Tint($FF, $FF, $FF, $FF);
glEnable(GL_TEXTURE_2D);
@@ -480,7 +490,7 @@
UpdateModelview;
glLineWidth(Width);
SetVertexPointer(@CircleVertex[0]);
- glDrawArrays(GL_LINE_LOOP, 0, 60);
+ //glDrawArrays(GL_LINE_LOOP, 0, 60);
glEnable(GL_TEXTURE_2D);
glDisable(GL_LINE_SMOOTH);
ResetModelview;
@@ -522,7 +532,7 @@
else
SetVertexPointer(@VertexBuffers[0][0]);
SetTexCoordPointer(@TextureBuffer[0]);
- glDrawArrays(GL_TRIANGLE_FAN, 0, 4);
+ //glDrawArrays(GL_TRIANGLE_FAN, 0, 4);
ResetModelview;
end;