Hello, I trying to load a PNG file, as make the example, that come with Lazarus, OpenGlControlDemo.
So I copy the function LoadflTextImage2DfromPNG, and for Test I wrote this small program.
program project1;
{$mode objfpc}{$H+}
uses
{$IFDEF UNIX}{$IFDEF UseCThreads}
cthreads,
{$ENDIF}{$ENDIF}
Classes
{ you can add units after this },
Graphics, IntfGraphics,Gl,Fpimage;
TYpe
{ TglTexture }
TglTexture= class
public
width ,Height : Longint;
Data : Pointer;
destructor Destroy;Override;
end;
var
P: TPortableNetworkGraphic;
InfImage: TLazIntfImage;
Textura : TglTexture;
Pb: PByte;
X,Y: Integer;
c : TFpColor;
{ TglTexture }
destructor TglTexture.Destroy;
begin
Data := Nil;
//Data.Free;
inherited Destroy;
end;
begin
Textura := TglTexture.Create;
InfImage := nil;
P := TPortableNetworkGraphic.Create;
P.LoadFromFile('Texture1.png');
InfImage := P.CreateIntfImage;
Textura.width:= P.Width;
Textura.Height:=P.Height;
Getmem(Textura.Data,Textura.width * Textura.Height * 3);
Pb := PByte (Textura.Data);
For Y := 0 To P.Height-1 do
Begin
For X := 0 To P.Width do
Begin
c:=InfImage.Colors[x,y];
Pb^:= c.red shr 8;
inc(pb);
Pb^:=c.Green shr 8;
inc(pb);
Pb^:=c.blue shr 8;
inc(pb);
end;
end;
ReadLn;
P.Free;
InfImage.Free;
Textura.Free;
end.
But in the line
InfImage := P.CreateIntfImage;
I got a exception of the debugger: Extenal SigSev.
But If I run the example that come with Lazarus, every thing goes ok.
I don't know what I doing wrong.
Any idea?
Thank
/BlueIcaro