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

Surface Transparency

Started by TGPrankster Mar 13, 2007 at 5:54 PM 1 replies 1.9k views
Original Post
TGPrankster
TGPrankster
Stupid question number 2! And on the same day, wow! So, I'm trying to make a HUD for my game using bitmaps that I load onto offscreen surfaces and render over the 3d part of the game. When I load the bitmaps, I specify pure white as the transparency color, but instead of becoming transparent, it just turns the white into pitch black! Can anyone help me fix this problem?
~ Open your mind ~
remigius
remigius
Aside from specifying the transparent color, you need to explicitly enable the AlphaTesting render state as described here. This will tell D3D not to render the transparent pixels of your texture. Don't forget to disable alphatesting when you're done with your HUD rendering, to save some performance and prevent unexpected transparency effects in the rest of your game.

If you need partial transparency ('see-through') you might want to look into alpha blending. This is a bit more complex as it brings in the need to perform some depthsorting manually (objects behind transparent objects need to be rendered first), but that shouldn't be too hard to do for a HUD.

Edit: if you're using D3DX sprites to render your hud, you should either pass in D3DXSPRITE_ALPHABLEND to the Begin method to tell the sprite to use alphablending OR you can pass in D3DXSPRITE_DONOTMODIFY_RENDERSTATE to tell the sprite to respect the renderstates you set. Otherwise the sprite will happily modify the renderstates to fit it's own needs.

Hope this helps :)
TGPrankster
TGPrankster
Okay. I've been using offScreen surfaces to make the interface for the game, but all I keep hearing about is using sprites and such. I don't know how to do that yet, so I guess I'll start experimenting with it.

Thanks for the help!
~ Open your mind ~

Topic Locked

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

Sign in to reply to this topic.