Magnum::Text::GlyphCache class

Glyph cache.

Contains font glyphs prerendered into texture atlas.

Usage

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

Containers::Pointer<Text::AbstractFont> font = ;
Text::GlyphCache cache{Vector2i{512}};
font->fillGlyphCache(cache, "abcdefghijklmnopqrstuvwxyz"
                            "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
                            "0123456789?!:;,. ");

See Renderer for information about text rendering.

This class supports the GlyphCacheFeature::ImageDownload (and thus calling image()) only on desktop OpenGL, due to using GL::Texture::image(), which is not available on OpenGL ES platforms.

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 = {}) explicit
Constructor.
GlyphCache(const Vector2i& originalSize, const Vector2i& size, const Vector2i& padding) explicit
Constructor.
GlyphCache(const Vector2i& size, const Vector2i& padding = {}) explicit
Constructor.

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
size Actual glyph cache texture size
padding Padding around every glyph

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 = {}) explicit

Constructor.

Same as calling the above with originalSize and size the same.

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

Constructor.

Sets internal texture format to red channel only. On desktop OpenGL requires ARB_texture_rg (also part of OpenGL ES 3.0 and WebGL 2), on ES2 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 = {}) explicit

Constructor.

Same as calling the above with originalSize and size the same.