• Advertisement

Archived

This topic is now archived and is closed to further replies.

Color Key is not working

This topic is 5037 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

Hello again, the following code is working properly, except for the fact that the color key is not working (all areas where it should be applied are black):
Dim t As Texture = TextureLoader.FromFile(d3dDev, "C:\tmp.bmp", 256, 256, 0, 0, Format.X8B8G8R8, Pool.Default, Microsoft.DirectX.Direct3D.Filter.Linear, Microsoft.DirectX.Direct3D.Filter.Linear, Color.FromArgb(255, 255, 255, 255).ToArgb)

d3dDev.SetTexture(0, t)

d3dDev.RenderState.AlphaBlendEnable = True
d3dDev.RenderState.DestinationBlend = Blend.InvSourceAlpha
d3dDev.RenderState.SourceBlend = Blend.SourceAlpha
Why does DX ignore the color key? [edited by - Christoph on May 9, 2004 7:00:40 AM]

Share this post


Link to post
Share on other sites
Advertisement
I''m not sure if this is it, but I had the problem and I found out that the color key number didn''t match the color number in the picture, because of diffrent resolutions or some such, try setting a color to zero and try with that, if it doesn''t work atleast you''ve eliminated that this is the problem.

Share this post


Link to post
Share on other sites
I think the problem is that the alpha value loaded when creating a texture from a 24-bit bitmap is 0 instead of 255...I could be wrong though.

Share this post


Link to post
Share on other sites
I suppose the color key itself is working, because the color on which it is applied is always presented in black. In my opinion, the alpha blending must cause some trouble...
Should I perhaps change texture states set earlier?

[edited by - Christoph on May 9, 2004 1:08:45 PM]

Share this post


Link to post
Share on other sites
Thanx, I have done this, and it kind of works, but there is still one prob: When I set these texture states

d3dDev.TextureState(0).ColorOperation = TextureOperation.Modulate
d3dDev.TextureState(0).ColorArgument1 = TextureArgument.TextureColor
d3dDev.TextureState(0).ColorArgument2 = TextureArgument.Diffuse
d3dDev.TextureState(0).AlphaOperation = TextureOperation.SelectArg2
d3dDev.TextureState(0).AlphaArgument2 = TextureArgument.Diffuse

the color key is ignored.
What should I reset after these calls so that the color key is working again?

Share this post


Link to post
Share on other sites
quote:
Original post by Christoph
d3dDev.TextureState(0).AlphaOperation = TextureOperation.SelectArg2
d3dDev.TextureState(0).AlphaArgument2 = TextureArgument.Diffuse

the color key is ignored.
What should I reset after these calls so that the color key is working again?


Well, colour keying is done via the texture, and the above code sets the alpha to come from the Diffuse colour of the vertex...



Stay Casual,

Ken
Drunken Hyena

Share this post


Link to post
Share on other sites
quote:
Original post by graphicsware
You also need to enable Alpha testing.


No you don''t. Alpha Blending and Alpha Testing are 2 different things. Alpha Testing is generally a good idea with a colour key, but is not required at all.



Stay Casual,

Ken
Drunken Hyena

Share this post


Link to post
Share on other sites
When you specify a colour key in that call to load the texture what happens is all pixel instances of that specified colour in the texture are replaced with pure transparent black.

You need to enable alpha testing to not see the transparent bits when rendering that texture.

Share this post


Link to post
Share on other sites

  • Advertisement