summaryrefslogtreecommitdiffhomepage
path: root/src
diff options
context:
space:
mode:
authorRay <[email protected]>2023-07-06 12:29:28 +0200
committerRay <[email protected]>2023-07-06 12:29:28 +0200
commit668b37e1113c653c38ce50757984b8fc074ea9b3 (patch)
treeae5243994c463e6bec70c6a37e52a080cf257b6c /src
parent4f9235f6eb51a33fd59ed69ff01e9483832998a8 (diff)
downloadraylib-668b37e1113c653c38ce50757984b8fc074ea9b3.tar.gz
raylib-668b37e1113c653c38ce50757984b8fc074ea9b3.zip
REVIEWED: `GenImageFontAtlas()`, make atlas size less conservative
Diffstat (limited to 'src')
-rw-r--r--src/rtext.c21
1 files changed, 17 insertions, 4 deletions
diff --git a/src/rtext.c b/src/rtext.c
index 396275a8..eb3ad551 100644
--- a/src/rtext.c
+++ b/src/rtext.c
@@ -699,7 +699,7 @@ Image GenImageFontAtlas(const GlyphInfo *chars, Rectangle **charRecs, int glyphC
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;
+ totalWidth += chars[i].image.width + 4*padding;
}
//#define SUPPORT_FONT_ATLAS_SIZE_CONSERVATIVE
@@ -713,15 +713,28 @@ Image GenImageFontAtlas(const GlyphInfo *chars, Rectangle **charRecs, int glyphC
imageSize *= 2; // Double the size of image (to keep POT)
rowCount = imageSize/(fontSize + 2*padding); // Calculate new row count for the new image size
}
+
+ atlas.width = imageSize; // Atlas bitmap width
+ atlas.height = imageSize; // Atlas bitmap height
#else
// No need for a so-conservative atlas generation
- float totalArea = totalWidth*fontSize*1.3f;
+ float totalArea = totalWidth*fontSize*1.2f;
float imageMinSize = sqrtf(totalArea);
int imageSize = (int)powf(2, ceilf(logf(imageMinSize)/logf(2)));
+
+ if (totalArea < ((imageSize*imageSize)/2))
+ {
+ atlas.width = imageSize; // Atlas bitmap width
+ atlas.height = imageSize/2; // Atlas bitmap height
+ }
+ else
+ {
+ atlas.width = imageSize; // Atlas bitmap width
+ atlas.height = imageSize; // Atlas bitmap height
+ }
#endif
- atlas.width = imageSize; // Atlas bitmap width
- atlas.height = imageSize; // Atlas bitmap height
+
atlas.data = (unsigned char *)RL_CALLOC(1, atlas.width*atlas.height); // Create a bitmap to store characters (8 bpp)
atlas.format = PIXELFORMAT_UNCOMPRESSED_GRAYSCALE;
atlas.mipmaps = 1;