views:

31

answers:

1

Hello everyone!

How can I alphablend only certain parts of a texture in DX 9?

For example, layers in Photoshop (or any other photo editing program that supports layers).
You can draw something in a layer (background filled with alpha), then place the layer over the original image (draw the texture on the screen) which leads to the original image + ONLY the things I drew in the layer.

Yes, I know my english is not very "shiny".

Thank you very much, in advance!

P.S. The background of my texture IS filled with alpha.

A: 

So you have setup the alpha on the texture you wish to overlay such that 0 is transparent (ie shows whats underneath) and 1 is opaque (ie shows the overlay texture)?

If so then you just need to set up a a simple blend mode:

pDevice->SetRenderState( D3DRS_SRCBLEND, D3DBLEND_SRCALPHA );
pDevice->SetRenderState( D3DRS_DESTBLEND, D3DBLEND_INVSRCALPHA );
pDevice->SetRenderState( D3DRS_ALPHABLENDENABLE, TRUE );

Make sure you draw the background first! Also note that values between 0 and 1 represent a linear interpolation between background and the overlay texture.

Goz
I enabled alphablending and did everything else you said, but it seems that whenever I set these render states : pDevice->SetRenderState( D3DRS_SRCBLEND, D3DBLEND_SRCALPHA ); pDevice->SetRenderState( D3DRS_SRCBLEND, D3DBLEND_INVSRCALPHA ); The textures are shown all black. Oh, and by the way, my game is 2D, and I've been wondering the whole day if the RHW in the FVF I'm using has anything to do with the problems I'm having. Big thanks again, in advance!Oh, and I hope I didn't misuse the comments.
C4theWin
What colour is the background? What are the vertex colours set to?
Goz
The background color is D3DCOLOR_XRGB(150, 200, 255). Vertex colors are all D3DCOLOR_ARGB(255, 255, 255, 255), though I tried some other colors too.
C4theWin
Then it might be handy to see your texture and its alpha channel.
Goz
The code here is setting the Source-Blend factor twice. For standard alpha-blending, you want `pDevice->SetRenderState( D3DRS_DSTBLEND, D3DBLEND_INVSRCALPHA );`
Alan
LOL well spotted Alan. Updated my answer!
Goz