-
Notifications
You must be signed in to change notification settings - Fork 0
/
gla_texture.inc
58 lines (57 loc) · 1.66 KB
/
gla_texture.inc
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
{
GLA中的纹理操作单元
}
{$IFDEF GLA_INTERFACE}
{$IFDEF GLA_DEBUG}
{$INFO Compiling gla_texture::interface}
{$ENDIF}
function glaLoadTexture(fnm:string):GLUint;
{$ENDIF}
{$IFDEF GLA_IMPLEMENTATION}
{$IFDEF GLA_DEBUG}
{$INFO Compiling gla_texture::implementation}
{$ENDIF}
function glaLoadTexture(fnm:string):GLUInt;
var
Reader:TFPCustomImageReader;
img:TFPMemoryImage;
s:string;
t,i,j,p:longint;
texture:GLUInt;
PTexture:^Byte;
begin
s:=fnm;
p:=pos('.',fnm);
while p<>0 do begin
delete(fnm,1,p);
p:=pos('.',fnm);
end;
fnm:=LowerCase(fnm);
if fnm='bmp' then Reader:=TFPReaderBMP.Create
else if fnm='png' then Reader:=TFPReaderPNG.Create
else if (fnm='jpg')or(fnm='jpeg') then Reader:=TFPReaderJPEG.Create
else if fnm='gif' then Reader:=TFPReaderGIF.Create;
img:=TFPMemoryImage.Create(0,0);
img.LoadFromFile(s,Reader);
PTexture:=GetMem(img.Height*img.Width*4);
t:=-1;
for i:=img.height-1 downto 0 do
for j:=0 to img.Width-1 do begin
t:=t+1; PTexture[t]:=img.Colors[j,i].red;
t:=t+1; PTexture[t]:=img.Colors[j,i].green;
t:=t+1; PTexture[t]:=img.Colors[j,i].blue;
t:=t+1; PTexture[t]:=img.Colors[j,i].alpha;
end;
img.Free; Reader.Free;
glGenTextures(1,@texture);
glBindTexture(GL_TEXTURE_2D,texture);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_WRAP_S,GL_REPEAT);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_WRAP_T,GL_REPEAT);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_NEAREST);
glTexEnvf(GL_TEXTURE_ENV,GL_TEXTURE_ENV_MODE,GL_REPLACE);
glTexImage2d(GL_TEXTURE_2D,0,GL_RGBA,img.Height,img.Width,0,GL_RGBA,
GL_UNSIGNED_BYTE,PTexture);
exit(texture);
end;
{$ENDIF}