Jump to content
  • Advertisement
Sign in to follow this  
POLSKASH

Alpha Blending Q

This topic is 4739 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

My Pong clone is in its final stages, and I wanna add in an intro. I'm looking for the simple fade in, fade out effect of a few lines of text. I'm thinking of just using a texture that has the words I want, and then placing a solid texture over it that slowly loses its opacity and then gains it back, then the words are replaced and repeat. I'm using the ID3DXSprite interface, and I'm not sure how to do it. I remember reading in an article that the interface has the capability of doing it to the whole texture, and not just portions of it, which is what I need. I read the SDK docs and they're so vague. It's telling me to making some SetRenderState calls, but I'm not sure if this is where I should be going. Any pointers here? I'm using bitmaps by the way.

Share this post


Link to post
Share on other sites
Advertisement
I haven't used ID3DXSprite yet before, but since no one else has answered yet, I'll take a stab at explaining how the process works in general, and how I think it should work for ID3DXSprite, after browsing through the docs briefly.

You can alpha blend an entire object, without having to manipulate the texture any at all. To do so, you need to set an alpha value for the vertices. This alpha value then gets applied to whatever texture is being drawn onto the object. You're right, though, that there are some states you have to set. You have to set some Render States to enable alpha blending (D3DRS_ALPHABLENDENABLE), and tell it how to blend the new partially transparent pixel with the pixel further in the distance (D3DRS_SRCBLEND and D3DRS_DESTBLEND). You also will probably need to set up the Texture Stage States so that the D3DTSS_ALPHAOP either selects Arg1 which would be D3DTA_DIFFUSE, or make the op modulate D3DTA_DIFFUSE and D3DTA_TEXTURE.

However, I'm guessing ID3DXSprite takes care of all this for you, because in the function Begin(), one of the flag options is D3DXSPRITE_ALPHABLEND, which you'll want to use. Also, you'll probably want to include the flag D3DXSPRITE_SORT_DEPTH_BACKTOFRONT, if any of your sprites overlap each other, so that they'll be alpha-blended with each other properly. And in the Draw() call, it takes a Color parameter. Just make the high-order byte of this value contain the alpha value you want, and all the other bytes contain 0xFF. Or use one of the D3DCOLOR macros like the docs suggest, such as D3DCOLOR_ARGB(0x80, 0xFF, 0xFF, 0xFF).

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!