Skip to main content
gamedev.net
🔒 Locked

Transparency Help

Started by Squirell Nov 2, 2004 at 11:11 AM 1 replies 350+ views
Original Post
Squirell
Squirell
I'm trying to implement a HUD for my game. I'm loading in textures and rendering them onto a already transformed quad (XYZRHW). Everything works fine except Im loading the texture via LoadTextureEx (or whatever it is). I'm color coding it so that pink is transparent. However, when I render it takes the background color (black) to replace the pink with. This makes things look really bad because instead of grabbing my grass for example it puts in a black square. So how do I get the transparency to work right? Sorry if I'm not making myself clear, just ask and I'll try to explain better...
Axiverse
Axiverse
can you tell us what renderstates you have set??
Namethatnobodyelsetook
Namethatnobodyelsetook
Using a color key just replaces the color with transparent black. You'll get ugly outlines on things if you have linear filtering, or mip maps. You can get away with this for sprites drawn 1:1 as long as you draw things properly, but in general it's a bad solution.

If your image contains an alpha channel, you'll get better results. Say you're making a leaf. Put green even outside the leaf, and create the shape with the alpha channel. Now when filtering or mip mapping, the color will remain as expected. Some versions of photoshop change alpha=0 pixels to white (to compress better), which ruins the texture for filtering and mipmaps... ensure your art tools don't do this, or that you use a minimum alpha of 1.

Also, ensure you ask D3D to load the image into a format that contains alpha bits. You'll need those regardless of using colorkey or an alpha channel in the file.

After that, you have to ensure you have alpha set up correctly.
D3DRS_ALPHABLENDENABLE, true
D3DRS_SRCBLEND, D3DBLEND_SRCALPHA
D3DRS_DESTBLEND, D3DBLEND_INVSRCALPHA
(optionally add in alphatest too, or even instead.)

Topic Locked

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

Sign in to reply to this topic.