Skip to main content
gamedev.net
🔒 Locked

Real simple transparency

Started by Orphix 4 replies 550+ views
Original Post
Orphix
Orphix
Hi, I''ve just started learning OpenGL, and NeHe''s tutorials really helped me a lot. But I can''t do a, I think, real simple thing. When I have a texture with a black background, how can I display it without the black background. So, not real blending, as the image has to be rendered normal, just the background has to be transparent. I''ve tried several blending functions, but they just don''t fullfill my needs How can I solve this? Thanks in advance, Orphix
Orphix
Orphix
Sorry, I should have gone through the forum first
There is already a post about this topic with the answers.
Promag
Promag
Well, what you need is masking. And Nehe have a tuturial about it. It uses two textures and then perform masking (i think)

But there''s another way to do it, but you will need another color channel: alpha

So, everthing that will be displayed, in alpha channel must be alpha > 0.

The rest is invisible, so alpha = 0

then in the glBendFunc you only pass the fragments with alpha > 0

cya


PROgrammer
Naveed Ahmed
Naveed Ahmed
Err... that''s interesting, can you explain it in more detail, alpha channel stuff?
Xersist
Xersist
Shouldn''t you just be able to do a quick and dirty one by enabling Blending?

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

I''m just learning too, but when I do this, the darker the area is, the more transparent it is.
-X-
Orphix
Orphix
I''ve read nehe''s tutorial and it seems to me there is only solution for my problem which is adding an alpha channel to the texture. I still have to do that.

But it seems like nehe''s tutorial #20 can only handle overlays, since OpenGL draws first the overlay and then the other stuff on pieces that are still blank. But as I don''t need a realy overlay, but more an object which has to rotate and moves behind other scenes this is no option for me.

And Xersist, blending will cause the black part to dissapear, but the image will be blended too, so that''s also no option for me.

I will try the alpha channel option asap.

Thanks for the reactions.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.