Magnum::Text::GlyphCache class

Glyph cache.

Contains font glyphs rendered into a texture atlas.

Usage

Create the GlyphCache object with sufficient size and then call AbstractFont::createGlyphCache() to fill it with glyphs.

Containers::Pointer<Text::AbstractFont> font = ;
font->openFile("font.ttf", 12.0f);

Text::GlyphCache cache{Vector2i{128}};
font->fillGlyphCache(cache, "abcdefghijklmnopqrstuvwxyz"
                            "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
                            "0123456789?!:;,. ");

See the Renderer class for information about text rendering. The AbstractGlyphCache base class has more information about general glyph cache usage.

Base classes

class AbstractGlyphCache new in 2019.10
Base for glyph caches.

Derived classes

class DistanceFieldGlyphCache
Glyph cache with distance field rendering.

Constructors, destructors, conversion operators

GlyphCache(GL::TextureFormat internalFormat, const Vector2i& originalSize, const Vector2i& size, const Vector2i& padding) explicit
Constructor.
GlyphCache(GL::TextureFormat internalFormat, const Vector2i& size, const Vector2i& padding = Vector2i{1}) explicit
Constructor.
GlyphCache(const Vector2i& originalSize, const Vector2i& size, const Vector2i& padding) explicit
Constructor.
GlyphCache(const Vector2i& size, const Vector2i& padding = Vector2i{1}) explicit
Constructor.
GlyphCache(NoCreateT) explicit noexcept new in Git master
Construct without creating the internal state and the OpenGL texture object.

Public functions

auto texture() -> GL::Texture2D&
Cache texture.

Function documentation

Magnum::Text::GlyphCache::GlyphCache(GL::TextureFormat internalFormat, const Vector2i& originalSize, const Vector2i& size, const Vector2i& padding) explicit

Constructor.

Parameters
internalFormat Internal texture format
originalSize Unscaled glyph cache texture size in pixels
size Actual glyph cache texture size in pixels
padding Padding around every glyph in pixels

All glyphs parameters are saved relative to originalSize, although the actual glyph cache texture has size. Glyph padding can be used to account for e.g. glyph shadows.

Magnum::Text::GlyphCache::GlyphCache(GL::TextureFormat internalFormat, const Vector2i& size, const Vector2i& padding = Vector2i{1}) explicit

Constructor.

Same as calling the above with originalSize and size being set to the same value. See Glyph padding for more information about the default padding.

Magnum::Text::GlyphCache::GlyphCache(const Vector2i& originalSize, const Vector2i& size, const Vector2i& padding) explicit

Constructor.

Sets the internal texture format to single-channel. On OpenGL ES 3.0+ and WebGL 2 uses GL::TextureFormat::R8. On desktop OpenGL requires ARB_texture_rg (also part of OpenGL 3.0). On ES2 and WebGL 1 unconditionally uses GL::TextureFormat::Luminance. This is done for consistency with GL::pixelFormat(), which unconditionally returns GL::PixelFormat::Luminance for PixelFormat::R8Unorm. See GlyphCache(GL::TextureFormat, const Vector2i&, const Vector2i&) for an alternative.

Magnum::Text::GlyphCache::GlyphCache(const Vector2i& size, const Vector2i& padding = Vector2i{1}) explicit

Constructor.

Same as calling the above with originalSize and size being set to the same value. See Glyph padding for more information about the default padding.

Magnum::Text::GlyphCache::GlyphCache(NoCreateT) explicit noexcept new in Git master

Construct without creating the internal state and the OpenGL texture object.

The constructed instance is equivalent to moved-from state, i.e. no APIs can be safely called on the object. Useful in cases where you will overwrite the instance later anyway. Move another object over it to make it useful.

This function can be safely used for constructing (and later destructing) objects even without any OpenGL context being active. However note that this is a low-level and a potentially dangerous API, see the documentation of NoCreate for alternatives.