Need some fast code to dump whole screenshoot of your opengl program to TGA image?
No problem!
with some small changes it would save to bmp as well, if you like png or jpg you'll have to extend that yourself
Code:
// this saves the viewport to a TGA file format
Procedure ScreenShoot(filen: string);
type
TTGAHeader = packed record
Length: Byte;
ColorMapType: Byte;
ImageType: Byte;
FirstEntryIndex: Word;
ColorMapLength: Word; // Palette Length - should be alaways 256
ColorMapEntrySize: Byte; // Palette BPP
XOriginImage: Word;
YOriginImage: Word;
ImageWidth: Word;
ImageHeight: Word;
PixelDepth: Byte;
ImageDescriptor: Byte; // AlphaBits (for example - 8 bits for 32 bit tga)
end; // 18
var
vport: array[0..3] of integer;
buffer: pchar;
bufflen: integer;
f: Tmemorystream;
TGAHeader: TTGAHeader;
begin
glGetIntegerv(GL_VIEWPORT, @vPort);
bufflen:= (vport[2] * vport[3]) * 3; // rgb
getmem(buffer, bufflen);
glPixelStorei(GL_PACK_ALIGNMENT, 1);
glReadPixels(0, 0, vport[2], vport[3], GL_BGR_EXT, GL_UNSIGNED_BYTE, buffer);
fillchar(TGAHeader, sizeof(TGAHeader), 0);
TGAHeader.ImageType:= 2;
TGAHeader.ImageWidth:= vport[2];
TGAHeader.ImageHeight:= vport[3];
TGAHeader.PixelDepth:= 24;
f:= Tmemorystream.Create;
f.Write(TGAHeader, sizeof(TGAHeader));
f.Write(buffer^, bufflen);
f.SaveToFile(filen);
f.free;
freemem(buffer);
end;
Bookmarks