DEV Community

Adam Sawicki
Adam Sawicki

Posted on • Originally published at asawicki.info on

WinFontRender - my new library

Displaying text is a common problem in graphics applications where all you can do is to render textured quads. I've implemented my solution already back in 2007, as part of my old engine The Final Quest 7, which was my master thesis. I've recently come back to this code and improved it because I needed it for the personal project I now work on. Then I thought: Maybe it's a good idea to extract this code into a library? So here it is:

WinFontRender - small single-header C++ library that renders Windows fonts in graphics applications

It does two things:

  1. It renders characters of the font to a texture, tightly packed.

  1. It calculates vertices needed to render given text.

Here are more details about the library:

  • License based on MIT, so it's free to use even in a proprietary, closed-source software.
  • Standalone, single file, easy to integrate with your project.
  • Written in C++. Depends only on STL and WinAPI.
  • Agnostic to graphics API. Returns data for your texture and vertices. It is your task to display them using Direct3D, OpenGL, Vulkan or whatever you prefer. Sample application is provided for Direct3D 11.
  • Works on Windows only. Tested using Visual Studio 2017, 64-bit configuration.
  • Renders fonts installed in the system. Doesn't load custom textures or fonts from files.
  • Works with Unicode strings const wchar_t*/std::wstring.
  • Supports multiline text and automatic line break, also on whole word boundary.
  • Supports horizontal and vertical alignment to left/center/right and top/middle/bottom.
  • Supports flexible vertex formats. You can specify separate position and texture coordinate streams and custom vertex strides.
  • Supports various primitive topologies. You can request triangle list, triangle strip with primitive restart index, or triangle strip with degenerate triangles, with or without index buffer.
  • Supports kerning.
  • Fonts are antialiased and can be rendered pixel-perfect.
  • Underline and strikeout can be added.
  • Hit testing functions are available that find the character at a given point.

Top comments (2)

Collapse
 
abdurrahmaanj profile image
Abdur-Rahmaan Janhangeer

Understood nothing, maybe a tuto post?

Collapse
 
reg__ profile image
Adam Sawicki

Please take a look at library page on GitHub github.com/sawickiap/WinFontRender There you can find more detailed description and code samples. There is also complete example project with source code included in the repository.