Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // ---------------------
- // Unit: Font4.pas
- //
- // FontObjs now load data and images separately
- // Uses proper ABC font widths
- // Supports Unicode Widestrings. (not Win 98 and earlier compatible?)
- //
- // Can Load JPG (separate RGB and Alpha) and 32bit TGAs
- // Can Load Binary Fnt Data which has been combined with another file or separately.
- //
- // 17/08/08 - Added support for .fnt files.
- //
- // Author: Michael Pote
- // Date: 30 April 2007
- // -------------------
- unit Font4;
- interface
- Uses GL,GLU; //Use either OpenGL, OpenGL12 or dglOpenGl, they are all compatible here.
- const
- MAX_CHARS = high(Word);
- USE_MIPMAP = false; //if you dont want mipmaps set this to false.
- USE_INVERTED = false; //Use this if you use inverted GL coordinates
- //where (0,0) is the top left corner.
- USE_AUTOTEXTURESWITCH = true; //Use this to change the GL texture
- //every time you draw text, saving you
- //from having to manually change to the
- //font texture every time you want
- //to write something to screen.
- type FontInfo = record
- A, C: integer;
- Wid, Hgt: cardinal;
- char: WideChar;
- x1,y1,x2,y2: double;
- end;
- TFontObj = class
- private
- CharLookup: array[0..MAX_CHARS] of integer;
- public
- F: array of FontInfo;
- NumFonts: cardinal;
- TexInd: glUInt;
- SpaceWidth, MaxHeight: cardinal;
- constructor Create; overload;
- function LoadFnt(const Path: string): boolean;
- function LoadTGAComp(const Path: string): boolean;
- function LoadJPEGs(const rgb, alpha: string): boolean;
- function LoadData(const Filename: string; MergedFile: boolean): boolean;
- function TextLen(const Txt: widestring): integer;
- function TextLenEx(const Txt: widestring; Size: single): single;
- Procedure Draw(Const X,Y: single;Const Txt: widestring; Lev:single); Overload;
- function GetXPos(Const X: single;Const Txt: widestring; const charindex: integer): single;
- Procedure DrawEx(Const X,Y: single;Const Txt: widestring; Size:single);
- end;
- Procedure DrawQuadRT(X, Y, Wid, Hgt, Lev, Tu, Tu2, Tv,Tv2: single);
- Procedure DrawQuadRTI(X, Y, Wid, Hgt, Lev, Tu, Tu2, Tv,Tv2: single);
- implementation
- Uses Classes, {Windows,} {JPEG, Graphics,} SysUtils;
- const
- MajorVersion: byte = 4;
- MinorVersion: byte = 0;
- type QuadDrawingFunction = procedure(X, Y, Wid, Hgt, Lev, Tu, Tu2, Tv,Tv2: single);
- function LoadJPGs(Filename1, Filename2: String; var Texture: GLuint): Boolean; forward;
- function LoadTGA( filename : string; var TexId: glUint; MipMap: boolean) : boolean; forward; // Loads A TGA File Into Memory
- var DrawQuad: QuadDrawingFunction;
- ////////////////////////////////////////////////////////////////////////////////
- // TFONTOBJ
- ////////////////////////////////////////////////////////////////////////////////
- constructor TFontObj.Create;
- begin
- inherited Create;
- NumFonts := 0;
- end;
- function TFontObj.TextLen(const Txt: widestring): integer;
- var CurX: integer;
- Ch: Widechar;
- Chaar, I, Ind: integer;
- begin
- CurX := 0;
- for I := 1 to length(Txt) do
- begin
- Ch := Txt[I];
- Chaar := integer(ch);
- if Chaar = 32 then
- begin
- Ind := -1;
- CurX := CurX + SpaceWidth;
- end
- else
- begin
- Ind := CharLookup[Chaar];
- end;
- if ind > -1 then
- begin
- CurX := CurX + F[Ind].A;
- //DrawQuadRT(CurX, Y, F[ind].Wid, F[ind].Hgt, 0, F[ind].x1,F[ind].x2,F[ind].y1,F[ind].y2);
- CurX := CurX + F[Ind].C;
- end;
- end;
- result := CurX;
- end;
- function TFontObj.TextLenEx(const Txt: widestring; Size: single): single;
- var CurX: single;
- Ch: Widechar;
- Chaar, I, Ind: integer;
- begin
- CurX := 0;
- for I := 1 to length(Txt) do
- begin
- Ch := Txt[I];
- Chaar := integer(ch);
- if Chaar = 32 then
- begin
- Ind := -1;
- CurX := CurX + SpaceWidth*Size;
- end
- else
- begin
- Ind := CharLookup[Chaar];
- end;
- if ind > -1 then
- begin
- CurX := CurX + F[Ind].A*Size;
- //DrawQuadRT(CurX, Y, F[ind].Wid, F[ind].Hgt, 0, F[ind].x1,F[ind].x2,F[ind].y1,F[ind].y2);
- CurX := CurX + F[Ind].C*Size;
- end;
- end;
- result := CurX;
- end;
- procedure TFontObj.Draw(const X, Y: single; const Txt: widestring; Lev: single);
- var CurX: single;
- Ch: Widechar;
- Chaar, I, Ind: integer;
- begin
- CurX := X;
- if USE_AUTOTEXTURESWITCH then glBindTexture(GL_TEXTURE_2D, TexInd);
- for I := 1 to length(Txt) do
- begin
- Ch := Txt[I];
- Chaar := integer(ch);
- if Chaar = 32 then
- begin
- Ind := -1;
- CurX := CurX + SpaceWidth;
- end
- else
- begin
- Ind := CharLookup[Chaar];
- end;
- if ind > -1 then
- begin
- CurX := CurX + F[Ind].A;
- DrawQuad(CurX, Y, F[ind].Wid, F[ind].Hgt, lev, F[ind].x1,F[ind].x2,F[ind].y1,F[ind].y2);
- CurX := CurX + F[Ind].C;
- end;
- end;
- end;
- procedure TFontObj.DrawEx(const X, Y: single; const Txt: widestring;
- Size: single);
- var CurX: single;
- Ch: Widechar;
- Chaar, I, Ind: integer;
- begin
- CurX := X;
- if USE_AUTOTEXTURESWITCH then glBindTexture(GL_TEXTURE_2D, TexInd);
- for I := 1 to length(Txt) do
- begin
- Ch := Txt[I];
- Chaar := integer(ch);
- if Chaar = 32 then
- begin
- Ind := -1;
- CurX := CurX + SpaceWidth*Size;
- end
- else
- begin
- Ind := CharLookup[Chaar];
- end;
- if ind > -1 then
- begin
- CurX := CurX + F[Ind].A*Size;
- DrawQuad(CurX, Y, F[ind].Wid*Size, F[ind].Hgt*Size, 0, F[ind].x1,F[ind].x2,F[ind].y1,F[ind].y2);
- CurX := CurX + F[Ind].C*Size;
- end;
- end;
- end;
- function TFontObj.GetXPos(const X: single; const Txt: widestring; const charindex: integer): single;
- var CurX: single;
- Ch: Widechar;
- Chaar, I, Ind: integer;
- begin
- CurX := X;
- for I := 1 to CharIndex do
- if I <= Length(Txt) then
- begin
- Ch := Txt[I];
- Chaar := integer(ch);
- if (Chaar = 32) then
- begin
- Ind := -1;
- if I < CharIndex then
- CurX := CurX + SpaceWidth;
- end
- else
- begin
- Ind := CharLookup[Chaar];
- end;
- if ind > -1 then
- begin
- CurX := CurX + F[Ind].A;
- //DrawQuad(CurX, Y, F[ind].Wid*Size, F[ind].Hgt*Size, 0, F[ind].x1,F[ind].x2,F[ind].y1,F[ind].y2);
- if I < CharIndex then
- CurX := CurX + F[Ind].C;
- end;
- end
- else
- if I < CharIndex then
- CurX := CurX + self.SpaceWidth;
- result := CurX;
- end;
- //Loads the data part of the font.
- //Use MergedFile if you saved the data into the graphic composite in Font Studio.
- //Can only load binary font data (.Fnt filetype)
- function TFontObj.LoadData(const Filename: string; MergedFile: boolean): boolean;
- var Fs: TFileStream;
- Pos: int64;
- I: integer;
- Header: array[0..3] of char;
- begin
- Fs := nil;
- try
- Fs := TFileStream.Create(filename, fmOpenRead);
- if MergedFile then
- begin
- Fs.Seek(-10, soFromEnd);
- Fs.Read(Header[0], 2);
- if (header[0] <> 'F') or (header[1] <> 'S') then
- begin
- // Messagebox(0, 'TFontObj.LoadData: This is not a valid Merged file.', 'Error', MB_OK);
- result := false; //Not a valid merged file.
- exit;
- end;
- Fs.Read(Pos, sizeof(int64));
- Fs.Seek(Pos, soFromBeginning); //Move to the correct position.
- end;
- Fs.Read(Header[0], 4);
- if (header[0] <> 'F') or (header[1] <> 'S') then
- begin
- // Messagebox(0, 'TFontObj.LoadData: This is not a valid font file (must be .fnt format).', 'Error', MB_OK);
- result := false; //Not a valid file.
- exit;
- end;
- //if (byte(header[2]) <> MajorVersion) or (byte(header[3]) <> MinorVersion) then
- if (header[2] <> 't') or (header[3] <> 'd') then
- begin
- // Messagebox(0, 'TFontObj.LoadData: Warning! Version Mismatch!', 'Error', MB_OK);
- end;
- Fs.Read(NumFonts, sizeof(Cardinal));
- Fs.Read(SpaceWidth, sizeof(Cardinal));
- setlength(F, NumFonts);
- for I := 0 to MAX_CHARS-1 do
- CharLookup[I] := -1;
- MaxHeight := 0;
- for I := 0 to NumFonts-1 do
- begin
- fs.Read(F[I].char, sizeof(WideChar));
- fs.Read(F[I].A, sizeof(integer));
- fs.Read(F[I].C, sizeof(integer));
- fs.Read(F[I].Wid, sizeof(cardinal));
- fs.Read(F[I].Hgt, sizeof(cardinal));
- fs.Read(F[I].X1, sizeof(double));
- fs.Read(F[I].Y1, sizeof(double));
- fs.Read(F[I].X2, sizeof(double));
- fs.Read(F[I].Y2, sizeof(double));
- if F[I].Hgt > MaxHeight Then MaxHeight := F[I].Hgt;
- if (integer(F[I].char) >= 0) and (integer(F[I].char) < MAX_CHARS) then
- CharLookup[integer(F[I].char)] := I;
- end;
- Result := true;
- finally
- if assigned(Fs) then Fs.Free;
- end;
- end;
- function TFontObj.LoadFnt(const Path: string): boolean;
- begin
- //fnt files are just TGA composites.
- result := LoadTGAComp(Path) and LoadData(path, true);
- end;
- // Loads two jpeg images as the font texture.
- function TFontObj.LoadJPEGs(const rgb, alpha: string): boolean;
- begin
- LoadJpgs(rgb, alpha, TexInd);
- end;
- // Loads a 32bit TGA image as the font texture.
- function TFontObj.LoadTGAComp(const Path: string): boolean;
- begin
- result := LoadTGA(path, TexInd, USE_MIPMAP);
- end;
- ////////////////////////////////////////////////////////////////////////////////
- function CreateTexture(Width, Height, Format : Word; pData : Pointer; Mipmap: boolean) : Integer;
- var
- Texture : GLuint;
- begin
- glGenTextures(1, @Texture);
- glBindTexture(GL_TEXTURE_2D, Texture);
- glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE); {Texture blends with object background}
- { Select a filtering type. BiLinear filtering produces very good results with little performance impact
- GL_NEAREST - Basic texture (grainy looking texture)
- GL_LINEAR - BiLinear filtering
- GL_LINEAR_MIPMAP_NEAREST - Basic mipmapped texture
- GL_LINEAR_MIPMAP_LINEAR - BiLinear Mipmapped texture
- }
- if Mipmap then
- begin
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); { only first two can be used }
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR); { all of the above can be used }
- end
- else
- begin
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); { only first two can be used }
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); { all of the above can be used }
- end;
- if Format = GL_RGBA then
- gluBuild2DMipmaps(GL_TEXTURE_2D, GL_RGBA, Width, Height, GL_RGBA, GL_UNSIGNED_BYTE, pData)
- else
- gluBuild2DMipmaps(GL_TEXTURE_2D, format, Width, Height, format, GL_UNSIGNED_BYTE, pData);
- result :=Texture;
- end;
- function LoadJPGs(Filename1, Filename2: String; var Texture: GLuint): Boolean;
- {var
- Data : Array of Byte;
- W, Width : Integer;
- H, Height : Integer;
- BMP : TBitmap;
- JPG: TJPEGImage;
- C : LongWord;
- Line : PByteArray;
- MaxSize: integer;
- TD: Array of LongWord;
- ScaleF: single;
- OldW, OldH, X, Y, I: integer;}
- begin
- { result :=FALSE;
- JPG:=TJPEGImage.Create;
- try
- JPG.LoadFromFile(Filename1);
- except
- MessageBox(0, PChar('Couldn''t load JPG - "'+ Filename1 +'"'), PChar('BMP Unit'), MB_OK);
- Exit;
- end;
- // Create Bitmap
- BMP:=TBitmap.Create;
- BMP.pixelformat:=pf24bit;
- BMP.width:=JPG.width;
- BMP.height:=JPG.height;
- BMP.canvas.draw(0,0,JPG); // Copy the JPEG onto the Bitmap
- Width :=BMP.Width;
- Height :=BMP.Height;
- SetLength(Data, Width*Height*4);
- For H:=0 to Height-1 do
- Begin
- Line :=BMP.scanline[Height-H-1]; // flip JPEG
- For W:=0 to Width-1 do
- Begin
- Data[(W*4)+(H*Width*4)] := Line[W*3+2];
- Data[(W*4)+1+(H*Width*4)] := Line[W*3+1];
- Data[(W*4)+2+(H*Width*4)] := Line[W*3];
- End;
- End;
- try
- JPG.LoadFromFile(Filename2);
- except
- MessageBox(0, PChar('Couldn''t load JPG - "'+ Filename2 +'"'), PChar('BMP Unit'), MB_OK);
- Exit;
- end;
- BMP.canvas.draw(0,0,JPG); // Copy the JPEG onto the Bitmap
- For H:=0 to Height-1 do
- Begin
- Line :=BMP.scanline[Height-H-1]; // flip JPEG
- For W:=0 to Width-1 do
- Begin
- Data[(W*4)+3+(H*Width*4)] := Line[W*3];
- End;
- End;
- BMP.free;
- JPG.free;
- glGetIntegerv(GL_MAX_TEXTURE_SIZE, @MaxSize);
- OldW := -1;
- if width > Height then
- begin
- if width > Maxsize then
- begin
- ScaleF := MaxSize / width;
- OldW := width;
- OldH := Height;
- width := Maxsize;
- Height := round(Height*ScaleF);
- end;
- end
- else
- begin
- if height > Maxsize then
- begin
- ScaleF := MaxSize / height;
- OldW := width;
- OldH := Height;
- height := Maxsize;
- width := round(width*ScaleF);
- end;
- end;
- if OldW > -1 then
- begin
- ScaleF := 1/ScaleF;
- SetLength(TD, Width*Height);
- For X := 0 to Width-1 do
- For Y := 0 to Height-1 do
- begin
- TD[(Y*Width+X)] := data[
- round(((Y*OldW)*ScaleF+(X*ScaleF)))
- ];
- end;
- SetLength(Data, Width*Height);
- For Y := 0 to high(Td) do
- Data[Y] := Td[Y];
- SetLength(TD, 0);
- end;
- Texture :=CreateTexture(Width, Height, GL_RGBA, addr(Data[0]), USE_MIPMAP);}
- result :=TRUE;
- end;
- Procedure DrawQuadRT(X, Y, Wid, Hgt, Lev, Tu, Tu2, Tv,Tv2: single);
- begin
- Tv := 1-Tv;
- Tv2 := 1-Tv2;
- glBegin(GL_QUADS);
- glTexCoord2f(Tu, Tv); glVertex3f(X, Y, -lev);
- glTexCoord2f(Tu2, Tv); glVertex3f(X+Wid, Y, -lev);
- glTexCoord2f(Tu2,Tv2); glVertex3f(X+Wid, Y-Hgt, -lev);
- glTexCoord2f(Tu, Tv2); glVertex3f(X, Y-Hgt, -lev);
- glEnd;
- end;
- Procedure DrawQuadRTI(X, Y, Wid, Hgt, Lev, Tu, Tu2, Tv,Tv2: single);
- begin
- Tv := 1-Tv;
- Tv2 := 1-Tv2;
- glBegin(GL_QUADS);
- glTexCoord2f(Tu, Tv) ; glVertex3f(X, Y , -lev);
- glTexCoord2f(Tu2, Tv) ; glVertex3f(X+Wid, Y , -lev);
- glTexCoord2f(Tu2, Tv2); glVertex3f(X+Wid, Y+Hgt, -lev);
- glTexCoord2f(Tu, Tv2); glVertex3f(X, Y+Hgt, -lev);
- glEnd;
- end;
- function LoadTGA( filename : string; var TexId: glUint; MipMap: boolean) : boolean; // Loads A TGA File Into Memory
- const
- TGAheader : array [0..11] of GLubyte = (0,0,2,0,0,0,0,0,0,0,0,0); // Uncompressed TGA Header
- TGAComheader : array [0..11] of GLubyte = (0,0,10,0,0,0,0,0,0,0,0,0); // Compressed TGA Header
- type TextureImage = record // Structure Name
- imageData : PChar; // Image Data (Up To 32 Bits)
- bpp : GLuint; // Image Color Depth In Bits Per Pixel.
- width : GLuint; // Image Width
- height : GLuint; // Image Height
- texID : GLuint;
- end;
- var
- TGAcompare : array [0..11] of GLubyte; // Used To Compare TGA Header
- header : array [0..5] of GLubyte; // First 6 Useful Bytes From The Header
- bytesPerPixel : GLuint; // Holds Number Of Bytes Per Pixel Used In The TGA File
- imageSize : GLuint; // Used To Store The Image Size When Setting Aside Ram
- i : GLuint; // Temporary Variable
- gltype : GLuint; // Set The Default GL Mode To RBGA (32 BPP)
- Compressed:boolean;
- Tm: Char;
- Texture: TextureImage;
- tgafile : integer;
- TD: pchar;
- ScaleF: single;
- OldW, OldH, X, Y: integer;
- PixelCount, CurrentPixel, CurrentByte: gluInt;
- ColorBuffer: Pchar;
- ChunkHeader: gluByte;
- Counter, Ret: integer;
- begin
- tgafile := FileOpen(filename, fmOpenReadWrite);
- Ret := FileRead(tgafile, TGAcompare, sizeof(TGAcompare));
- if (
- (tgafile = -1) or // Does File Even Exist?
- (Ret <> sizeof(TGAcompare)) // Are There 12 Bytes To Read?
- )
- then
- begin
- //ShowError(10, 'TGATexture.LoadTGA', False);
- if (tgafile = -1) then // Did The File Even Exist? *Added Jim Strong*
- begin
- result := false; // Return False
- exit;
- end
- else
- begin
- fileclose(tgafile); // If Anything Failed, Close The File
- result := false; // Return False
- exit;
- end;
- end;
- if (CompareMem(@TGAheader, @TGAcompare, sizeof(TGAheader)) = false) // Does The Header Match What We Want?
- Then
- begin //File is not uncompressed...
- if (CompareMem(@TGAComheader, @TGAcompare, sizeof(TGAComheader)) = True) // Does The Header Match What We Want?
- Then
- Begin
- Compressed := True;
- end
- else
- Begin
- i := 0;
- //ShowError(17, 'TGATexture.LoadTGA', False);
- if (tgafile = -1) then // Did The File Even Exist? *Added Jim Strong*
- begin
- result := false; // Return False
- exit;
- end
- else
- begin
- fileclose(tgafile); // If Anything Failed, Close The File
- result := false; // Return False
- exit;
- end;
- end;
- end
- else
- begin
- Compressed := False;
- end;
- if (FileRead(tgafile, header, sizeof(header)) <> sizeof(header)) then
- begin
- //ShowError(10, 'TGATexture.LoadTGA', False);
- if (tgafile = -1) then // Did The File Even Exist? *Added Jim Strong*
- begin
- result := false; // Return False
- exit;
- end
- else
- begin
- fileclose(tgafile); // If Anything Failed, Close The File
- result := false; // Return False
- exit;
- end;
- end;
- texture.width := header[1] * 256 + header[0]; // Determine The TGA Width (highbyte*256+lowbyte)
- texture.height := header[3] * 256 + header[2]; // Determine The TGA Height (highbyte*256+lowbyte)
- if (texture.width <= 0) or // Is The Width Less Than Or Equal To Zero
- (texture.height <= 0) or // Is The Height Less Than Or Equal To Zero
- ((header[4] <> 24) and (header[4] <> 32)) then // Is The TGA 24 or 32 Bit?
- begin
- //ShowError(11, 'TGATexture.LoadTGA', False);
- fileclose(tgafile); // If Anything Failed, Close The File
- result := false; // Return False
- exit;
- end;
- texture.bpp := header[4]; // Grab The TGA's Bits Per Pixel (24 or 32)
- bytesPerPixel := texture.bpp div 8; // Divide By 8 To Get The Bytes Per Pixel
- imageSize := texture.width * texture.height * bytesPerPixel; // Calculate The Memory Required For The TGA Data
- If BytesPerPixel = 4 then glType := GL_RGBA else
- glType := GL_RGB;
- GetMem(texture.imageData, imageSize); // Reserve Memory To Hold The TGA Data
- //Setlength(texture.imagedata, imagesize);
- if Not Compressed then
- begin
- if (texture.imageData = nil) or // Does The Storage Memory Exist?
- (fileread(tgafile, texture.imageData^, integer(imageSize)) <> imageSize) // Does The Image Size Match The Memory Reserved?
- then
- begin
- if (texture.imageData <> nil) // Was Image Data Loaded
- then freemem(texture.imageData); // If So, Release The Image Data
- fileclose(tgafile); // Close The File
- //ShowError(10, 'TGATexture.LoadTGA', False);
- result := false; // Return False
- exit;
- end;
- i := 0;
- while i < imageSize do
- with texture do
- begin
- Tm := ImageData[I+2];
- imageData[i+2] := imageData[i]; // Set The 3rd Byte To The Value In 'temp' (1st Byte Value)
- imageData[i] := Tm; // Set The 1st Byte To The Value Of The 3rd Byte
- i := i + bytesPerPixel;
- end;
- end
- else //COMPRESSED TGA'S
- begin
- PixelCount := texture.width * Texture.Height;
- CurrentPixel := 0;
- CurrentByte := 0;
- GetMem(ColorBuffer, BytesPerPixel);
- Repeat
- ChunkHeader := 0;
- if FileRead(tgaFile, ChunkHeader, sizeof(gluByte)) = 0 then
- begin
- //ERROR reading Chunk!
- fileclose(tgafile); // Close The File
- result := false; // Return False
- exit;
- end;
- if ChunkHeader < 128 then
- begin
- ChunkHeader := ChunkHeader + 1;
- For Counter := 0 to ChunkHeader-1 do
- begin
- if fileRead(tgafile, ColorBuffer^, BytesPerPixel) <> BytesPerPixel then
- begin
- fileclose(tgafile); // Close The File
- result := false; // Return False
- exit;
- end;
- Texture.imageData[CurrentByte] := (ColorBuffer[2]);
- Texture.imageData[CurrentByte+1] := (ColorBuffer[1]);
- Texture.imageData[CurrentByte+2] := (ColorBuffer[0]);
- if BytesPerPixel = 4 then
- Texture.imageData[CurrentByte+3] := (ColorBuffer[3]);
- CurrentByte := CurrentByte + bytesPerPixel;
- inc(CurrentPixel);
- if CurrentPixel > PixelCount then
- begin
- fileclose(tgafile); // Close The File
- result := false; // Return False
- exit;
- end;
- end;
- end
- else //Chunkheader > 128
- begin
- ChunkHeader := ChunkHeader - 128;
- if fileRead(tgafile, ColorBuffer^, BytesPerPixel) <> BytesPerPixel then
- begin
- fileclose(tgafile); // Close The File
- result := false; // Return False
- exit;
- end;
- For Counter := 0 to ChunkHeader do
- begin
- Texture.imageData[CurrentByte] := ColorBuffer[2];
- Texture.imageData[CurrentByte+1] := ColorBuffer[1];
- Texture.imageData[CurrentByte+2] := ColorBuffer[0];
- if BytesPerPixel = 4 then
- Texture.imageData[CurrentByte+3] := ColorBuffer[3];
- CurrentByte := CurrentByte + bytesPerPixel;
- inc(CurrentPixel);
- end;
- end;
- Until CurrentPixel >= PixelCount;
- FreeMem(ColorBuffer);
- end;
- fileclose (tgafile); // Close The File
- // Build A Texture From The Data
- Texture.texId := CreateTexture(Texture.Width, Texture.Height, glType, Texture.Imagedata, Mipmap);
- FreeMem(Texture.ImageData);
- TexId := Texture.texID;
- result := true; // Texture Building Went Ok, Return True
- end;
- procedure SetupInversion;
- begin
- if USE_INVERTED then
- begin
- DrawQuad := @DrawQuadRTI;
- end
- else
- begin
- DrawQuad := @DrawQuadRT;
- end;
- end;
- initialization
- SetupInversion;
- end.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement