Ming_Lei Posted May 16, 2004 Posted May 16, 2004 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? Quote
ThePentiumGuy Posted May 17, 2004 Posted May 17, 2004 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 Quote 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
Ming_Lei Posted May 18, 2004 Author Posted May 18, 2004 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? Quote
Kavan Posted May 18, 2004 Posted May 18, 2004 You have to first set both textures and then only call DrawSubset once. Quote
Ming_Lei Posted May 19, 2004 Author Posted May 19, 2004 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? Quote
Kavan Posted May 19, 2004 Posted May 19, 2004 device.SetTexture(0,texture1); device.SetTexture(1,texture2); PieceMesh.mesh.DrawSubset(i); Quote
Ming_Lei Posted May 19, 2004 Author Posted May 19, 2004 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? Quote
Kavan Posted May 19, 2004 Posted May 19, 2004 (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 May 20, 2004 by Kavan Quote
Ming_Lei Posted May 21, 2004 Author Posted May 21, 2004 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? Quote
Kavan Posted May 21, 2004 Posted May 21, 2004 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. Quote
Ming_Lei Posted May 23, 2004 Author Posted May 23, 2004 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. Quote
Kavan Posted May 23, 2004 Posted May 23, 2004 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. Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.