public static TextTexture DrawTextToTexture(string text, System.Drawing.Font font, Device device, int width, int height) { Bitmap img = new Bitmap(width, height); Graphics g = Graphics.FromImage(img); SizeF tSz = g.MeasureString(text, font); int x = (int)((width - tSz.Width) / 2.0f); int y = (int)((height - tSz.Height) / 2.0f); g.DrawString(text, font, Brushes.White, x, y); TextTexture tex = new TextTexture(); tex.texture = Texture.FromBitmap(device, img, Usage.None, Pool.Managed); tex.size = new Size(width, height); g.Dispose(); img.Dispose(); return tex; }
public static TextTexture DrawTextToTexture(string text, System.Drawing.Font font, Device device, int width, int height) { Bitmap img = new Bitmap(width, height); Graphics g = Graphics.FromImage(img); SizeF tSz = g.MeasureString(text, font); int x = (int)((width - tSz.Width) / 2.0f); int y = (int)((height - tSz.Height) / 2.0f); g.DrawString(text, font, Brushes.White, x, y); TextTexture tex = new TextTexture(); tex.texture = Texture.FromBitmap(device, img, Usage.None, Pool.Managed); tex.size = new Size(width, height); g.Dispose(); img.Dispose(); return(tex); }