--- a/hedgewars/uConsts.pas Sun Mar 15 17:47:06 2009 +0000
+++ b/hedgewars/uConsts.pas Mon Mar 16 14:43:15 2009 +0000
@@ -114,6 +114,7 @@
TTexture = record
id: GLuint;
w, h: LongInt;
+ rx, ry: GLfloat;
end;
PTexture = ^TTexture;
--- a/hedgewars/uMisc.pas Sun Mar 15 17:47:06 2009 +0000
+++ b/hedgewars/uMisc.pas Mon Mar 16 14:43:15 2009 +0000
@@ -141,7 +141,7 @@
TargetPoint: TPoint = (X: NoPointX; Y: 0);
implementation
-uses uConsole, uStore, uIO, Math, uRandom, GLU;
+uses uConsole, uStore, uIO, Math, uRandom;
var KBnum: Longword = 0;
{$IFDEF DEBUGFILE}
var f: textfile;
@@ -283,6 +283,8 @@
new(NewTexture);
NewTexture^.w:= width;
NewTexture^.h:= height;
+NewTexture^.rx:= 1.0;
+NewTexture^.ry:= 1.0;
glGenTextures(1, @NewTexture^.id);
@@ -296,8 +298,10 @@
function Surface2Tex(surf: PSDL_Surface): PTexture;
var mode: LongInt;
- tw, th: Longword;
- tmpp: pointer;
+ tw, th, x, y: Longword;
+ tmpp: pointer;
+ fromP4, toP4: PLongWordArray;
+ fromP1, toP1: PByteArray;
begin
new(Surface2Tex);
Surface2Tex^.w:= surf^.w;
@@ -319,21 +323,85 @@
SDLTry(SDL_LockSurface(surf) >= 0, true);
if not (isPowerOf2(Surf^.w) and isPowerOf2(Surf^.h)) then
- begin
- tw:= toPowerOf2(Surf^.w);
- th:= toPowerOf2(Surf^.h);
+ begin
+ tw:= toPowerOf2(Surf^.w);
+ th:= toPowerOf2(Surf^.h);
+
+ Surface2Tex^.rx:= Surf^.w / tw;
+ Surface2Tex^.ry:= Surf^.h / th;
+
+ GetMem(tmpp, tw * th * surf^.format^.BytesPerPixel);
+
+ if surf^.format^.BytesPerPixel = 4 then
+ begin
+ fromP4:= Surf^.pixels;
+ toP4:= tmpp;
- GetMem(tmpp, tw * th * surf^.format^.BytesPerPixel);
+ for y:= 0 to Pred(Surf^.h) do
+ begin
+ for x:= 0 to Pred(Surf^.w) do
+ toP4^[x]:= fromP4^[x];
+ for x:= Surf^.w to Pred(tw) do
+ toP4^[x]:= 0;
+ toP4:= @(toP4^[tw]);
+ fromP4:= @(fromP4^[Surf^.w]);
+ end;
+
+ for y:= Surf^.h to Pred(th) do
+ begin
+ for x:= 0 to Pred(tw) do
+ toP4^[x]:= 0;
+ toP4:= @(toP4^[tw]);
+ end;
+ end
+ else
+ begin
+ fromP1:= Surf^.pixels;
+ toP1:= tmpp;
- gluScaleImage(mode, Surf^.w, Surf^.h, GL_UNSIGNED_BYTE,
- Surf^.pixels, tw, th, GL_UNSIGNED_BYTE,
- tmpp);
+ for y:= 0 to Pred(Surf^.h) do
+ begin
+ for x:= 0 to Pred(Surf^.w) do
+ begin
+ toP1^[x * 3]:= fromP1^[x * 3];
+ toP1^[x * 3 + 1]:= fromP1^[x * 3 + 1];
+ toP1^[x * 3 + 2]:= fromP1^[x * 3 + 2];
+ end;
+ for x:= Surf^.w to Pred(tw) do
+ begin
+ toP1^[x * 3]:= 0;
+ toP1^[x * 3 + 1]:= 0;
+ toP1^[x * 3 + 2]:= 0;
+ end;
+ toP1:= @(toP1^[tw * 3]);
+ fromP1:= @(fromP1^[Surf^.pitch]);
+ end;
- glTexImage2D(GL_TEXTURE_2D, 0, mode, tw, th, 0, mode, GL_UNSIGNED_BYTE, tmpp);
+ for y:= Surf^.h to Pred(th) do
+ begin
+ for x:= 0 to Pred(tw) do
+ begin
+ toP1^[x * 3]:= 0;
+ toP1^[x * 3 + 1]:= 0;
+ toP1^[x * 3 + 2]:= 0;
+ end;
+ toP1:= @(toP1^[tw * 3]);
+ end;
+ end;
- FreeMem(tmpp, tw * th * surf^.format^.BytesPerPixel)
- end else
- glTexImage2D(GL_TEXTURE_2D, 0, mode, surf^.w, surf^.h, 0, mode, GL_UNSIGNED_BYTE, surf^.pixels);
+// gluScaleImage(mode, Surf^.w, Surf^.h, GL_UNSIGNED_BYTE,
+// Surf^.pixels, tw, th, GL_UNSIGNED_BYTE,
+// tmpp);
+
+ glTexImage2D(GL_TEXTURE_2D, 0, mode, tw, th, 0, mode, GL_UNSIGNED_BYTE, tmpp);
+
+ FreeMem(tmpp, tw * th * surf^.format^.BytesPerPixel)
+ end else
+ begin
+ Surface2Tex^.rx:= 1.0;
+ Surface2Tex^.ry:= 1.0;
+ glTexImage2D(GL_TEXTURE_2D, 0, mode, surf^.w, surf^.h, 0, mode, GL_UNSIGNED_BYTE, surf^.pixels);
+ end;
if SDL_MustLock(surf) then
SDL_UnlockSurface(surf);
--- a/hedgewars/uStore.pas Sun Mar 15 17:47:06 2009 +0000
+++ b/hedgewars/uStore.pas Mon Mar 16 14:43:15 2009 +0000
@@ -317,10 +317,10 @@
rr.w:= r^.w;
rr.h:= r^.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;
+_l:= r^.x / SourceTexture^.w * SourceTexture^.rx;
+_r:= (r^.x + r^.w) / SourceTexture^.w * SourceTexture^.rx;
+_t:= r^.y / SourceTexture^.h * SourceTexture^.ry;
+_b:= (r^.y + r^.h) / SourceTexture^.h * SourceTexture^.ry;
glBindTexture(GL_TEXTURE_2D, SourceTexture^.id);
@@ -350,13 +350,13 @@
glTexCoord2f(0, 0);
glVertex2i(X, Y);
-glTexCoord2f(1, 0);
+glTexCoord2f(Texture^.rx, 0);
glVertex2i(Texture^.w + X, Y);
-glTexCoord2f(1, 1);
+glTexCoord2f(Texture^.rx, Texture^.ry);
glVertex2i(Texture^.w + X, Texture^.h + Y);
-glTexCoord2f(0, 1);
+glTexCoord2f(0, Texture^.ry);
glVertex2i(X, Texture^.h + Y);
glEnd()
@@ -375,8 +375,8 @@
else
hw:= 16;
-ft:= Frame / Frames;
-fb:= (Frame + 1) / Frames;
+ft:= Frame / Frames * Texture^.ry;
+fb:= (Frame + 1) / Frames * Texture^.ry;
glBindTexture(GL_TEXTURE_2D, Texture^.id);
@@ -385,10 +385,10 @@
glTexCoord2f(0, ft);
glVertex2i(-hw, -16);
-glTexCoord2f(1, ft);
+glTexCoord2f(Texture^.rx, ft);
glVertex2i(hw, -16);
-glTexCoord2f(1, fb);
+glTexCoord2f(Texture^.rx, fb);
glVertex2i(hw, 16);
glTexCoord2f(0, fb);
@@ -440,13 +440,13 @@
glTexCoord2f(0, 0);
glVertex2i(-hw, -hh);
-glTexCoord2f(1, 0);
+glTexCoord2f(Tex^.rx, 0);
glVertex2i(hw, -hh);
-glTexCoord2f(1, 1);
+glTexCoord2f(Tex^.rx, Tex^.ry);
glVertex2i(hw, hh);
-glTexCoord2f(0, 1);
+glTexCoord2f(0, Tex^.ry);
glVertex2i(-hw, hh);
glEnd();