Unofficial OpenGL Software Development Kit
0.5.0
|
#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< GlyphQuad > | 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. 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 | |
Font * | GenerateFont (FontSizes eSize) |
Creates a font with the given size and characteristics. More... | |
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.
codepoint | The 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. |
ptReference | The start point of the glyph. |
eRef | Defines what the Y-component of ptReference means. |
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).
text | The string of text to get the glyphs for, encoded as UTF-8. |
ptReference | The starting point for the string. Each glyph will be offset to the right. |
eRef | Defines what the Y-component of ptReference means. |
InvalidEncodingException | Thrown if text is not valid UTF-8. |
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:
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.
eSize | The requested font size. |