simple transparency

Ok, I’ve been reading tutorials (nehe, jumping into, redbook, forum search…) for hours now, and I can’t find a solution to this simple problem:
How do I get simple transparent backgrounds for my textured sprites?!

I convert a texture with black background (RGB), and I can’t get it to be displayed correctly with transparent background. If I use blending with GL_ONE/GL_ONE or whatever else, it’s transparent all right, but the sprites are blended together, too, not drawn on top of each other!

do I really need to use RGBA sprites to have a single transparent color?! I guess it’s something incredibly trivial I just fail to see… :stuck_out_tongue:

You need a transparent component to the texture and then set up the blending mode to ALPHA/ONE_MINUS_ALPHA. Also make sure you turn off z-buffer writes before this and you sort the sprites from back to front in depth relatve to the camera position.

so I do need RGBA textures, just to get a single transparent color?

also, I take it you mean SRC_ALPHA and ONE_MINUS_SRC_ALPHA?

\ edit

well, it works with alpha channel… but that’s a bit overkill, isn’t it? :expressionless:

Yes, you need the alpha channel. That’s precisely what it is supposed to do - it sets the amount of transparency. How would you expect to make something transparent without transparency information? The other three channels set colour but don’t contain any transparency information, hence the need for the 4th channel.

There’s a difference between transparent and translucent.
An alpha channel is used to define the opacity of every single pixel of an image, this is (relatively) rarely used, while a single transparent color (sup “magic pink”) is just a simple transparency for non-rectangular sprites etc, this can be found everywhere, like here -> :), that’s why I expected opengl to have some way to set one transparent color for textures…

Colour key transparency (eg. ‘hot pink’ stuff) only really makes sense when you’re using palletted images - typically 16 or 256 colours - and one of them is marked as invisible. Palletted images in OpenGL don’t really exist[1], so instead we get proper RGBA support. If you’re really worried about the memory overhead when all you want is on/off transparency, it’s possible to load a 16bit RGBA image with only 1bit of alpha (5551 format). However the graphics card driver may or may not decide to expand that out to a full 32bit texture behind your back.

The major downside with colour key transparency is that when texture filtering is enabled the colour key starts bleeding into the rest of the sprite, so you end up with an ugly halo around it.

[1] well, theres a palletted texture extension, but it’s being phased out and not widely supported.

theres a masking tutorial at nehe, that does (more or less) what you want: http://nehe.gamedev.net/data/lessons/lesson.asp?lesson=20

but I would opt for the alpha channel, since you can do much more with it (e.g. glass windows in your sprite)