OpenTK builtin font

Has there been any thought of a native "OpenTK-font"? Maybe fixed-width and super-builtin? Maybe even simpler to use than the general fonts of OpenTK? I'm imagining something like

TKFont.DrawAt(0, 1, "Welcome to OpenTK 0.9.3!"); // 0,1 means top-left corner of screen
double ystep = TKFont.Height; // static property: uses current screen height
TKFont.DrawAt(0,1-ystep, "This is one line down.");

Could become a part of the "feel" of OpenTK, given a visually slick font at least ;).

Would be mostly a debug-facility for the game developer, something to get the game up-and-running / debuggeable quick. English ASCII-letters will go far given this limited context. Also, given this limited context, performance is not essential (eg. could even use GDI+ / Windows.Forms-Graphics to draw in the GLControl case..)


Comments

Re: OpenTK builtin font
posted by the Fiddler

TextureFont font = new TextureFont(...);
TextPrinter printer = new TextPrinter();
...
printer.Begin();
    printer.Print("Welcome to OpenTK 0.9.3!", font);
    GL.Translate(0, font.Height, 0);
    printer.Print("This is one line down.", font);
printer.End();

It really doesn't get any simpler than that. Note that you'd also need the "Begin"-"End" lines in your code, to set up rendering state (unless you set it on each DrawAt call, which is just too inefficient).

By the way, I've tried using GDI+ to draw text (Graphics->Bitmap->Texture->Quad), but it's not usable for realtime graphics: the fps drop from 1600 to ~90 for a 256x256 texture - ouch! The current method, which uses GDI+ to draw glyphs and caches these is much better.

If you are still not convinced, here is an implementation the above code, using OpenTK.Graphics.TextPrinter:

// copylefted code follows
// v0.0.1 - Initial release
// v0.0.2 - Fields should have been static.
public static class TKFont
{
    static TextureFont font = new TextureFont(new Font(FontFamily.Monospace, 16.0f));
    static TextPrinter printer = new TextPrinter();

    public static DrawAt(int x, int y, string text)
    {
        printer.Begin();
        GL.Translate(x, y, 0);
        printer.Print(text, font);
        printer.End();
    }

    public static int Height
    {
        return font.Height;
    }
}

You are welcome to use it, but don't complain about performance ;-)

Re: OpenTK builtin font
posted by objarni

Indeed a useful class, thanks.

You are welcome to use it, but don't complain about performance ;-)

As I stated in my initial post, performance in the debug-output context has low priority.