Jump to content
  • Advertisement
Sign in to follow this  
nsto119

Making an entire primitive transparent, dynamically [MDX]

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

So, say I have a triangle. How can I make the whole have the same alpha value, regardless of texture or color data? For example, if I want the triangle to be fully opaque when the mouse is over it and transparent when it's not, what do I need to do in the triangle's rendering method?

Share this post


Link to post
Share on other sites
Advertisement
You'll have to modulate the alpha from the texture or color with another alpha value to achieve this effect. There are a number of ways to do this, but the easiest is probably by using the TextureFactor, which can serve as a constant in the texture stages during rendering. The following code should modulate your texture color with the alpha you specify:

[source lang=C#]
// set up blending as usual
device.RenderState.AlphaBlendEnable = true;
device.RenderState.SourceBlend = Blend.SourceAlpha;
device.RenderState.DestinationBlend = Blend.InvSourceAlpha;

// set up texture stage states
device.TextureState[0].AlphaArgument1 = TextureArgument.TFactor;
device.TextureState[0].AlphaArgument2 = TextureArgument.TextureColor;
device.TextureState[0].AlphaOperation = TextureOperation.Modulate;

// set up our global alpha as the texture factor
float alphaPerc = 0.25f; // alphaPerc from 0.0f to 1.0f
int alpha = (int)(alphaPerc * 255.0f); // alpha from 0 to 255
alpha = alpha << 24; // shift to correct position in ARGB int
device.RenderState.TextureFactor = alpha;

// render stuff here

// reset stages
device.RenderState.AlphaBlendEnable = false;
device.TextureState[0].AlphaOperation = TextureOperation.SelectArg2;





I pieced it together form some other code I had lying around, so it might not work out of the box. Still, it should give you an idea of how this can be done, I hope :)

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!