Guest User

Untitled

a guest
Jan 21st, 2018
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.94 KB | None | 0 0
  1.  
  2.         public static Texture2D renderText(SpriteFont font, string text, Color color)
  3.         {
  4.  
  5.             GraphicsDevice graphic_device = Game.instance.GraphicsDevice;
  6.             Vector2 text_size = font.MeasureString(text);
  7.             RenderTarget2D output_texture = new RenderTarget2D(graphic_device,1024,1024);
  8.             RenderTargetBinding[] oldTargets = graphic_device.GetRenderTargets();
  9.             graphic_device.SetRenderTarget(output_texture);
  10.             graphic_device.Clear(Color.Transparent);
  11.  
  12.             SpriteBatch spriteBatch = new SpriteBatch(graphic_device);
  13.             spriteBatch.Begin(SpriteSortMode.Immediate, BlendState.AlphaBlend, SamplerState.LinearWrap, null, null);
  14.  
  15.             spriteBatch.DrawString(font, text, Vector2.Zero, color);
  16.  
  17.             spriteBatch.End();
  18.             spriteBatch.Dispose();
  19.             graphic_device.SetRenderTargets(oldTargets);
  20.  
  21.             return output_texture;
  22.         }
Add Comment
Please, Sign In to add comment