PDA

View Full Version : Sprites



02-10-2002, 09:52 AM
Hello!

I'm using textured quads as sprites in my OpenGL program. Everything works fine except transparency. I don't know how to make certain parts of my sprite transperent. I know that this can done in DirectDraw very easily by telling it the keycolor which is in my example purple (RGB = (255, 0, 255).

However, there is no such command in OpenGL and therefore I somehow have to tell OpenGL, how to make certain parts look transparent. I've read that this works well with image files (I'm using bitmaps) which have an alpha value set.. well, I don't know how to actually set the alpha value of an image - at least I don't have an app which can do that for me.

So how can I perform transperancy on my sprites? ( in a simple way )

P.S.
I don't want to use sprite libraries, DirectDraw, or anything else.. I want to do it on my own.

Mr_Smith
02-10-2002, 10:46 AM
U could use a mask i guess or if its just for particle effects i just blend it and although see though it self, it looks ok.

02-10-2002, 11:05 AM
If your current bitmap is a 24 bit RGB i means bitmap-data i an array of unsigned char's where every pixel is three bytes long. The first byte is the red value, the next is green and the last i blue. If you want to set the alpha-value you should convert the bitmap to an 32 bit RGBA bitmap in your code. The last byte in every pixel is the alpha value. Set to 0 for transparent and 255 for opaque.

Remember to enable blending:
glEnable (GL_BLEND);
And to set how OpenGL should blend:
glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);

MrShoe
02-10-2002, 07:28 PM
It is relatively easy to hack up a function that converts a 24bit bitmap to a 32bit bitmap using say black as a transparent colour key. Just check whether the first 3 bytes are all 0, and then set the 4th byte to 0 for transparant, 1 if the first 3 bytes are anything else.

02-10-2002, 08:28 PM
Thank you all very much for your help http://www.opengl.org/discussion_boards/ubb/smile.gif
I'll do as you suggested, writing a bmp converter and enable blending.

Hope

Leyder Dylan
02-12-2002, 11:26 AM
Use alpha chanel with TGA

On my site, I've a example for displayng a tree like a sprite. http://ibelgique.ifrance.com/Slug-Production/