question
Hi,
You've probably been asked this a million times, but how do I make part of a texture transparent so I can show the background through it with opengl in C++?
The two usual methods are to use an color key or an alpha channel.
For a color key, you color the parts you want to be transparent all as a single color, generally one that doesn't show up in the rest of your image. Be careful that the format of your texture doesn't have lossy compression otherwise your color key color will bleed into the rest of the texture giving you ugly artifacts.
For the alpha channel, most image editors offer the ability to simply add and the modify the alpha as a seperate layer or channel or mask. This depends somewhat on the image manipulation software yo use. For example, in Gimp I usually use a layer mask for transparency. Then I work directly on the mask to get the transparency effect I want. This gets flattened into the alpha channel when I export the texture to an image format that's loaded in OpenGL, usually a TGA.
For a color key, you color the parts you want to be transparent all as a single color, generally one that doesn't show up in the rest of your image. Be careful that the format of your texture doesn't have lossy compression otherwise your color key color will bleed into the rest of the texture giving you ugly artifacts.
For the alpha channel, most image editors offer the ability to simply add and the modify the alpha as a seperate layer or channel or mask. This depends somewhat on the image manipulation software yo use. For example, in Gimp I usually use a layer mask for transparency. Then I work directly on the mask to get the transparency effect I want. This gets flattened into the alpha channel when I export the texture to an image format that's loaded in OpenGL, usually a TGA.
I'm using BMP files... do you know how to do it with them, or can you tell me how to import another file type please
Use an image format that supports alpha channels (OK, according to the specs BMPs can have an alpha channel, too but I have yet to see an application that supports this[wink]). TGA and PNG are the most common formats used for 32 bit images with alpha channels.
Using these formats you best take some image library like OpenIL to load them into an OpenGL texture. This saves you from a lot of hassle with figuring out the formats and writing a custom loader.
Good luck,
Pat.
Using these formats you best take some image library like OpenIL to load them into an OpenGL texture. This saves you from a lot of hassle with figuring out the formats and writing a custom loader.
Good luck,
Pat.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement