Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

Sponzie

adjusting alpha / transparency

This topic is 5304 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

Small question about drawing a textured quad more and more transparent. The explosions in my small 2d shooter game are drawn as textured quads (the texture working through 16 different pics to make it animate). The background of these explosion textures is alpha tested out, so I have a transparent background for my explosions already. What I would like to do next, is change the opacity of the rest of the texture during the explosion animation. My question is, how do I change the opacity of a drawn texture? I know about the SetRenderState(D3DRS_ALPHABLENDENABLE, TRUE) etc, but my texture pic is a simple bmp, no alpha values there. How do I make the texture more and more transparent through the explosion animation? (is there some way to multiply/blend the texture with a transparent black or something?) thanks!

Share this post


Link to post
Share on other sites
Advertisement
All you need to do is set the alpha byte of your diffuse component on your vertices that make up the quad, assuming you have a diffuse component specified. If not, you need to add one. You might need to make sure a few other render states are set appropriately, aside from D3DRS_ALPHABLENDENABLE, but that is the main one. Other than that method, I can''t think of any other way, short of locking your texture and writing alpha values to all the pixels, but you definitely wouldn''t want to do that.

Share this post


Link to post
Share on other sites
Alright, so I add a diffuse color component to my fvf, but what color should I give it to not make a texture any darker nor brighter? The alpha value would change depending on how far I am in rendering the explosion, but how do I determine the RGB value?

Share this post


Link to post
Share on other sites
I believe if you do this:

pD3DDevice->SetTextureStageState(0, D3DTSS_COLOROP, D3DTOP_SELECTARG1);
pD3DDevice->SetTextureStageState(0, D3DTSS_COLORARG1, D3DTA_TEXTURE);
pD3DDevice->SetTextureStageState(0, D3DTSS_ALPHAOP, D3DTOP_MODULATE);
pD3DDevice->SetTextureStageState(0, D3DTSS_ALPHAARG1, D3DTA_DIFFUSE);
pD3DDevice->SetTextureStageState(0, D3DTSS_ALPHAARG2, D3DTA_TEXTURE);
then the color operation just gets the texture''s color, ignoring the diffuse setting, but the alpha operator multiplies the texture''s alpha value by the diffuse component''s alpha value. I know I''ve done this exact thing before, but I don''t have the code available to me, but I''m pretty sure this is right.

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

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

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!