Making an entire primitive transparent, dynamically [MDX]
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?
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:
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 :)
[source lang=C#]// set up blending as usualdevice.RenderState.AlphaBlendEnable = true;device.RenderState.SourceBlend = Blend.SourceAlpha;device.RenderState.DestinationBlend = Blend.InvSourceAlpha;// set up texture stage statesdevice.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 factorfloat alphaPerc = 0.25f; // alphaPerc from 0.0f to 1.0fint alpha = (int)(alphaPerc * 255.0f); // alpha from 0 to 255alpha = alpha << 24; // shift to correct position in ARGB intdevice.RenderState.TextureFactor = alpha;// render stuff here// reset stagesdevice.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 :)
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement