opengl - Writing uncompressed TGA to file in C++ -
i writing opengl fbo content tga file.i read pixels in bgr format , saving uncompressed tga.the weird thing if save monotone colors (no textures) exporter writes ok,but if pixel data comes texture getting result depicted in following image: 
and correct export managed 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 suspect wrong 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 tga header fwrite(header,sizeof(glubyte),18,shot); //write out data: fwrite(pixels,sizeof(glubyte), _framewidth * _frameheight * 3 ,shot); fclose(shot); what wrong ?
i found bug.it wrong file open mode!
shot=fopen(concatstring.c_str(),"w"); when had :
shot=fopen(concatstring.c_str(),"wb"); "wb" - intend open binary file.
freeimage did right because opens file internally.
Comments
Post a Comment