device.RenderState.ZBufferEnable = true;
device.RenderState.SourceBlend = Blend.SourceAlpha;
device.RenderState.DestinationBlend = Blend.InvSourceAlpha;
device.RenderState.AlphaBlendEnable = true;
Texture myTexture = Texture.FromBitmap(device, myBitmap, 0,
Pool.Managed);
...
sprite = new Sprite(device);
...
sprite.Begin(SpriteFlags.AlphaBlend);
sprite.Draw(myTexture, rect, center, pos, clr);
sprite.Flush();
sprite.End();
The problem I have is that the code only interprets full transparency
or non-transparency.
Alpha values larger than certain value (about 30) will all interpreted
as non-transparency, basically black. This has the effect that the
image icons all have ugly black boundary instead of smooth boundary
with anti-alias effects.
Can anybody give me some help to address this problem?
thanks in advance.
Problem solved by:
1. call sprite.Begin( SpriteFlags.AlphaBlend |
SpriteFlags.SortDepthFrontToBack);
2. Scale all z coordinators into the range [0, 1].