Repository navigation
Expose font atlas pixels: ofTrueTypeFont::getFontAtlasPixels(), ofBitmapFont::getAtlasPixels() - #8600
Merged
Merged
Conversation
…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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Split out of #8577 as a small PR, as asked in review.
Both fonts build their glyph atlas as
ofPixelsand upload it to a texture; this keeps it reachable on the CPU:Both are
OF_PIXELS_GRAY_ALPHA, the same data asgetFontTexture()/getTexture(). Useful for non-GL renderers, exporting or processing glyphs, and tools; reading the texture back isn't an option, sinceofTexture::readToPixels()doesn't support theseGL_RGtextures (it logs "image type not supported" and crashes on macOS).ofTrueTypeFont: the atlas is moved intoatlasPixelsafter upload inload()(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, andreloadTextures()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 afterinit(), 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.