Book Image

Libgdx Cross-platform Game Development Cookbook

Book Image

Libgdx Cross-platform Game Development Cookbook

Overview of this book

Table of Contents (20 chapters)
Libgdx Cross-platform Game Development Cookbook
Credits
About the Authors
About the Reviewers
www.PacktPub.com
Preface
Index

Dynamic font effects using distance fields


Interestingly, the distance fields technique from the previous recipe can be exploited to achieve font effects dynamically, such as outlines, glows, and drop shadows. Can this technique get any more awesome?

No need to generate yet another font texture with prebaked effects; you can turn them off or on as well as tweak and tween their parameters completely at runtime. Consequently, you will be able to achieve a much richer and engaging experience. Moreover, the performance penalty is negligible—you can go crazy!

Just keep in mind that every time you set a shader on a SpriteBatch object, the latter is automatically flushed with the consequent draw call.

In this recipe, we will start off with an existing distance field font and write a configurable fragment shader to obtain outline and glow effects.

Getting ready

This time, we will use the data/fonts/pacific-distance.fnt file as well as the data/fonts/font-effects.frag and data/fonts/font-effects.vert...