0
votes

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: Corrupted export

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());

Correct export

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 ?

2

2 Answers

2
votes

I found the bug.It was wrong file open mode!

    shot=fopen(concatString.c_str(),"w");

when it had to be :

    shot=fopen(concatString.c_str(),"wb");

"wb" - as we intend to open binary file.

FreeImage did it right because it opens the file internally.

0
votes

It looks like the pitch/stride is wrong in your code.