Unofficial OpenGL Software Development Kit: Basic Font System

Unofficial OpenGL Software Development Kit 0.5.0

- Main Page
- Related Pages
- Modules
- Namespaces
- Classes
- Files

All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
Classes | Enumerations | Functions
Basic Font System
GL Util

##

Classes for basic font rendering.

This SDK module provides basic font rendering services. It is important to note that this is basic font rendering. This is not intended to be a serious font handling system. Therefore, you will notice that some of the amenities one might find in a more significant font system are not present.

The fonts themselves are hard-coded directly into the library. This means that the executable's size can be noticably bigger by including the font system (~500KB). However, if you never use the font system (ie: you never call glutil::GenerateFont), your executable size will be completely unaffected.

The font used here is called Inconsolata, a free font available online. The font is a fixed-width font, which makes text layout much easier. It is used here as a raster font, with several pre-defined font sizes.

This system provides limited Unicode support. Specifically, it accepts UTF-8-encoded text, but it only recognizes the first 256 Unicode codepoints. While this corresponds to Latin-1, it cannot actually take Latin-1 encoded strings; it only accepts the UTF-8 encoding. This limited Unicode support avoids complex text layout system, as well as minimizes the image storage size of the fonts.

A glutil::Font object can only be created by calling glutil::GenerateFont (which requires that GL Load has been successfully initialized). The Font class provides methods for getting size information about the font (since it is fixed-width, all of the characters have the same size characteristics). It also has a function that will layout a single string of text (horizontally), without line-breaks or anything of that nature.

More complex text layout, like paragraphs and line breaks, is beyond this system.

## Classes

class | glutil::GlyphQuad
| Data type for a single glyph. More...
class | glutil::InvalidEncodingException
| Thrown if a supposedly UTF-8 encoded string is not valid UTF-8. More...
class | glutil::Font
| The class that represents a series of glyphs as well as the information to layout a string of text. More...

## Enumerations

enum | glutil::FontSizes { glutil::FONT_SIZE_SMALL, glutil::FONT_SIZE_MEDIUM, glutil::FONT_SIZE_LARGE, glutil::FONT_SIZE_GIANT }
| The allowed sizes for fonts. More...
enum | glutil::PointReference { glutil::REF_BASELINE, glutil::REF_BOTTOM, glutil::REF_TOP }
| Defines what the vertical value of the point represents. More...

## Functions

Font * | glutil::GenerateFont (FontSizes eSize)
| Creates a font with the given size and characteristics. More...

## Enumeration Type Documentation

enum glutil::FontSizes

The allowed sizes for fonts.

The sizes are baseline-to-baseline; the actual height of a character will be smaller than this.

Enumerator
FONT_SIZE_SMALL | 10 pixels in height.
FONT_SIZE_MEDIUM | 14 pixels in height.
FONT_SIZE_LARGE | 30 pixels in height.
FONT_SIZE_GIANT | 63 pixels in height.

enum glutil::PointReference

Defines what the vertical value of the point represents.

When doing text layout, a starting point is provided. The vertical axis of this point could mean one of three possible places. It could represent the baseline point in the font, such that glyphs that hang under the baseline (commas, certain lower-case letters, etc) would modify pixels below this point. It could represent the absolute lowest point that any text could be rendered to, such that no pixels will be modified below this point. And it could represent the absolute highest point that any text could be rendered to, such that no pixels will be modified above this point.

Enumerator
REF_BASELINE | The point is the baseline.
REF_BOTTOM | The point is the bottom of the text; nothing below here will be touched.
REF_TOP | The point is the top of the text; nothing above here will be touched.

## Function Documentation

Font* glutil::GenerateFont | ( | FontSizes | eSize | ) |

Creates a font with the given size and characteristics.

This function requires an active OpenGL context.

This function allocates the Font object with new. You are responsible for deleting the Font object yourself with delete. Also, make sure that the OpenGL context is still active; it must be the same context (or one shared with it) that was active when this function was called.

Since the Font creates an OpenGL texture, calling this function will modify the following OpenGL state:

- All `GL_UNPACK_*` state.
- The current texture unit's `GL_TEXTURE_2D` target will have texture object 0 bound to it.

If ARB_texture_storage, or GL 4.2+, is available, then the texture's storage will be immutable. So don't count on being able to modify the storage (the contents can be modified, just not the storage structure itself).

Calling this function multiple times with the same parameters will create multiple copies of the same data. That is not necessary; just keep the Font object around and use it from different places.

Parameters

  eSize | The requested font size.

Returns
  The created Font.

Note
  Despite this function creating a texture, this function has no dependencies on GL Image.