writing to tgas with alpha

Hi - in my code - i wrote a function that saves every frame to a tga file.
So I can basically play my window back later etc etc.

But i wanna be able to use alphas in tgas. So, where there are no objects in my scene, nothing is written to my tga file. If you get me.

Im using
glReadPixels(0,0,Xpixels,Ypixels,GL_RGB,GL_UNSIGNED_BYTE,(GLvoid *)imageData);

at he mo - which may not work for alphas - dunno -

anyway - much help needed

many thanks

But i wanna be able to use alphas in tgas. So, where there are no objects in my scene, nothing is written to my tga file. If you get me.

I think I understand what you want, but I also think you don’t realize what that really mean when reading the file. You can’t just skip writing a pixel just like that. If you want to save space by doing so, you must also provide information about what pixels are skipped so the image can be recreated without guessing. TGA does not give you any ways to do so. The closest file format I can think of is SGI’s fileformat, which can compress the image by storing multiple identical rows in the image as a single row in the file.

[This message has been edited by Bob (edited 12-12-2002).]

thx for ur reply.

maybe i didnt explain very well.
When using alpha with tga - the alpha part is basically “empty” - I want my tga writer to write the rgb values of my scene for the according pixels - and where there is nothing in my scene - write the according pixel as alpha.
This makes sense to me - but i dont hink im expalining right - sorry:S

cheers for ur reply

Your framebuffer already has an alpha channel (called the “destination alpha”), which gets updated just like the three color channels.

If you want to generate an image where your rendered object is opaque and the background is transparent, simply clear the destination alpha to 0 (glClearColor(0, 0, 0, 0)). When you read back the framebuffer, use GL_BGRA instead of GL_BGR (note that TGAs are not RGB!), and of course make sure to adjust the color depth of your image accordingly (32 bpp instead of 24).

– Tom

oo thanks

ill try that

i know tgas arent rgb - i just cant type

thx - ill let u know how it goes

Also make sure to ask for a destination alpha channel when choosing the pixel format.

sorry - but what do you mean?

When you create your window you ask for a certain pixel format. If you don’t say you want a destination alpha channel, you may not get one. And if you don’t get one, what you want to do won’t work.

TGA does not give you any ways to do so. The closest file format I can think of is SGI’s fileformat, which can compress the image by storing multiple identical rows in the image as a single row in the file.
TGAs do support RLE compression. If the background is a solid color, it can significantly reduce the size of an image.

When using alpha with tga - the alpha part is basically “empty” - I want my tga writer to write the rgb values of my scene for the according pixels - and where there is nothing in my scene - write the according pixel as alpha.
This makes sense to me - but i dont hink im expalining right - sorry:S
This makes no sense to me. It sounds like you’re suggesting that you want to switch from writing RGB values to just alpha values where there is nothing in the scene. You can’t do this. What do you want to do: compression or alpha blending? Perhaps you could get out your English-to-your-native-language dictionary and ask your question a third time.