Book Image

Lua Game Development Cookbook

By : Mario Kasuba, Mário Kašuba
Book Image

Lua Game Development Cookbook

By: Mario Kasuba, Mário Kašuba

Overview of this book

Table of Contents (16 chapters)
Lua Game Development Cookbook
Credits
About the Author
About the Reviewer
www.PacktPub.com
Preface
Index

Displaying the text


Text rendering if often the base part of any graphical engine. The text rendering engine can be divided into two groups:

  • The bitmap font rendering engine

  • The TrueType font rendering engine

The main difference is that bitmap fonts are usually proportional and glyph placement is quite easy as each glyph uses the same spacing and all glyphs use the texture of the same size. On the other hand, TrueType font rendering is more complex as it uses glyphs of different sizes. Each glyph has its own characteristics and you can't easily determine how much space will be taken by text.

This recipe will cover the second case with TrueType font rendering. Bitmap font rendering can be easily derived from this recipe with a few changes.

Getting ready

Before you start, make sure you have a valid font object with font information. You'll also need to apply a blending function so that the transparent parts of the glyph won't be visible. Otherwise, you will see only solid rectangles instead of characters...