-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathuPngCopy.pas
108 lines (91 loc) · 2.56 KB
/
uPngCopy.pas
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
unit uPngCopy;
interface
Uses
PngImage, GLGraphics, glMaterial, glColor, glTexture,
VectorGeometry, SysUtils, uUtils;
procedure SetPngTexture(A: TPngObject; destBmp32: TGLBitmap32); overload;
procedure SetPngTexture(fName: String; destBmp32: TGLBitmap32); overload;
procedure SetMaterialPngTexture (fName:String; mat : TGlMaterial);
implementation
procedure SetPngTexture(A: TPngObject; destBmp32: TGLBitmap32);
var
tmp: TGLBitmap32;
i,j:Integer;
cl: TVector;
begin
try
tmp:= TGLBitmap32.Create;
tmp.Width:= A.Width;
tmp.Height:= A.Height;
for i:= 0 to A.Width - 1 do
for j:= 0 to A.Height - 1 do
begin
cl:= ConvertWinColor(A.Pixels[i,j]);
tmp.data[i + (A.Height-1-j) * A.Width]:= RGB2Pixel32(Round(cl[0]*255), Round(cl[1]*255), Round(cl[2]*255), A.AlphaScanline[j]^[i]);
end;
destBmp32.Assign(tmp);
finally
FreeAndNil(A);
FreeAndNil(tmp);
end;
end;
procedure SetPngTexture(fName: String; destBmp32: TGLBitmap32);
var
A: TPngObject;
tmp: TGLBitmap32;
i,j:Integer;
cl: TVector;
begin
try
A:= TPngObject.Create;
A.LoadFromFile(fName);
A.CreateAlpha;
tmp:= TGLBitmap32.Create;
tmp.Width:= A.Width;
tmp.Height:= A.Height;
for i:= 0 to A.Width - 1 do
for j:= 0 to A.Height - 1 do
begin
cl:= ConvertWinColor(A.Pixels[i,j]);
tmp.data[i + (A.Height-1-j) * A.Width]:= RGB2Pixel32(Round(cl[0]*255), Round(cl[1]*255), Round(cl[2]*255), A.AlphaScanline[j]^[i]);
end;
destBmp32.Assign(tmp);
finally
FreeAndNil(A);
FreeAndNil(tmp);
end;
end;
procedure SetMaterialPngTexture (fName:String; mat : TGlMaterial);
var
A: TPngObject;
i,j:Integer;
cl: TVector;
tmp: TglBitMap32;
begin
try
mat.Texture.Disabled:= false;
mat.BlendingMode:= bmTransparency;
mat.Texture.TextureMode:= tmModulate;
mat.FrontProperties.Ambient.SetColor(1,1,1, 1);
mat.FrontProperties.Diffuse.SetColor(1,1,1, 1);
mat.FrontProperties.Emission.SetColor(1,1,1, 1);
mat.FrontProperties.Specular.SetColor(1,1,1, 1);
A:= TPngObject.Create;
A.LoadFromFile(fName);
A.CreateAlpha;
tmp:= TglBitMap32.Create;
tmp.Width:= A.Width;
tmp.Height:= A.Height;
for i:= 0 to A.Width - 1 do
for j:= 0 to A.Height - 1 do
begin
cl:= ConvertWinColor(A.Pixels[i,j]);
tmp.data[i + (A.Height-1-j) * A.Width]:= RGB2Pixel32(Round(cl[0]*255), Round(cl[1]*255), Round(cl[2]*255), A.AlphaScanline[j]^[i]);
end;
Mat.Texture.Image.Assign(tmp);
finally
FreeAndNil(A);
FreeAndNil(tmp);
end;
end;
end.