Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

How to draw sprite with alpha channel?

45 views
Skip to first unread message

JXL

unread,
Feb 13, 2009, 10:16:36 PM2/13/09
to
I have some bitmap objects with alpha channels (loaded from png
files). I would like to draw these images
as sprite in a window. I used the roughly the following code the
create the texture:

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.

JXL

unread,
Feb 14, 2009, 10:12:00 PM2/14/09
to

Problem solved by:
1. call sprite.Begin( SpriteFlags.AlphaBlend |
SpriteFlags.SortDepthFrontToBack);
2. Scale all z coordinators into the range [0, 1].

0 new messages