Quote:
# ifndef WIN32
typedef struct /**** BMP file header structure ****/
{
unsigned short bfType; /* Magic number for file */
unsigned int bfSize; /* Size of file */
unsigned short bfReserved1; /* Reserved */
unsigned short bfReserved2; /* ... */
unsigned int bfOffBits; /* Offset to bitmap data */
} BITMAPFILEHEADER;
# define BF_TYPE 0x4D42 /* "MB" */
typedef struct /**** BMP file info structure ****/
{
unsigned int biSize; /* Size of info header */
int biWidth; /* Width of image */
int biHeight; /* Height of image */
unsigned short biPlanes; /* Number of color planes */
unsigned short biBitCount; /* Number of bits per pixel */
unsigned int biCompression; /* Type of compression to use */
unsigned int biSizeImage; /* Size of image data */
int biXPelsPerMeter; /* X pixels per meter */
int biYPelsPerMeter; /* Y pixels per meter */
unsigned int biClrUsed; /* Number of colors used */
unsigned int biClrImportant; /* Number of important colors */
} BITMAPINFOHEADER;
# define BI_RGB 0 /* No compression - straight BGR data */
# define BI_RLE8 1 /* 8-bit run-length compression */
# define BI_RLE4 2 /* 4-bit run-length compression */
# define BI_BITFIELDS 3 /* RGB bitmap with RGB masks */
And here's my method to take a picture.
Quote:
void snapshot(int windowWidth, int windowHeight, char * filename){
char * bmpBuffer = (char *)malloc(windowWidth * windowHeight * 3);
if (!bmpBuffer) return;
glReadPixels((GLint)0, (GLint)0, (GLint)windowWidth - 1, (GLint)windowHeight - 1, GL_RGB, GL_UNSIGNED_BYTE, bmpBuffer);
FILE *filePtr = fopen(filename, "wb");
if (!filePtr) return;
BITMAPFILEHEADER bitmapFileHeader;
BITMAPINFOHEADER bitmapInfoHeader;
bitmapFileHeader.bfType = 0x424D; //"MB" - remember bitmap data is bottom to top, right to left
bitmapFileHeader.bfSize = windowWidth * windowHeight * 3;
bitmapFileHeader.bfReserved1 = 0; //reserved, always zero
bitmapFileHeader.bfReserved2 = 0; //reserved, always zero
bitmapFileHeader.bfOffBits = sizeof(BITMAPFILEHEADER) + sizeof(BITMAPINFOHEADER);
bitmapInfoHeader.biSize = sizeof(BITMAPINFOHEADER);
bitmapInfoHeader.biWidth = windowWidth - 1;
bitmapInfoHeader.biHeight = windowHeight - 1;
bitmapInfoHeader.biPlanes = 1;
bitmapInfoHeader.biBitCount = 24; //24 bit
bitmapInfoHeader.biCompression = BI_RGB; //0
bitmapInfoHeader.biSizeImage = 0; //can be ignored
bitmapInfoHeader.biXPelsPerMeter = 0; //Always zero
bitmapInfoHeader.biYPelsPerMeter = 0; //Always zero
bitmapInfoHeader.biClrUsed = 0; //24 bit, don't need these
bitmapInfoHeader.biClrImportant = 0; //24 bit doesn't have important colours
fwrite(&bitmapFileHeader, sizeof(BITMAPFILEHEADER), 1, filePtr);
fwrite(&bitmapInfoHeader, sizeof(BITMAPINFOHEADER), 1, filePtr);
fwrite(bmpBuffer, windowWidth * windowHeight * 3, 1, filePtr);
fclose(filePtr);
free(bmpBuffer);
}
I've been looking at it for an hour, I don't see it.