opcon / QuickFont

A Modern OpenGL Font Rendering Library for OpenTK
https://github.com/opcon/QuickFont
MIT License
83 stars 25 forks source link
c-sharp cross-platform font opengl opentk rendering

QuickFont Join the chat at https://gitter.im/opcon/QuickFont Build Status Build status NuGet

A modern OpenGL text rendering library for OpenTK.

Forked from swax/QuickFont library. Original Library QFont

You can install this library via nuget.

Supported Platforms

QuickFont has been tested and runs on Windows, Linux and OSX.

The minimum supported OpenGL version is 3.0

Note the example project will need to be changed to build correctly on OSX, since by default Apple returns an OpenGL 2.1 context if a specific version is not specified.

Simply replace the Game.cs constructor with:

public Game()
    : base(800, 600, GraphicsMode.Default, "QuickFont Example", GameWindowFlags.Default, DisplayDevice.Default, 3, 2, GraphicsContextFlags.Default)

This will select an OpenGL version >= 3.2 (usually 4.1).

Changelog

Latest Release - Version 4.5

Previous Releases:

Version 4.4

Version 4.3

Version 4.2

Version 4.1

Version 4.0

Todo

Screenshot

Example

In some OnLoad() method create your QFont and your QFontDrawing

_myFont = new QFont("Fonts/HappySans.ttf", 72, new QFontBuilderConfiguration(true));
_myFont2 = new QFont("basics.qfont", new QFontBuilderConfiguration(true));
_drawing = new QFontDrawing();

Call some print methods or create Drawing primitives by themselves. Add them to the drawing.

_drawing.DrawingPrimitives.Clear();
_drawing.Print(_myFont, "text1", pos, FontAlignment.Left);

// draw with options
var textOpts = new QFontRenderOptions()
    {
    Colour = Color.FromArgb(new Color4(0.8f, 0.1f, 0.1f, 1.0f).ToArgb()),
    DropShadowActive = true
    };
SizeF size = _drawing.Print(_myFont, "text2", pos2, FontAlignment.Left, textOpts);

var dp = new QFontDrawingPrimitive(_myFont2);
size = dp.Print(text, new Vector3(bounds.X, Height - yOffset, 0), new SizeF(maxWidth, float.MaxValue), alignment);
drawing.DrawingPrimitives.Add(dp);

// after all changes do update buffer data and extend it's size if needed.
_drawing.RefreshBuffers();

Then in your draw loop do:

_drawing.ProjectionMatrix = proj;
_drawing.Draw();
SwapBuffers();

At the end of the program dispose the QuickFont resources:

protected virtual void Dispose(bool disposing)
{
    _drawing.Dispose();
    _myFont.Dispose();
    _myFont2.Dispose();
}

See the included example project for more!

Contributors

The following is a non-exhaustive list of people who have contributed to QuickFont:

James Lohr - Creator of the original library (http://www.opentk.com/project/QuickFont)

John (swax) Marshall - Added vertex buffer support

Patrick (opcon) Yates - Current maintainer

Robertofon - Refactored monolithic QFont class

Martinay - OpenGL ES 2.0 support

Jan Polak

Jonathan

License

Licensed under MIT, please see the file License.txt in the project root directory