using System; using System.Drawing; using OpenTK; using OpenTK.Fonts; using OpenTK.OpenGL; using OpenTK.OpenGL.Enums; namespace Example { public class TKFontTest : GameWindow { TextureFont textureFont = new TextureFont(new Font(FontFamily.GenericSerif, 24.0f)); TextHandle textHandle; ITextPrinter textPrinter = new TextPrinter(); string text = "ABCD abcd To whom it may concern:"; public TKFontTest() : base(new DisplayMode(570, 55), "TKFontTest") { } public override void OnLoad(EventArgs e) { GL.ClearColor(Color.Black); textPrinter.Prepare(text, textureFont, out textHandle); } public override void OnUnload(EventArgs e) { textHandle.Dispose(); textureFont.Dispose(); } float[] viewport = new float[6]; protected override void OnResize(OpenTK.Platform.ResizeEventArgs e) { GL.Viewport(0, 0, Width, Height); GL.GetFloat(GetPName.Viewport, viewport); GL.MatrixMode(MatrixMode.Projection); GL.LoadIdentity(); GL.Ortho(viewport[0], viewport[2], viewport[3], viewport[1], 0.0, 1.0); GL.MatrixMode(MatrixMode.Modelview); GL.LoadIdentity(); } public override void OnRenderFrame(RenderFrameEventArgs e) { GL.Clear(ClearBufferMask.ColorBufferBit); float width; float height; textureFont.MeasureString(text, out width, out height); GL.Color3(0.25f, 0.25f, 0.25f); GL.Rect(10.0f, 10, 10+width, 10 + height); textPrinter.Begin(); { GL.Color3(1.0f, 1.0f, 1.0f); GL.Translate(10.0f, 10, 0.0f); textPrinter.Draw(textHandle); } textPrinter.End(); SwapBuffers(); } [STAThread] public static void Main() { using (TKFontTest tkFontTest = new TKFontTest()) { tkFontTest.Run(30.0, 0.0); } } } }