How to clip the texture in rounded shape

為{幸葍}努か 提交于 2019-12-11 05:42:35

问题


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:


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


来源:https://stackoverflow.com/questions/1969493/how-to-clip-the-texture-in-rounded-shape

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!