Transparency in C#

Ming_Lei

Freshman
Joined
May 6, 2004
Messages
41
Location
Seattle, WA
I am trying to do transparency in DirectX with C# in MS VS.
How do you set up RenderState and Alpha values for Mesh textures
to achieve this? :-\
 
Ming_Lei said:
I am trying to do transparency in DirectX with C# in MS VS.
How do you set up RenderState and Alpha values for Mesh textures
to achieve this? :-\

I don't know about meshes ... but i use Sprite class for viewing textures.
I initiate the sprite.begin function with SpriteFlags.AlphaBlend

LDV
 
Hm Im not sure of an easy way to do it

But you could use a pixel shader and a mapping texture (use the texture to store the alpha values using a grayscale) then add the transparancy in the pixel shader but this is probably a much more complicated method than your looking for.
 
Code:
        With device.TextureState(0)
            .ColorOperation = TextureOperation.Modulate
            .ColorArgument1 = TextureArgument.TextureColor
            .ColorArgument2 = TextureArgument.Diffuse
            .AlphaOperation = TextureOperation.Modulate
            .AlphaArgument1 = TextureArgument.TextureColor
            .AlphaArgument2 = TextureArgument.Diffuse
        End With

        With device.RenderState
            .AlphaBlendEnable = True
            .SourceBlend = Blend.SourceAlpha
            .DestinationBlend = Blend.InvSourceAlpha
            .AlphaTestEnable = True
            .ReferenceAlpha = &H8
            .AlphaFunction = Compare.GreaterEqual
        End With

If you set the states like this then if the texture has an alpha value stored in it, you'll get transparency.

Sorry it's in VB.NET, but I guess you can manage.
 

Thanks for the information. I will see if I can use it. Another question I
like to ask is that what do I do to divide a large texture image (BMP)
into small textures so I can map to different rectangular objects?
Which functions I should use to divide the bitmap?

- Thanks. :rolleyes:
 
Ming_Lei said:
Thanks for the information. I will see if I can use it. Another question I
like to ask is that what do I do to divide a large texture image (BMP)
into small textures so I can map to different rectangular objects?
Which functions I should use to divide the bitmap?

Device.StretchRectangle should do what you want. Load the main image into a surface. Create your smaller textures and then get their surfaces by calling GetSurfaceLevel.
 
Back
Top