hi guys
could you please tell me what could be the problem with this function…
this one i’ve almost completely rewrote from one of threads some time ago (think it was originally written by rts)…tried also another code from some tutorial - both were very similar but they build BMP files i can’t read then - every windows application says it’s not valid BMP format or starts to read it but doesn’t finish
in the code here is GL_RGB - i know i should replace R and B, but this shouldn’t make my file invalid…
so here’s the code
void screen_c::screenshot()
{
char fileName[256];
FILE *fBMP;sprintf(fileName, “save/screenshots/shot%i.bmp”, numScreenshots++);
if (!(fBMP = fopen(fileName, “wb”))) return;unsigned char image = (unsigned char) malloc(sizeof(unsigned char) * width * height * 3);
glReadPixels(0, 0, width, height, GL_RGB, GL_UNSIGNED_BYTE, image);struct BMPHeader
{
unsigned short type;
unsigned int size;
unsigned short res1;
unsigned short res2;
unsigned int offset;
} header;struct BMPInfo
{
unsigned int size;
unsigned int width;
unsigned int height;
unsigned short planes;
unsigned short bit_count;
unsigned int comp;
unsigned int sizeImage;
unsigned int x_pels_per_meter;
unsigned int y_pels_per_meter;
unsigned int clr_used;
unsigned int clr_important;
} info;header.type = ‘B’ | ‘M’ << 8;
header.size = sizeof(header) + sizeof(info) + width * height * 3;
header.res1 = header.res2 = 0;
header.offset = sizeof(header) + sizeof(info);
info.size = sizeof(info);
info.width = width;
info.height = height;
info.planes = 1;
info.bit_count = 24;
info.comp = 0;
info.sizeImage = width * height * 3;
info.x_pels_per_meter = info.y_pels_per_meter = 0;
info.clr_used = 0;
info.clr_important = 0;
fwrite(&header, sizeof(header), 1, fBMP);
fwrite(&info, sizeof(info), 1, fBMP);
fwrite(image, sizeof(unsigned char), width * height * 3, fBMP);fclose(fBMP);
}
thx for any suggestions