wolfhece.opengl.glyph_atlas
SDF glyph atlas for GPU text rendering.
Renders TrueType glyphs at high resolution via PIL, computes a Signed Distance Field (SDF), and packs them into a single-channel OpenGL texture atlas. The SDF allows resolution-independent rendering with clean glow/outline effects at any zoom level.
Usage:
atlas = GlyphAtlas.get("arial.ttf") # cached singleton per font
atlas.bind(0) # bind to texture unit 0
m = atlas.get_metrics('A') # query glyph layout info
Author: HECE - University of Liege, Pierre Archambeau Date: 2026
Copyright (c) 2026 University of Liege. All rights reserved.
Module Contents
- class wolfhece.opengl.glyph_atlas.GlyphMetrics[source]
Layout metrics for a single glyph in the SDF atlas.
All spatial values are normalised so that 1.0 equals one em (i.e. the
RENDER_SIZEused during atlas construction).
- class wolfhece.opengl.glyph_atlas.GlyphAtlas(font_name: str = 'arial.ttf', charset: list[str] | None = None)[source]
SDF glyph atlas backed by a single-channel OpenGL texture.
Build once per font; the atlas is cached and reused for all rendering. The SDF encoding (0.5 = edge, >0.5 = inside, <0.5 = outside) makes it trivial to render glow, outlines, and anti-aliased text at any scale from a single texture.
- Parameters:
font_name – TrueType font file name (resolved via
wolfhece.textpillow.load_font()).charset – List of characters to include. Defaults to ASCII printable + common accented latin characters.
- _cache: dict[str, GlyphAtlas][source]
- _metrics: dict[str, GlyphMetrics][source]
- classmethod get(font_name: str = 'arial.ttf') GlyphAtlas[source]
Return a cached atlas for font_name, creating it if needed.
- static _compute_sdf(bitmap: numpy.ndarray, spread: float) numpy.ndarray[source]
Compute SDF from a greyscale bitmap.
Returns array in
[0, 1]: 0.5 = edge, >0.5 = inside, <0.5 = outside. Falls back to a simple ramp when scipy is not installed.
- get_metrics(char: str) GlyphMetrics | None[source]
Return metrics for char, or
Noneif absent from the atlas.
- property metrics: dict[str, GlyphMetrics][source]
Full metrics dictionary (read-only view).