Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

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?

Posted

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

My VB.NET Game Programming Tutorial Site (GDI+, Direct3D, Tetris [coming soon], a full RPG.... you name it!)

vbprogramming.8k.com

My Project (Need VB.NET Programmers)

http://workspaces.gotdotnet.com/ResolutionRPG

Posted

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?

Posted
You have to first set both textures and then only call DrawSubset once.

How do you setup both textures? Do you render them to a same surface

first?

Posted
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?

Posted (edited)
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. Edited by Kavan
Posted

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?

Posted

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.

Posted

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.

Posted
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.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...