How to make the transparent black in the surface become "transparent"?

When I use

HRESULT D3DXLoadSurfaceFromSurface(
LPDIRECT3DSURFACE9pDestSurface,
CONST PALETTEENTRY *pDestPalette,
CONST RECT *pDestRect,
LPDIRECT3DSURFACE9pSrcSurface,
CONST PALETTEENTRY *pSrcPalette,
CONST RECT *pSrcRect,
DWORDFilter,
D3DCOLORColorKey
);

according to the documantation of directx sdk, the color specified in ColorKey will be replaced by transparent black.

But if I load this surface to another surface, by D3DXLoadSurfaceFromSurface or StretchRect, the transparent black is visible and covering the background image in other surface.

So my question is, how to make the transparent black become "transparent" so that the image in other surface is not covered by that transparent black?

Thank you.

p.s. if I don't want to use sprite class, is there any solution?

[1079 byte] By [waison] at [2007-12-23]
# 1

I had the same problem you have before and I did the following stuff to fix it, I wish they can help

you as well

d3dDevice->SetRenderState(D3DRS_ALPHABLENDENABLE,true);
d3dDevice->SetRenderState(D3DRS_SRCBLEND,D3DBLEND_SRCALPHA);
d3dDevice->SetRenderState(D3DRS_DESTBLEND,D3DBLEND_INVSRCALPHA);

this is where I found the solution:

http://www.mvps.org/directx/articles/colorkeydx8.htm

However I do have a question is that since the above article I found is about DirectX8, then why I have to

do this in Directx9 as well to make the transparency effect work?

I hope somebody passed by here could give me some clue......

nikkitan at 2007-8-30 > top of Msdn Tech,Game Technologies: DirectX, XNA, XACT, etc.,Game Technologies: DirectX 101...
# 2

When you load a texture without alpha channel the Alpha is FF by default, not 00

Because it's assumed that the color is not transparent alpha 00 but opaque so a Alpha of FF

So if your colorkey test value is 0,0,0,0 it's not going to compare to any black in your loaded Texture

Because all your black color in your texture are assume to be 0,0,0,FF

You need to specify a colorkey value this way : 0x000000FF

When the loader see the color 0,0,0 in the texture without alpha channel

it will assume it's the color 0x000000FF opaque black (0,0,0,FF)

Now when it will compare to the ColorKey value 0x000000FF it will convert to transparent black 0x00000000

With alpha correctly to 00 so transparent...

It's logical but it's completely twisted...

You load a texture without alpha channel so all color have a alpha FF (including the black)

And are all opaque

After the load which replace the color 0,0,0,FF (0x000000FF) with 0,0,0,0 (0x00000000) transparent black

all color will have a alpha of FF but all your 0,0,0,FF black will be replace with 0,0,0,0...

Now you can use this loaded texture with all the black having a alpha at 00 and all other alpha at FF for all other color

Make sure you have a surface with alpha channel and that you copy the alpha channel too

You must have Texture with alpha channel format too

Etienne2005 at 2007-8-30 > top of Msdn Tech,Game Technologies: DirectX, XNA, XACT, etc.,Game Technologies: DirectX 101...