Jump to content
  • Advertisement
Sign in to follow this  
jad_salloum

transparency for textures

This topic is 4301 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

hi guys i need to give trancparency for a texture drawn on a VertexBuffer so how could i do this ??? am using C# thanks alot for any help. jad

Share this post


Link to post
Share on other sites
Advertisement
You must load texture by D3DXCreateTextureFromFileEx and set ColorKey as your transparent color.

http://msdn.microsoft.com/archive/en-us/dx81_c/directx_cpp/Graphics/Reference/CPP/D3DX/Functions/Texture/D3DXCreateTextureFromFileEx.asp?frame=true

Share this post


Link to post
Share on other sites
What format are your images in? PNG and 32-bit TGAs already have alpha information so there's no need to colorkey them.

If you do want to colorkey a texture use this overload of TextureLoader.FromFile, the last argument is the colorkey. Also make sure you have alpha testing on so it actually works.

Share this post


Link to post
Share on other sites
thanks guys for ur reply , but what i need to do is give the whole texture transparency not a fixed color in it , and i don't care about the picture if it has originaly alpha in it or not but usualy it should not , like when i draw a mesh i give its material color Alpa to make it transparent so ow to do it for textures ??

Share this post


Link to post
Share on other sites
You create a texture with an alpha channel. This can be done several ways. Either you can create the texture and add an alpha channel directly using a program such as photoshop or you can use the DirectX Texture Tool to add two textures (one RGB and one grayscale) together to form a RGBA texture. When loading the texture you also need to specify a format that uses alpha channel, i.e. D3DFMT_A8R8G8B8 instead of D3DFMT_X8R8G8B8 for example...

Then for the rendering you need to enable alpha blending and set the blendstates. A common setting is:
AlphaEnable = true
SrcBlend = SrcAlpha
DestBlend = InvSrcAlpha

Maybe not exactly the correct C# names for it (Don't have the doc's on this computer) but you should get the point.

Also when rendering with transparency you should disable ZBuffer writing. You need to make sure to draw the opaque objects first and then sort the transparent ones by Z.

I'm using shaders in my app but I believe it would work fine with fixed function as well.

Hope this helps!

Share this post


Link to post
Share on other sites
Do you mean the last part about texture drawn on vertexbuffer or the part of using c#? Anyway... could you explain your problem a little more in detail?

EDIT: Sorry missed one there

[Edited by - fortia on September 11, 2006 3:36:09 PM]

Share this post


Link to post
Share on other sites
If the texture does not have alpha, then it has an implicit alpha of 1. So, in order to use any other alpha value you will need to modulate the texture color with a material color that is white, and has the alpha value you desire.

Share this post


Link to post
Share on other sites
(This is a generic reply, since I use C++, but it should apply to managed DX as well.)

If you're using the fixed function pixel pipeline (texture stages), you can use the texture factor to provide alpha for the stage (they just use a 'selectarg1 texturefactor' stage entry). The texture factor is easy to change and doesn't require any buffer changes.

If you're using pixel shaders, then just use a shader constant to provide the alpha.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!