Created
February 22, 2015 01:16
-
-
Save axefrog/12f02e099ac80356919d to your computer and use it in GitHub Desktop.
Planning out a font atlas
This file contains 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
std::shared_ptr<FontAtlas> generateFontAtlas(int fontId, int fontSizeInPixels, int sdfPadding) | |
{ | |
/* ACTION PLAN: | |
create a new list (vector) in which to stage a set of character glyphs, each prepared in isolation | |
for each character: | |
load the character and its metrics from the font engine, using a very large font size (10 times the requested font size) | |
create a new image expanded to include padding for the distance field | |
copy the character bitmap into the centre of the image | |
render the distance field into the image | |
downsize the image | |
create a new glyph object and store the character metrics and downsized image | |
add the glyph object to the list | |
sort the list by descending image height, which will reduce the amount of space required by the atlas | |
start with a smaller atlas size which is square, with dimensions that are a power of 2 | |
do until we can fit all of the glyphs in our chosen atlas size | |
for each glyph in the list | |
copy the image into the font atlas | |
add the character metrics to the font atlas lookup table | |
if all of the glyphs fit in the atlas then | |
we're done (break) | |
else | |
double the atlas width and height and reset it to a blank image | |
*/ | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment