void PrepareText(TextItem item) { // If we're modified and have texture already delete it from graphics card if (item.TextureID > 0) { //GL.DeleteTexture(item.TextureID); item.TextureID = -1; } Size s; try { s = TextRenderer.MeasureText( item.Text, item.Font, MaxSize, item.Flags); } catch { return; } item.ImgWidth = s.Width; item.ImgHeight = s.Height; if (!RenderSettings.TextureNonPowerOfTwoSupported) { item.ImgWidth = RHelp.NextPow2(s.Width); item.ImgHeight = RHelp.NextPow2(s.Height); } Bitmap img = new Bitmap( item.ImgWidth, item.ImgHeight, System.Drawing.Imaging.PixelFormat.Format32bppArgb); Graphics g = Graphics.FromImage(img); g.TextRenderingHint = System.Drawing.Text.TextRenderingHint.AntiAliasGridFit; TextRenderer.DrawText( g, item.Text, item.Font, new Rectangle(0, 0, s.Width + 2, s.Height + 2), Color.White, Color.Transparent, item.Flags); item.TextureID = RHelp.GLLoadImage(img, true, false); g.Dispose(); img.Dispose(); }
public void PrepareText(int maxWidth) { if (maxWidth != widthForTextureGenerated) { string txt = item.From + item.Text; // If we're modified and have texture already delete it from graphics card if (textureID > 0) { GL.DeleteTexture(textureID); textureID = -1; } TextFormatFlags flags = TextFormatFlags.Top | TextFormatFlags.Left | TextFormatFlags.WordBreak; Size s = TextRenderer.MeasureText( txt, ChatOverlay.ChatFont, new Size(maxWidth, 2000), flags); ImgWidth = TextWidth = s.Width; ImgHeight = TextHeight = s.Height; if (!RenderSettings.TextureNonPowerOfTwoSupported) { ImgWidth = RHelp.NextPow2(TextWidth); ImgHeight = RHelp.NextPow2(TextHeight); } Bitmap img = new Bitmap( ImgWidth, ImgHeight, System.Drawing.Imaging.PixelFormat.Format32bppArgb); Graphics g = Graphics.FromImage(img); TextRenderer.DrawText( g, txt, ChatOverlay.ChatFont, new Rectangle(0, ImgHeight - TextHeight, TextWidth + 2, TextHeight + 2), Color.White, Color.Transparent, flags); widthForTextureGenerated = maxWidth; textureID = RHelp.GLLoadImage(img, true, false); g.Dispose(); img.Dispose(); } }