I hope it will make you happy when use it.
Code: Select all
void CaptureScreen(int w,int h, unsigned char *image)
{
BITMAPFILEHEADER bf;
BITMAPINFOHEADER bi;
//unsigned char *image = (unsigned char*)malloc(sizeof(unsigned char)*Width*Height * 3);
FILE *file = fopen("C:/a.bmp", "wb");
if (image != NULL)
{
if (file != NULL)
{
glReadPixels(0, 0, w, h, 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) + w * h * 3;
bf.bfOffBits = sizeof(bf) + sizeof(bi);
bi.biSize = sizeof(bi);
bi.biWidth = w;
bi.biHeight = h;
bi.biPlanes = 1;
bi.biBitCount = 24;
bi.biSizeImage = w * h * 3;
fwrite(&bf, sizeof(bf), 1, file);
fwrite(&bi, sizeof(bi), 1, file);
fwrite(image, sizeof(unsigned char), w*h * 3, file);
fclose(file);
}
}
}
Code: Select all
Surface Texture(cameraWidth, cameraHeight);
....
//In main method, on while method :o
CaptureScreen(cameraWidth, cameraHeight, Texture.GetBuffer());