views:

134

answers:

1

I need to display texture of image with the rounded shape,my code as follow

 texture = Texture.FromBitmap(device,myBitmap, Usage.RenderTarget, Pool.Default);

_sprite.Begin(SpriteFlags.SortTexture | SpriteFlags.DoNotModifyRenderState); _sprite.Draw(_allocator.Texture, Vector3.Empty, new Vector3(_objectLocation.X, _objectLocation.Y, 0), RenderingColor); _sprite.End();

But it always show rectangle texture, how can clip this texture in rounded shape.

+1  A: 

Use the alpha channel of the texture (255 is opaque, 0 is transparent and anything between the 2) and set alpha blending and alpha testing to not draw the transparent pixels.

Edit: (Try these alpha settings once you have your 4 channel texture set up).

ALPHABLENDENABLE = TRUE
SRCBLEND = SRCALPHA
DESTBLEND = INVSRCALPHA

ALPHATESTENABLE = TRUE
ALPHAREF = 192
ALPHAFUNC = GREATER
Goz