diff options
| author | Ray <[email protected]> | 2023-03-22 11:08:46 +0100 |
|---|---|---|
| committer | Ray <[email protected]> | 2023-03-22 11:08:46 +0100 |
| commit | ecb6a6af32b4219207f9adc9635c280756dd0f57 (patch) | |
| tree | 7822c190fbc06bcdd824db0f238a19cf891a857b /src/rtext.c | |
| parent | 8b8eddc8e29ddfb679100c5acc290c065e177d42 (diff) | |
| download | raylib-ecb6a6af32b4219207f9adc9635c280756dd0f57.tar.gz raylib-ecb6a6af32b4219207f9adc9635c280756dd0f57.zip | |
Review format
Diffstat (limited to 'src/rtext.c')
| -rw-r--r-- | src/rtext.c | 12 |
1 files changed, 9 insertions, 3 deletions
diff --git a/src/rtext.c b/src/rtext.c index e8493778..2d01360e 100644 --- a/src/rtext.c +++ b/src/rtext.c @@ -695,14 +695,20 @@ Image GenImageFontAtlas(const GlyphInfo *chars, Rectangle **charRecs, int glyphC Rectangle *recs = (Rectangle *)RL_MALLOC(glyphCount*sizeof(Rectangle)); // Calculate image size based on total glyph width and glyph row count - int totalWidth = 0, maxGlyphWidth = 0; + int totalWidth = 0; + int maxGlyphWidth = 0; + for (int i = 0; i < glyphCount; i++) { if (chars[i].image.width > maxGlyphWidth) maxGlyphWidth = chars[i].image.width; totalWidth += chars[i].image.width + 2*padding; } - int rowCount = 0, imageSize = 64; // A minimum starting value to avoid unnecessary calculation steps for very small images - while (totalWidth > (imageSize - maxGlyphWidth)*rowCount) // maxGlyphWidth is maximum possible space left at the end of row + + int rowCount = 0; + int imageSize = 64; // Define minimum starting value to avoid unnecessary calculation steps for very small images + + // NOTE: maxGlyphWidth is maximum possible space left at the end of row + while (totalWidth > (imageSize - maxGlyphWidth)*rowCount) { imageSize *= 2; // Double the size of image (to keep POT) rowCount = imageSize/(fontSize + 2*padding); // Calculate new row count for the new image size |
