Skip to main content
GameDev.net gamedev.net
🔒 Locked

Part of a texture... transparent ...

Started by SulphurTenM Apr 14, 2008 at 7:41 PM 4 replies 1.3k views
Original Post
SulphurTenM
SulphurTenM
I have looked around, and I have found that I use GL_BLEND to blend a texture with it's surrounds. But I want to have only part of a texture transparent, maybe the black part of a texture... I am using .tga 32bit/pixel images. The environmental settings for the textures are GL_REPLACE. So the question is, how do I get the black (or white) part of a texture to become completely transparent while retaining the rest of the image (completely opaque)? Thanks for any help.
GLUT Setup: -Dev C++ 4.9.9.2GPU: GeForce 7600GT (256mb)CPU: Core 2 Due 1.86RAM: 1Gig
dpadam450
dpadam450
Not sure why your using GL_REPLACE or what it will do to blending.

Open your .tga in GIMP. Make it have a transparent part, which 32-bit implies it already has an alpha channel. Paint away your alpha parts with an erase tool.

When you use glTexImage2d(...,GL_RBGA)

glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINSU_SRC_ALPHA)
NBA2K, Madden, Maneater, Killing Floor, Sims 
SulphurTenM
SulphurTenM
Ah ok, cool. I think I got it.

Thanks!
GLUT Setup: -Dev C++ 4.9.9.2GPU: GeForce 7600GT (256mb)CPU: Core 2 Due 1.86RAM: 1Gig
mmakrzem
mmakrzem
the code in VMK19C shows how to load a TGA file and apply a mask to the texture so that pixels become transparent.
SulphurTenM
SulphurTenM
One last question...

As it has become apparent that the order in which things are drawn (e.g. if there are two objects, obj1 and obj2, and obj1 is drawn first (and has some transparent features) and obj2 is behind obj1, whenever transparent parts of obj1 overlap with obj2, obj2 two is treated as non-existent...



Is there a way around this? I'm working in 3d, so unless I fix the camera, there are gonna to be a high number of occurrences of this type of effect.

[Edited by - SulphurTenM on April 15, 2008 9:10:24 AM]
GLUT Setup: -Dev C++ 4.9.9.2GPU: GeForce 7600GT (256mb)CPU: Core 2 Due 1.86RAM: 1Gig
Kalidor
Kalidor
Quote:
Original post by SulphurTenM
One last question...

As it has become apparent that the order in which things are drawn (e.g. if there are two objects, obj1 and obj2, and obj1 is drawn first (and has some transparent features) and obj2 is behind obj1, whenever transparent parts of obj1 overlap with obj2, obj2 two is treated as non-existent...

[broken img link]

Is there a way around this? I'm working in 3d, so unless I fix the camera, there are gonna to be a high number of occurrences of this type of effect.
The standard way of dealing with this is to render all opaque geometry, then render all transparent geometry sorted from farthest to closest. This comes up fairly regularly so if you need more information a search of these forums should help.

If you need it to be perfect, you could look into something like depth peeling. Although it is rather slow, it might be worth the cost depending on your needs.

Topic Locked

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

Sign in to reply to this topic.