Color Key is not working

Started by
8 comments, last by Christoph 19 years, 11 months ago
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]
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.
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.

---------------------------Hello, and Welcome to some arbitrary temporal location in the space-time continuum.

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]

Colour keying is done through the alpha channel. Your texture doesn''t have one. Try using Format.A8B8G8R8.


Stay Casual,

Ken
Drunken Hyena
Stay Casual,KenDrunken Hyena
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?
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
Stay Casual,KenDrunken Hyena
You also need to enable Alpha testing.

GraphicsWare
3D Graphics & Solutions
GraphicsWare3D Graphics & Solutions
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
Stay Casual,KenDrunken Hyena
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.

This topic is closed to new replies.

Advertisement