The Colon Case - Font Families in SFML


Slow but steady, progress is being made on my upcoming detective game, The Colon Case.  With basic character movement well behind me, the next main feature to tackle will involve examining items on the map.  Following that will be dialog with NPCs.  Both of these features will require large blocks of text to be displayed on the screen.

A while back I went on a search for fonts I could use without licensing issues.  Open Sans seems like a good choice for large amounts of text.  It comes packaged in a large family, with lots of bold and italic variations to choose from.

I'm using SFML to render my graphics, which provides core classes Font and Text used to draw text on the screen.  SFML even provides a style property that can stylize text with bold, italic, underline, or strike-through variations.  However, if your font has native bold and italic variations of its own, it might be preferable to use them directly instead of SFML's programmatic styles.

I started a Git repository where I'll be building up a library of features that sit on top of SFML.  The first feature is a simple FontFamily class, where you can indicate the base font, and optionally a bold, italic, and bold-italic variation of that same font.  The createTextWithStyle method automatically sets both the font and style properties of an SFML Text object.  Included in the repo is an example program showing the results below.


In the case of Open Sans, I definitely prefer the native bold variation, but I actually kind of prefer the way SFML renders its italic style.  The native italic font seems slightly skinnier, and its A and G characters are shaped differently.  SFML rendering retains both its size and character shape.

Leave a comment

Log in with itch.io to leave a comment.