What is Print3D?

Print3D is a light-weight text rendering framework included in our PowerVR Graphics SDK’s PVRTools package. As the name suggests, it can print text anywhere in 3D space, but it can also be used to render screen-aligned text.

This post will demonstrate how Print3D can be used to render custom True Type fonts in your 3D graphics applications.

It’s worth noting that this approach is only suitable for languages where the entire required character set can be easily written into one or more texture atlas offline – for example, English, Spanish & Polish. More complex languages, such as Chinese, may require run-time glyph creation to generate characters as they are needed. Languages with complex character sets are beyond the scope of this post.

The IntroducingPrint3D example

Our IntroducingPrint3D example provides an overview of the Print3D API and demonstrates how custom fonts can be used to render 2D and 3D text using OpenGL ES. For this post, we will modify this example to use a custom True Type font.

Introducing Print3DIntroducingPrint3D

Converting from True Type to PVR

First, we need to convert from the True Type format to something that can be loaded by our 3D graphics application. PVRTexTool can be used for this task (see figure below).

TexTool Create Font TextureCreate a font texture in PVRTexTool

TexTool Select TTFSelect your TTF

When the Create Font Texture dialog appears, we need to point it to the TTF file we want to convert. With this dialog, we can also configure how this font will translate into a texture atlas. For this example, a Courier New font has been selected with the same options as the default font in our SDK (see figure below). The default options are:

  1. Size: 36px
  2. Boarder: 0px
  3. Gird fitting: no
  4. Character Set: ASCII Character Set (7-bit)

TexTool Generated Texture AtlasGenerated texture atlas

Once we’ve clicked ok, a texture atlas will be generated that contains the characters from our TTF file (see figure below).

TexTool EncodeEncode the texture to A8

Next, we need to convert the atlas into an optimal deployment format. The Print3D framework expects font data to be stored as A8. Before encoding, the Vertical Flip option must be disabled. The Generate MIPMaps option should only be used if your text will be rendered in 3D, i.e. cases where there will not be a 1:1 mapping of pixels to texels.

SavePVRSave to PVR

Once the image data has been encoded to the A8 format, we can save the data to a PVR texture container file. PVRTexTool writes the texture coordinates for the atlas into the PVR file’s metadata, which enables the Print3D framework to identify characters.

Rendering my new font

Customizing Print3DPrint3D Custom font

Now that we’ve generated a PVR texture atlas from our TrueType font, we can load it into the IntroducingPrint3D Example application! This can be done with PVRTools and the Print3D framework by adding the following code to the application’s InitView() function:

CPVRTResourceFile myFont(“myFont.pvr”);

bool bRotate = PVRShellGet(prefIsRotated) && PVRShellGet(prefFullScreen);

m_Print3D.SetTextures(NULL, myFont.DataPtr(), FRAMEBUFFER_WIDTH, FRAMEBUFFER_HEIGHT, bRotate);

And that’s it! With a few easy steps, the Print3D framework can be customized to use a font that better suits your application. As also demonstrated in the Example, the Print3D framework makes it extremely easy to go further and simultaneously use as many custom fonts as you want.

For more information on the Print3D framework, please download our SDK and check out the source code and comments for IntroducingPrint3D and all of our other great Examples!

About the author: Joe Davis

Profile photo of Joe Davis

Joe Davis leads the PowerVR Graphics developer support team. He and his team support a wide variety of graphics developers including those writing games, middleware, UIs, navigation systems, operating systems and web browsers. Joe regularly attends and presents at developer conferences to help graphics developers get the most out of PowerVR GPUs. You can follow him on Twitter @joedavisdev.

View all posts by Joe Davis