Sign in to follow this  
MPV

How can I put a image with some parts transparent?

Recommended Posts

MPV    122
I'm trying to make a 2D game with DirectX 9. I'm puting the images that I want to use in one surface using the function D3DXLoadSurfaceFromFile() and placing then in a surface created with CreateOffscreenPlainSurface(), but I have a problem, I can´t put the images with some parts transparent! I already try created one image in black and white (white is what I want to appear and black is what I want to became transparent), but I don´t know how to aply it! I also tryed creating a .dds image and in the program (DirectX Texture Tool) it worked! But when I used the function D3DXLoadSurfaceFromFile() to open it, the image was the same, it didn't made it transparent! Could someone tell me what functions I need to use or what to do! I already searched on the net, but I didn't find. Tks

Share this post


Link to post
Share on other sites
NexusOne    100
I'm not sure I'm the person to answer this question, as I haven't done 2D in DirectX, only 3D; and I've only used Managed DirectX; and I don't really know C++, BUT:
you definitely need to make an image object from your texture, go over each pixel and change it to have alpha 0 if it's a black pixel. Then you need to enable alpha-test in DX and use the alpha function to say if alpha is 0, don't render.

Share this post


Link to post
Share on other sites
SSJCORY    100
sounds right from the different alpha filtering techniques that i've used but i havent used dx before so i dont know the exact way.
-Cory

Share this post


Link to post
Share on other sites
Pelikaruga    142
The loadfromfile functions should have one parameter that defines the colorkey, the color that is transparent. Provide it with D3DCOLOR_XRGB( 0, 0, 0, 0 ).

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