Skip to content

Expose font atlas pixels: ofTrueTypeFont::getFontAtlasPixels(), ofBitmapFont::getAtlasPixels() - #8600

Merged
danoli3 merged 1 commit into
openframeworks:masterfrom
danoli3:font-atlas-pixels
Oct 25, 2026
Merged

danoli3 merged 1 commit into
openframeworks:masterfrom
danoli3:font-atlas-pixels

Conversation

@danoli3

@danoli3 danoli3 commented Oct 25, 2026

Copy link
Copy Markdown
Member

Split out of #8577 as a small PR, as asked in review.

Both fonts build their glyph atlas as ofPixels and upload it to a texture; this keeps it reachable on the CPU:

const ofPixels & ofTrueTypeFont::getFontAtlasPixels() const; // empty until load()
const ofPixels & ofBitmapFont::getAtlasPixels() const;       // 256x256, 16x16 grid, no GL context needed

Both are OF_PIXELS_GRAY_ALPHA, the same data as getFontTexture() / getTexture(). Useful for non-GL renderers, exporting or processing glyphs, and tools; reading the texture back isn't an option, since ofTexture::readToPixels() doesn't support these GL_RG textures (it logs "image type not supported" and crashes on macOS).

  • ofTrueTypeFont: the atlas is moved into atlasPixels after upload in load() (no extra copy while loading), and copied / moved with the rest of the font in the copy and move constructors and assignments. unloadTextures() (Android GL context loss) keeps it: it's CPU memory, and reloadTextures() rebuilds it anyway. Cost: the atlas stays in memory, 2 bytes per pixel (512x512 for a 32 px font: 512 KB).
  • ofBitmapFont: returns the existing static atlas after init(), which doesn't need GL.

The Dawn / WebGPU parts of #8577 aren't included.

Tested on macOS (make, Debug) with a small app: unloaded font has no pixels; after load("vag.ttf", 32) the atlas is allocated, 512x512 like the texture, OF_PIXELS_GRAY_ALPHA, with glyph coverage; it survives copy / move construction and assignment; the bitmap atlas is 256x256 with glyphs and matches its texture size.

…mapFont::getAtlasPixels()

The glyph atlas each font builds its texture from, on the CPU
(OF_PIXELS_GRAY_ALPHA), for renderers or tools that need the glyphs
without reading a GL texture back (ofTexture::readToPixels doesn't support
these GL_RG textures).

- ofTrueTypeFont keeps the atlas after load() (moved, not copied), carries
  it through copy / move construction and assignment, and keeps it when
  textures are unloaded (Android GL context loss; reload rebuilds it)
- ofBitmapFont returns its existing static atlas (256x256, 16x16 grid),
  available without a GL context

Split out of openframeworks#8577.
@danoli3
danoli3 merged commit b2012af into openframeworks:master Oct 25, 2026
20 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant