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
|
typedef struct {
unsigned char TGAheader[12];
unsigned char header[6];
} TGA_header;
//// prend un screenshot en tga //////////////
void ScreenShot(int w,int h ) {
static int ShotIndex = 0;
char Filename[250];
sprintf(Filename,"shot%d.tga",ShotIndex);
byte* Buffer;
FILE* TGAFile;
TGA_header TGA;
byte HeightH,HeightL,WidthH,WidthL;
Buffer = (unsigned char*)calloc(w*h*3,sizeof(unsigned char));
glReadPixels(0,0,w,h,GL_BGR_EXT,GL_UNSIGNED_BYTE,Buffer); // change si tu veux une zone d ecran qui part pas de 0,0
TGAFile = fopen(Filename, "wb");
HeightH = (byte)(h / 256);
HeightL = (byte)(h % 256);
WidthH = (byte)(w / 256);
WidthL = (byte)(w % 256);
// Write TGA Header
TGA.TGAheader[0] = 0;
TGA.TGAheader[1] = 0;
TGA.TGAheader[2] = 2;
TGA.TGAheader[3] = 0;
TGA.TGAheader[4] = 0;
TGA.TGAheader[5] = 0;
TGA.TGAheader[6] = 0;
TGA.TGAheader[7] = 0;
TGA.TGAheader[8] = 0;
TGA.TGAheader[9] = 0;
TGA.TGAheader[10] = 0;
TGA.TGAheader[11] = 0;
TGA.header[0] = (byte) WidthL;
TGA.header[1] = (byte) WidthH;
TGA.header[2] = (byte) HeightL;
TGA.header[3] = (byte) HeightH;
TGA.header[4] = (byte) 24;
TGA.header[5] = 0;
fwrite(&TGA,sizeof(TGA_header),1,TGAFile);
fwrite(Buffer,w*h*3*sizeof(unsigned char),1,TGAFile);
fclose(TGAFile);
++ShotIndex;
delete []Buffer;
} |
Partager