Transparent Texture

Ming_Lei

Freshman
Joined
May 6, 2004
Messages
41
Location
Seattle, WA
I have two textures, and I like to apply transparency in C#, so
that the pixels of images can be added to produce the final
effect. How do I set up things suchs RenderState variables,
texture formats to achieve this?
 
you'd need alphablending

before rendering:
Dev.RenderState.AlphaSourceBlend = Blend.SourceAlpha

Dev.RenderState.AlphaDestinationBlend = Blend.InvSourceAlpha

Dev.RenderState.AlphaBlendEnable = True

while creating your texture, you need to add a few other arguments to it (im doing this at the top of my head, so i dont remember exactly what it is)

dim x as color
x = Color.FromArgb(255, 255, 255, 255) 'i think this is black, - the firrst argument refers to Alpha - 255 is the highest and you're saying "make a black color which is fully opaque, transparent)

texture = textureloader.fromfile ("texture.bmp",width,height,filter,filter,yourtransparentcolor.toArgb)

there may be more arguments but i donht remember exactly,

pent

(oh yeah the code i pasted was vb, it should be easy to do the same in C#:) )

edit: oh yeah be sure to disable alphablending when you're done drawing the objects that should be transparent
 
Blend Textures

How do you blend two textures together. I have following codes
to draw a mesh subset with two textures. And I have se the state
variables as said.

device.SetTexture(0,texture1;
PieceMesh.mesh.DrawSubset(i);
device.SetTexture(0,texture2);
PieceMesh.mesh.DrawSubset(i);

But I can't have the textures blended correctly.
What is the problem?
 
Kavan said:
device.SetTexture(0,texture1);
device.SetTexture(1,texture2);
PieceMesh.mesh.DrawSubset(i);

How do you set the alpha channel for blending in the texture?
Do you use a paint program to set to a uniformed color?
 
I usually use a picture format that already has an alpha layer like tga or png. If you need colorkeying just do as ThePentiumGuy suggested.
 
Last edited:
Same problem

I have setup the following lines in C#:
device.RenderState.SourceBlend = Blend.SourceAlpha;
device.RenderState.DestinationBlend = Blend.InvSourceAlpha;
....
device.SetTexture(0,stex);
device.SetTexture(1,stex2);
PieceMesh.mesh.DrawSubset(i);

But I still can't get transparency. What's the problem?
 
Do you set the texture states? Something like:

device.TextureState(1).ColorArgument1 = TextureArgument.Current
device.TextureState(1).ColorArgument2 = TextureArgument.TextureColor
device.TextureState(1).ColorOperation = TextureOperation.Modulate
device.SamplerState(1).MagFilter = TextureFilter.Linear
device.SamplerState(1).MinFilter = TextureFilter.Linear

Maybe you'll also have to set AlphaOperation.
 
In Visual C#, I have set the stage variables as such:

device.RenderState.SourceBlend = Blend.SourceAlpha;
device.RenderState.DestinationBlend = Blend.InvSourceAlpha;
device.RenderState.AlphaBlendEnable = true;
device.TextureState[0].TextureCoordinateIndex = 0;
device.TextureState[0].ColorArgument1 = TextureArgument.TextureColor;
device.TextureState[0].ColorArgument2 = TextureArgument.Diffuse;
device.TextureState[0].ColorOperation = TextureOperation.Modulate;
device.SamplerState[0].MagFilter = TextureFilter.Linear;
device.SamplerState[0].MinFilter = TextureFilter.Linear;
device.TextureState[1].TextureCoordinateIndex = 1;
device.TextureState[1].ColorOperation = TextureOperation.Modulate;
device.TextureState[1].ColorArgument1 = TextureArgument.TextureColor;
device.TextureState[1].ColorArgument2 = TextureArgument.Current;
device.SamplerState[1].MagFilter = TextureFilter.Linear;
device.SamplerState[1].MinFilter = TextureFilter.Linear;

But I still can't get transparency. Is there something wrong?
Thanks.
 
What kind of textures do you use? Perhaps it would be easier to track the problem if you'd post a simple project that reproduces what you're trying to do.
 
Back
Top