Unofficial OpenGL Software Development Kit  0.5.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
List of all members | Public Member Functions | Friends
glutil::Font Class Reference

#include <Font.h>

The class that represents a series of glyphs as well as the information to layout a string of text.

This class contains functions to get the rendering information for a single glyph and a line of glyphs. It also has functions for inspecting properties of the font (the height of lines, width of the characters, etc).

This font will always be fixed-width. It contains characters only from the first 256 Unicode codepoints. Characters outside of this range are not available.

This font is a "bitmap" font; the glyphs are stores as images in a texture.

This class's constructors are private; you must use glutil::GenerateFont to create an instance of this class. The destructor is not private; you can (and should) call delete on this pointer.

This class contains and manages an OpenGL texture. This means that deleting this class will destroy that texture. Most important of all, you must ensure that this object does not outlive the OpenGL context that was active when glutil::GenerateFont was called.

All layout functions of this class assume the standard OpenGL coordinate system: +Y goes up and +X right. If you want to have a top-down coordinate system, you will need to adjust the glyphs manually.

Public Member Functions

GLuint GetTexture () const
 Retrieves the texture that contains the glyph images. More...
 
std::pair< GlyphQuad, bool > GetSingleGlyph (unsigned int codepoint, const glm::vec2 &ptReference, PointReference eRef=REF_BASELINE) const
 Retrieves a single glyph, given a Unicode codepoint. More...
 
std::vector< GlyphQuadLayoutLine (boost::string_ref text, const glm::vec2 &ptReference, PointReference eRef=REF_BASELINE) const
 Generates a series of GlyphQuad's from a string of text. More...
 
int GetLinePixelHeight () const
 Returns the baseline-to-baseline height of the font, in pixels.
 
int GetGlyphAdvanceWidth () const
 Returns the width of each character, in pixels. Remember: this is a fixed-width font.
 

Friends

FontGenerateFont (FontSizes eSize)
 Creates a font with the given size and characteristics. More...
 

Member Function Documentation

std::pair<GlyphQuad, bool> glutil::Font::GetSingleGlyph ( unsigned int  codepoint,
const glm::vec2 &  ptReference,
PointReference  eRef = REF_BASELINE 
) const

Retrieves a single glyph, given a Unicode codepoint.

You can use the GlyphQuad result (if present) to render the glyph at the position requested.

Parameters
codepointThe Unicode codepoint of the glyph to fetch. This must not be a control character, space character (including 0xA0, the non-breaking space), or 0xAD (the soft-hyphen). And it must be less than 256; all higher codepoints will not produce valid glyphs.
ptReferenceThe start point of the glyph.
eRefDefines what the Y-component of ptReference means.
Returns
A std::pair of GlyphQuad and a bool. If the bool is false, the glyph for the codepoint could not be found, and therefore you should not use the GlyphQuad part of the return value.
GLuint glutil::Font::GetTexture ( ) const

Retrieves the texture that contains the glyph images.

In order to render glyphs, you must bind this texture to the context and have your shader access the texture.

The texture will, after creation, use nearest filtering. If you wish to override this, you should use an OpenGL sampler object. Be advised that the texture does not have mipmaps, so performing mipmap filtering will not be useful.

std::vector<GlyphQuad> glutil::Font::LayoutLine ( boost::string_ref  text,
const glm::vec2 &  ptReference,
PointReference  eRef = REF_BASELINE 
) const

Generates a series of GlyphQuad's from a string of text.

Any codepoints in text that are not in the font (control characters, codepoings outside of Latin-1, etc) will be ignored. Spaces will use work (though obviously they won't draw anything).

Parameters
textThe string of text to get the glyphs for, encoded as UTF-8.
ptReferenceThe starting point for the string. Each glyph will be offset to the right.
eRefDefines what the Y-component of ptReference means.
Returns
An ordered set of glyphs that represent the string of text.
Exceptions
InvalidEncodingExceptionThrown if text is not valid UTF-8.

Friends And Related Function Documentation

Font* GenerateFont ( FontSizes  eSize)
friend

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:

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
eSizeThe requested font size.
Returns
The created Font.
Note
Despite this function creating a texture, this function has no dependencies on GL Image.

The documentation for this class was generated from the following file: