Magnum::Text::DistanceFieldGlyphCache class

Glyph cache with distance field rendering.

Unlike original GlyphCache converts each binary image to distance field. It is not possible to use non-binary colors with this cache, internal texture format is red channel only.

Usage

Usage is similar to GlyphCache, additionally you need to specify size of resulting distance field texture.

std::unique_ptr<Text::AbstractFont> font;
Text::DistanceFieldGlyphCache cache{Vector2i{2048}, Vector2i{384}, 16};
font->fillGlyphCache(cache, "abcdefghijklmnopqrstuvwxyz"
                            "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
                            "0123456789?!:;,. ");

Base classes

class GlyphCache
Glyph cache.

Constructors, destructors, conversion operators

DistanceFieldGlyphCache(const Vector2i& originalSize, const Vector2i& size, UnsignedInt radius) explicit
Constructor.

Public functions

void setImage(const Vector2i& offset, const ImageView2D& image) override virtual
Set cache image.
void setDistanceFieldImage(const Vector2i& offset, const ImageView2D& image)
Set distance field cache image.

Function documentation

Magnum::Text::DistanceFieldGlyphCache::DistanceFieldGlyphCache(const Vector2i& originalSize, const Vector2i& size, UnsignedInt radius) explicit

Constructor.

Parameters
originalSize Unscaled glyph cache texture size
size Actual glyph cache texture size
radius Distance field computation radius

See TextureTools::distanceField() for more information about the parameters. Sets internal texture format to red channel only. On desktop OpenGL requires ARB_texture_rg (also part of OpenGL ES 3.0), in ES2 uses EXT_texture_rg if available or GL::TextureFormat::RGB as fallback.

void Magnum::Text::DistanceFieldGlyphCache::setImage(const Vector2i& offset, const ImageView2D& image) override virtual

Set cache image.

Uploads image for one or more glyphs to given offset in original cache texture. The texture is then converted to distance field.

void Magnum::Text::DistanceFieldGlyphCache::setDistanceFieldImage(const Vector2i& offset, const ImageView2D& image)

Set distance field cache image.

Uploads already computed distance field image to given offset in distance field texture.