How to clip the texture in rounded shape

2019-08-12 07:22发布

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条回答
等我变得足够好
2楼-- · 2019-08-12 08:16

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
查看更多
登录 后发表回答