Sprites and Alpha channels

Started by
2 comments, last by Haytil 19 years, 3 months ago
im using an ID3DXSprite and i want to use an alpha channel in the texture but it doesn't seem to want to work am i limited to using the sprites draw function for create an alpha level? currently i am doing this before i draw but it is not working d3dd->SetRenderState(D3DRS_ALPHABLENDENABLE, TRUE); d3dd->SetRenderState(D3DRS_SRCBLEND, D3DBLEND_SRCALPHA); d3dd->SetRenderState(D3DRS_DESTBLEND, D3DBLEND_INVSRCALPHA); where d3dd is the Direct3DDevice pointer any help would be grand thanks
Advertisement
I'm not sure of the specifics of the D3DX Sprite stuff, so I don't know specifically what states it sets on it's own. But you might need to set the texture stage state properties, too. You'll want to set the D3DTSS_COLOROP to D3DTOP_SELECTARG1, probably, and set D3DTSS_COLORARG1 to D3DTA_TEXTURE, of course, and make sure to also set D3DTSS_ALPHAOP to D3DTOP_SELECTARG1, and D3DTSS_ALPHAARG1 to D3DTA_TEXTURE. It might likely default D3DTSS_ALPHAOP to D3DTOP_DISABLE. *checks docs* Okay, never mind, the default is D3DTOP_SELECTARG1 and D3DTA_TEXTURE, just like you should want. But I don't know. Might be something to look into anyway.
"We should have a great fewer disputes in the world if words were taken for what they are, the signs of our ideas only, and not for things themselves." - John Locke
D3DXSprite sets the states it needs when you call Begin. Are you passing the D3DXSPRITE_ALPHABLEND flag into the Begin call?
Stay Casual,KenDrunken Hyena
The way I do alpha blending with ID3DXSprite is as follows:

I call the sprite's "Draw" function, passing all the relevant information to it.

Draw(pSprite_Texture, &src_Rect, NULL, NULL, 0, &vPosition, D3DCOLOR_COLORVALUE(1.0f, 1.0f, 1.0f, alpha));


Here, &src_Rect is the adress of the rectangle, specifying coordinates on the texture pointed to by pSprite_Texture. My final argument in the function is how I control the alpha blending: I pass 1.0f for all three color channels, and the value "alpha" for the alpha channel (in a D3DCOLOR_COLORVALUE macro), where alpha is pre-determined and is between 0.0 and 1.0.

1.0 is completely visible, 0.0 is completely transparent.

Nothing else special is happening.

This topic is closed to new replies.

Advertisement