Sign in to follow this  
Telamon

Easy Color Keying in D3D

Recommended Posts

I'm writting a tile-based game using D3D in C#. I've got a single layer tilemap displaying and it works great. Now I'm trying to display tiles with transparent sections on top of the single layer. If I were using DirectDraw, I would just specify black as the color key and any black in the original image wouldn't be drawn. Is there a magical combination of source and destination render ops that I can set in D3D that will make the color black in the source texture transparent when rendered? I know I can always get this to work by adding alpha channels in all my imagery, either with a paint program or at runtime. But I'm looking for something quick and easy. Regards

Share this post


Link to post
Share on other sites
Look at the D3DXCreateTextureFromFileEx() function - it has a ColorKey parameter that does exactly what you want. Remember, to make a D3DCOLOR, you can use the D3DCOLOR_ARGB() macro (there are others that are similar, as well).

Share this post


Link to post
Share on other sites
You could also use the Bitmap class's MakeTransparent() function which will create an appropriate alpha channel for the colour you specify.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this