saving the frame buffer

i wonder if anyone can help me save out the current information contained in the framebuffer to a tga? im using the code below and it works to an extent. i get an image out but its kinda skewd and the colours are all wrong. im guessing its something about the pixel alinment thing but ive got no idea.

glReadBuffer(GL_BACK);

glReadPixels(0, 0, SIZE, SIZE, GL_RGB, GL_FLOAT, fTempImageData);

for(j=0;j<SIZE;j++)
{
for(i=jSIZE3;i<jSIZE3+SIZE3;i+=3)
{
ImageData[i]=255
fTempImageData[count+2];
ImageData[i+1]=255fTempImageData[count+1];
ImageData[i+2]=255
fTempImageData[count];
count+=3;
}
}

FileWrite(filename,SIZESIZE3,SIZE,SIZE);

any help or relevant tutorials would be greatly appreciated.

Use GL_UNSIGNED_BYTE instead of GL_FLOAT. This will save you the conversion.

Then add glPixelStorei(GL_PACK_ALIGNMENT,1); before calling glReadPixels (or put it in your general init code) and you should be all set.

cheers, tryd that. still goes google eyed though think my tga saving routine isnt quite up to the job. if anyone knows of something that works id like to know

>>for(j=0;j<SIZE;j++)
{
for(i=jSIZE3;i<jSIZE3+SIZE*3;i+=3)<<

is all the swaping necessary?
i just read + then write the data ( ie no swapping)

if it is a better/cleaner way would be
for (i=0; i<SIZE*SIZE; i++ )
{ image[i*3+0] = temp[i*3+2]
etc
}

also perhaps theres an error here
>>FileWrite(filename,SIZESIZE3,SIZE,SIZE);<<

http://www.opengl.org/discussion_boards/ubb/Forum4/HTML/000182.html