Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

I have a Direct3D9 application that is rendering ID3DXSprites. The problem I am experiencing is best described in this situation:

I have a texture that is totally opaque. On top of it I draw a rectangle filled with solid color and alpha of 128. On top of the rectangle I have a text that is totally opaque. I draw all of this and get the resulting image through GetRenderTarget call. The problem is that on the resulting image, on the area where the transparent rectangle is, I have semi transparent pixels. It is not a problem that the rectangle is transparent, the problem is that the resulting image is.

The question is how to setup the blending so in this situation I don't get the transparent pixels in the resulting image?

I use the sprite with D3DXSPRITE_ALPHABLEND which sets the device state to D3DBLEND_SRCALPHA and D3DBLEND_INVSRCALPHA. I tried couple of combinations of SetRenderState, like D3DBLEND_SRCALPHA, D3DBLEND_DESTALPHA etc., but couldn't make it work.

Thanks.

share|improve this question

migrated from stackoverflow.com Jun 25 '11 at 10:36

This question came from our site for professional and enthusiast programmers.

    
Why do you paint a transparent rectangle when you want no transparent pixels? –  vines Jun 24 '11 at 12:59
    
@vines I want a transparent rectangle over the first texture. But the resultant image shouldn't contain transparent pixels, since the first texture is totally opaque. –  ambrozija Jun 24 '11 at 13:15
    
Then it would be nice of you to post the code related to alpha-blending, so that we could check :) –  vines Jun 24 '11 at 13:58
    
There's really nothing to it: m_pSprite->Begin(D3DXSPRITE_ALPHABLEND); m_pSprite->Draw(m_vecTextures[0].pTexture, NULL, NULL, NULL, 0xffffffff); m_pSprite->End(); –  ambrozija Jun 24 '11 at 14:08

2 Answers 2

up vote 2 down vote accepted

You can use D3DRS_SEPARATEALPHABLENDENABLE render state to control the blend outcome in the alpha channel of the destination.

SetRenderState (D3DRS_SEPARATEALPHABLENDENABLE, TRUE); 
SetRenderState (D3DRS_SRCBLENDALPHA, D3DBLEND_ZERO);
SetRenderState (D3DRS_DESTBLENDALPHA, D3DBLEND_ONE);

Provided that your texture was filled with a fully opaque color to begin with; this should leave the alpha channel alone.

share|improve this answer
1  
@Aaldert thanks, but that didn't quite work for me. What did work was: SetRenderState (D3DRS_SEPARATEALPHABLENDENABLE, TRUE); SetRenderState (D3DRS_SRCBLENDALPHA, D3DBLEND_ONE); SetRenderState (D3DRS_DESTBLENDALPHA, D3DBLEND_ONE); –  ambrozija Jun 27 '11 at 8:57

for future reference, you should check out Pix in the directx SDK, it's a great tool for seeing exactly what is being rendered at each point, and working out how the final color fo a specific pixel was arrived at.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.