PDA

View Full Version : saving the frame buffer



03-23-2002, 07:21 AM
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=j*SIZE*3;i<j*SIZE*3+SIZE*3;i+=3)
{
ImageData[i]=255*fTempImageData[count+2];
ImageData[i+1]=255*fTempImageData[count+1];
ImageData[i+2]=255*fTempImageData[count];
count+=3;
}
}

FileWrite(filename,SIZE*SIZE*3,SIZE,SIZE);


any help or relevant tutorials would be greatly appreciated.

zeckensack
03-23-2002, 08:14 AM
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.

03-23-2002, 10:22 AM
cheers, tryd that. still goes google eyed though http://www.opengl.org/discussion_boards/ubb/frown.gif think my tga saving routine isnt quite up to the job. if anyone knows of something that works id like to know http://www.opengl.org/discussion_boards/ubb/smile.gif

zed
03-23-2002, 11:23 AM
>>for(j=0;j<SIZE;j++)
{
for(i=j*SIZE*3;i<j*SIZE*3+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,SIZE*SIZE*3,SIZE,SIZE);<<

rts
03-23-2002, 11:45 AM
http://www.opengl.org/discussion_boards/ubb/Forum4/HTML/000182.html