Giter Site home page Giter Site logo

sometimesrain / monogamedistancefont Goto Github PK

View Code? Open in Web Editor NEW
15.0 0.0 1.0 4.59 MB

An improved font library for Monogame. Draw scalable text fast and easy!

License: MIT License

C# 91.07% HLSL 8.93%
monogame font-rendering signed-distance-field

monogamedistancefont's Introduction

A simple signed distance field font renderer for Monogame

Detailed information on usage and creating your own fonts.

Features

  • Works like a sprite font
  • Scaling without losing quality
  • Great performance
  • Outline and glow
  • Kerning and text boxes

Distance field fonts are very similar to sprite fonts. Both are drawn using a single textured quad per character. A distance field image is used instead of a texture to keep quality high even when scaled. Using distance fields should feel familiar, there's no extra hoops to jump through -- no need to render to a texture first or anything.

Scaled down Scaled up

Usage

Add DistanceField.dll as a reference to Monogame pipeline tool, and to your Monogame project. Import a BMFont file with the pipeline tool and load it like any other resource. The BMFont file should be in the same folder with a distance field image that has the same file name.

//Load like any other pipeline resource
Font font = Content.Load<Font>("Arial");

...

//Draw text
font.DrawString("Hello Monogame!", Color.Black, new Vector2(20, 20), 12);

For more detailed information on usage, please see the documentation.

Future plans

Instead of importing BMFont files and distance field images generated by an external tool, it would be great to able to import a TrueType/OpenType file and have the importer generate a distance field image and required metadata. This would make the project truly standalone. However getting that to work is quite involved.

The steps needed to create this type of importer:

  • Loading glyph outlines from a .ttf/.otf file.
  • Being able to actually render characters.
  • Finding a font size that allows all characters to fit using square packing.
  • Generating a distance field. Has to be done at a higher quality then scaled down.

Parsing font files and rendering glyphs can be outsourced to a library, but I have not been able to find a font library that does high quality distance field rendering as well.

monogamedistancefont's People

Contributors

sometimesrain avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Forkers

zhaoguohao

monogamedistancefont's Issues

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.