Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public static Texture2D renderText(SpriteFont font, string text, Color color)
- {
- GraphicsDevice graphic_device = Game.instance.GraphicsDevice;
- Vector2 text_size = font.MeasureString(text);
- RenderTarget2D output_texture = new RenderTarget2D(graphic_device,1024,1024);
- RenderTargetBinding[] oldTargets = graphic_device.GetRenderTargets();
- graphic_device.SetRenderTarget(output_texture);
- graphic_device.Clear(Color.Transparent);
- SpriteBatch spriteBatch = new SpriteBatch(graphic_device);
- spriteBatch.Begin(SpriteSortMode.Immediate, BlendState.AlphaBlend, SamplerState.LinearWrap, null, null);
- spriteBatch.DrawString(font, text, Vector2.Zero, color);
- spriteBatch.End();
- spriteBatch.Dispose();
- graphic_device.SetRenderTargets(oldTargets);
- return output_texture;
- }
Add Comment
Please, Sign In to add comment