Customizing the Print3D function from the PVRTools package

Share on linkedin
Share on twitter
Share on facebook
Share on reddit
Share on digg
Share on email

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!

Joe Davis

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.

7 thoughts on “Customizing the Print3D function from the PVRTools package”

  1. Hi Joe,
    I have more doubt in SetTexture(), how can i define that function so it will show my new font pvr file content.
    i think that APIUpLoad4444(0, (unsigned char *)PVRTPrint3DABC_Pixels, 256, 1); is used for printing default font. so i replace this array PVRTPrint3DABC_Pixels with my new pointer variable which is pointing to new font .pvr file. but i found that no font changing.
    so can you please explain what changes i need to do for pointing new font pvr file and in SetTexture() definition.
    please reply as soon as possible.
    thanx.

    Reply
    • Hi Chirag,
      Sorry for the delay getting back to you on this issue.
      This blog post refers to PVR files with metadata which is required to render new fonts (it carries the texture atlas mapping).
      You code seems to be based on a very old SDK where the texture and the mapping was hardwired so it was not possible to be changed by the user.
      Could be possible for you to move to a more recent SDK?
      Best regards
      Carlos.

      Reply
      • adding to carlos post. our new sdk has an improved version of Print3D which is now called as UIRenderer and it has been redesigned and carries more features. The SDK comes with bunch of examples to get you started. Also it supports vulkan out of the box for windows and Android at the moment (linux support coming very soon).

        Reply
  2. Hi,
    thank you for such good information.
    Actually same application i also want to change the font. but in my source code m_Print3D.SetTextures(NULL, FRAMEBUFFER_WIDTH, FRAMEBUFFER_HEIGHT, bRotate);
    this function having only 3 parameters in my code.
    can u just tell me what are the changes for SetTextures() function.
    plz give me response as soon as possible.
    thanx in advance.

    Reply
  3. Thanks for this post, I found it very helpful.
    I do have a question. When I follow this process, the only color that shows up for any of the fonts I’ve made is black, no matter what color I pass into the Print3D() function. I’m using PVRTexTool 4.1.6 (SDK 3.5). Default fonts or fonts that shipped with the PowerVR SDK change color correctly.

    Reply

Please leave a comment below

Comment policy: We love comments and appreciate the time that readers spend to share ideas and give feedback. However, all comments are manually moderated and those deemed to be spam or solely promotional will be deleted. We respect your privacy and will not publish your personal details.

Blog Contact

If you have any enquiries regarding any of our blog posts, please contact:

United Kingdom

benny.har-even@imgtec.com
Tel: +44 (0)1923 260 511

Search by Tag

Search by Author

Related blog articles

ParticleSystem screenshot 1

Improving Particle Systems on PowerVR

This article is part of our ongoing series about the PowerVR Performance Recommendations. Today we’ll be focusing on what particle systems are and how they can affect performance, so if you’re interested, why not take a look?

Read More »

Connect

Sign up to receive the latest news and product updates from Imagination straight to your inbox.

  • This field is for validation purposes and should be left unchanged.

Subscribe to our newsletter

  • This field is for validation purposes and should be left unchanged.