I am writing OpenGL FBO content to TGA file.I read pixels in BGR format and saving to uncompressed TGA.The weird thing is that if I save monotone colors (no textures) my exporter writes ok,but if the pixel data comes from a texture I am getting result as is depicted in the following image:
And this is the correct export which I managed to get using FreeImage lib:
FIBITMAP *img = FreeImage_ConvertFromRawBits(pixels,_frameWidth,_frameHeight, 3 * _frameWidth , 24,FI_RGBA_RED_MASK, FI_RGBA_GREEN_MASK, FI_RGBA_BLUE_MASK,0);
FreeImage_Save(FIF_TARGA ,img,concatString.c_str());
So I suspect something is wrong with my TGA exporting code:
GLubyte header[18]={0,0,2,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
header[12] = _frameWidth & 0xFF;
header[13] = ( _frameWidth >> 8) & 0xFF;
header[14] = (_frameHeight) & 0xFF;
header[15] = (_frameHeight >> 8) & 0xFF;
header[16] = 24;
// write out the TGA header
fwrite(header,sizeof(GLubyte),18,shot);
//write out the data:
fwrite(pixels,sizeof(GLubyte), _frameWidth * _frameHeight * 3 ,shot);
fclose(shot);
What is wrong with it ?