aboutsummaryrefslogtreecommitdiffstats
path: root/Game/Code
diff options
context:
space:
mode:
authorb1indy <b1indy@b956fd51-792f-4845-bead-9b4dfca2ff2c>2007-07-22 18:30:33 +0000
committerb1indy <b1indy@b956fd51-792f-4845-bead-9b4dfca2ff2c>2007-07-22 18:30:33 +0000
commita5955bf26ecfe0ec20c70aff6522d1f8bd2e677d (patch)
tree92a97f224c3621f93cadc7eecbd7b4e4c60d1c3f /Game/Code
parent9395740413850d6d852666f7223aa95ac1c1412e (diff)
downloadusdx-a5955bf26ecfe0ec20c70aff6522d1f8bd2e677d.tar.gz
usdx-a5955bf26ecfe0ec20c70aff6522d1f8bd2e677d.tar.xz
usdx-a5955bf26ecfe0ec20c70aff6522d1f8bd2e677d.zip
changed loading of transparent PNGs, should be slower now, might break with some PNG types but gives nice correct transparency for 24bit transparent PNGs
git-svn-id: svn://svn.code.sf.net/p/ultrastardx/svn/trunk@320 b956fd51-792f-4845-bead-9b4dfca2ff2c
Diffstat (limited to 'Game/Code')
-rw-r--r--Game/Code/Classes/UTexture.pas42
1 files changed, 24 insertions, 18 deletions
diff --git a/Game/Code/Classes/UTexture.pas b/Game/Code/Classes/UTexture.pas
index 43a8737e..84604367 100644
--- a/Game/Code/Classes/UTexture.pas
+++ b/Game/Code/Classes/UTexture.pas
@@ -184,6 +184,8 @@ var
Error: integer;
SkipX: integer;
myAlpha: Real;
+ myRGBABitmap: array of byte;
+ RGBPtr: PByte;
begin
Log.BenchmarkStart(4);
Mipmapping := true;
@@ -240,6 +242,7 @@ begin
if (Typ = 'Transparent') and (TexturePNG.TransparencyMode = ptmPartial) then
begin
setlength(TextureAlpha, TextureB.Width*TextureB.Height);
+ setlength(MyRGBABitmap,TextureB.Width*TextureB.Height*4);
if (TexturePNG.Header.ColorType = COLOR_GRAYSCALEALPHA) or
(TexturePNG.Header.ColorType = COLOR_RGBALPHA) then
begin
@@ -247,9 +250,18 @@ begin
for Position := 0 to TextureB.Height - 1 do
begin
AlphaPtr := PByte(TexturePNG.AlphaScanline[Position]);
+ RGBPtr:=PByte(TexturePNG.Scanline[Position]);
for Position2 := 0 to TextureB.Width - 1 do
begin
TextureAlpha[Position*TextureB.Width+Position2]:= AlphaPtr^;
+ MyRGBABitmap[(Position*TextureB.Width+Position2)*4]:= RGBPtr^;
+ Inc(RGBPtr);
+ MyRGBABitmap[(Position*TextureB.Width+Position2)*4+1]:= RGBPtr^;
+ Inc(RGBPtr);
+ MyRGBABitmap[(Position*TextureB.Width+Position2)*4+2]:= RGBPtr^;
+ Inc(RGBPtr);
+ MyRGBABitmap[(Position*TextureB.Width+Position2)*4+3]:= AlphaPtr^;
+// Inc(RGBPtr);
Inc(AlphaPtr);
end;
end;
@@ -379,28 +391,22 @@ begin
TextureD32[Position*TexNewW + Position2 + 1, 2] := 0;
TextureD32[Position*TexNewW + Position2 + 1, 3] := 0;
TextureD32[Position*TexNewW + Position2 + 1, 4] := 0;
+ end else if (Format = 'PNG') and (length(TextureAlpha) <> 0) then begin
+ myAlpha:=TextureAlpha[Position*TexOrigW+Position2];
+ TextureD32[Position*TexNewW + Position2+1, 1] := MyRGBABitmap[(Position*TexOrigW+Position2)*4+2];
+ TextureD32[Position*TexNewW + Position2+1, 2] := MyRGBABitmap[(Position*TexOrigW+Position2)*4+1];
+ TextureD32[Position*TexNewW + Position2+1, 3] := MyRGBABitmap[(Position*TexOrigW+Position2)*4];
+ TextureD32[Position*TexNewW+Position2+1,4]:=MyRGBABitmap[(Position*TexOrigW+Position2)*4+3];
end else begin
- TextureD32[Position*TexNewW + Position2+1, 1] := Pix;
- TextureD32[Position*TexNewW + Position2+1, 2] := Pix div 256;
- TextureD32[Position*TexNewW + Position2+1, 3] := Pix div (256*256);
- // transparent png hack start (part 2 of 2)
- if (Format = 'PNG') and (length(TextureAlpha) <> 0) then begin
- myAlpha:=TextureAlpha[Position*TexOrigW+Position2];
-
- // the following calculations tweak transparency so that it really looks transparent
- myAlpha:=myAlpha-75;
- if myAlpha < 0 then myAlpha:=0;
- myAlpha:=myAlpha/180;
- myAlpha:=myAlpha*myAlpha*myAlpha;
- myAlpha:=myAlpha*255;
-
- TextureD32[Position*TexNewW+Position2+1,4]:=floor(myAlpha);
- end else
- // transparent png hack end
- TextureD32[Position*TexNewW + Position2+1, 4] := 255;
+ TextureD32[Position*TexNewW + Position2+1, 1] := (Pix and $ff);
+ TextureD32[Position*TexNewW + Position2+1, 2] := ((Pix shr 8) and $ff);
+ TextureD32[Position*TexNewW + Position2+1, 3] := ((Pix shr 16) and $ff);
+ TextureD32[Position*TexNewW + Position2+1, 4] := 255;
end;
end;
end;
+ setlength(TextureAlpha,0);
+ setlength(MyRGBABitmap,0);
glTexImage2D(GL_TEXTURE_2D, 0, 4, TexNewW, TexNewH, 0, GL_RGBA, GL_UNSIGNED_BYTE, @TextureD32);
{ if Mipmapping then begin
Error := gluBuild2DMipmaps(GL_TEXTURE_2D, 4, TextureB.Width, TextureB.Height, GL_RGBA, GL_UNSIGNED_BYTE, @TextureD32);