Alpha Blending?

Hello.
I`ve got a question. How can I make a texture, that will be transparent in some places. Lets take an example of the player. I would like it to be transparent in the background. Can I do it with glEnable()? Please help. :slight_smile:

Yes.

Either use [icode]glEnable(GL_ALPHA_TEST);[/icode], then only the purely transparent pixels in your texture will be discarded, or:

use [icode]glEnable(GL_BLEND);[/icode]. This will enable blending of semi-transparent pixels. This is much more advanced, and usually you don’t need it. Also different draw orders are giving different results… for example if I draw A over B, the resulting color is different than when I draw B over A.

Finally, please google more, and the docs are your friend:
glEnable();
Alpha Test
Blending

Also, mind that you can "configure" both the Alpha Test and Blending with [icode]glAlphaFunc(...);[/icode] and [icode]glBlendFunc(...);[/icode]. glAlphaFunc is pretty simple, I'd suggest you to "start" with this, since you don't even need something else in most cases, and you only need blending if you want to do stuff with transparency. Mind that it's much more complicated.

Thanks very much matheus23. ;D

:slight_smile:

Hopefully you’ve seen the edit … ::slight_smile:

Just add this into your display creation:

        glEnable(GL_BLEND);
        glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);

Now you will be able to use transparent textures.

Yes I have, thanks! ;D