Skip to content

A library for use with Silk.NET for easy drawing and manipulation of fonts with GL. Based off FontStash.NET and memononen/fontstash, originally intended for SilkyNvg

License

Notifications You must be signed in to change notification settings

Zekiah-A/FontStashPlus

 
 

Repository files navigation

FontStashPlus

A modernised version of FontStash.NET, that conforms to standard .NET code style practices, provides API cleanups, small optimisation and refactors.

Usage / Examples

Examples can be found in the 'samples' directory.

Creating a new context

Information about the desired font atlas and the callbacks used for rendering are stored in the FontParams struct.

var fontParams = new FontParams()
{
	// The initial dimensions of the font atlas
	Width = 512,
	Height = 512,
	// Where point (0, 0) is located on the atlas
	Flags = FontFlags.ZeroTopLeft,
	// Callbacks for creating, resizing, updating, drawing and deleting the atlas
	RenderCreate = OnCreate,
	RenderUpdate = OnUpdate,
	RenderDraw = OnDraw,
	RenderDelete = OnDelete
};

Examples for implementations of these methods can be found in either the src/FontStash.NET.GL.Legacy (for people not used to OpenGL) or src/FontStash.NET.GL (for how to render in modern OpenGL) projects.

To finally create the FontStash context and instance, do the following:

var fontManager = new FontManager(fontParams);

Now, the FontManager can be used with a similar API to that of memononen/fontstash, however, a context does not need to be passed with each call, as the context information is stored within each FontManager instance.

// Create a new font
// The last parameter should usually be set to zero when using StbTrueType font indices.
int testFontId = fontManager.CreateFont("testFont", "./fonts/verdana.ttf", 0);

// Render "I am the walrus!"
fontManager.SetFont(testFontId);
fontManager.SetSize(72.0f);
fontManager.SetColour(255, 0, 0, 255);
// FontStash.DrawText(float, float string) returns the end X-Position of the rendered string on the window.
float endX = fontManager.DrawText(20, 100, "I am the walrus!");

// Render the font atlas in it's current state
fontManager.DrawDebug(800, 200);

OpenGL utillities

When using OpenGL FontStash.NET, the same as fontstash, provids utillity classes to aid rendering. They are located in either src/FontStash.NET.GL.Legacy for legacy OpenGL and src/FontStash.NET.GL for modern OpenGL respectively. These use Silk.NET for rendering, so a compatible OpenGL object must be parsed.

// Pass in the GL context, usually created with Silk.Net's 'window.CreateOpenGL()' method
var glFont = new GLFont(gl);
FontManager fontManager = glFont.Create(512, 512, FontFlags.ZeroTopLeft);

The example seen above has the same effect as the "manual" example.

Examples

Two example projects using OpenGL can be found in 'samples' directory.

Without debug atlas displayed:
Example without Debug
With debug atlas displayed:
Example without Debug

Credits

License

FontStash.NET uses the MIT-License
fontstash uses the ZLib-License

About

A library for use with Silk.NET for easy drawing and manipulation of fonts with GL. Based off FontStash.NET and memononen/fontstash, originally intended for SilkyNvg

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • C# 100.0%