Subj : Problems writing BMP File To : comp.programming.threads From : Stephan Date : Fri Mar 11 2005 10:32 pm Hi I wanted to write a routine, that writes a BMP file. SO I took some code written for Windows. Unfortunately I work under Linux, so I can't include the mmsystem.h The generated BMP files are corrupt. I think it has to do something with the structs I had to build on my own, but don't know what. here is the code that I'm speaking of. #include #include using namespace std; typedef unsigned short WORD; typedef unsigned int DWORD; typedef long LONG; typedef struct tagBITMAPINFOHEADER{ DWORD biSize; LONG biWidth; LONG biHeight; WORD biPlanes; WORD biBitCount; DWORD biCompression; DWORD biSizeImage; LONG biXPelsPerMeter; LONG biYPelsPerMeter; DWORD biClrUsed; DWORD biClrImportant; } BITMAPINFOHEADER, *PBITMAPINFOHEADER; typedef struct tagBITMAPFILEHEADER { WORD bfType; DWORD bfSize; WORD bfReserved1; WORD bfReserved2; DWORD bfOffBits; } BITMAPFILEHEADER, *PBITMAPFILEHEADER; int screenshot(int x, int y, int Width, int Height, const char *fname) { BITMAPFILEHEADER bf; BITMAPINFOHEADER bi; unsigned char *image = (unsigned char*)malloc(sizeof(unsigned char)*Width*Height*3); FILE *file = fopen(fname, "wb"); if( image!=NULL ) { if( file!=NULL ) { glReadPixels( x, y, Width, Height, GL_BGR_EXT, GL_UNSIGNED_BYTE, image ); memset( &bf, 0, sizeof( bf ) ); memset( &bi, 0, sizeof( bi ) ); bf.bfType = 'MB'; bf.bfSize = sizeof(bf)+sizeof(bi)+Width*Height*3; bf.bfOffBits = sizeof(bf)+sizeof(bi); bi.biSize = sizeof(bi); bi.biWidth = Width; bi.biHeight = Height; bi.biPlanes = 1; bi.biBitCount = 24; bi.biSizeImage = Width*Height*3; fwrite( &bf, sizeof(bf), 1, file ); fwrite( &bi, sizeof(bi), 1, file ); fwrite( image, sizeof(unsigned char), Height*Width*3, file ); fclose( file ); } free( image ); } return 0; } Maybe someone can point me to the misstake Regards Stephan .