From 0e135118fd0edd3ef613cb28cb573d12916dca98 Mon Sep 17 00:00:00 2001 From: Ray Date: Thu, 21 Jun 2018 00:18:13 +0200 Subject: [PATCH] Improved GenImageFontAtlas() --- release/include/raylib.h | 2 +- release/libs/win32/mingw32/libraylib.a | Bin 1116752 -> 1116822 bytes src/raylib.h | 2 +- src/text.c | 22 +++++++--------------- 4 files changed, 9 insertions(+), 17 deletions(-) diff --git a/release/include/raylib.h b/release/include/raylib.h index 49434d52..9a6e117f 100644 --- a/release/include/raylib.h +++ b/release/include/raylib.h @@ -965,7 +965,7 @@ RLAPI void DrawTexturePro(Texture2D texture, Rectangle sourceRec, Rectangle dest RLAPI Font GetDefaultFont(void); // Get the default Font RLAPI Font LoadFont(const char *fileName); // Load font from file into GPU memory (VRAM) RLAPI CharInfo *LoadFontData(const char *fileName, int fontSize, int *fontChars, int charsCount, bool sdf); // Load font data for further use -RLAPI Image GenImageFontAtlas(CharInfo *chars, int fontSize, int charsCount, int packing); // Generate image font atlas using chars info +RLAPI Image GenImageFontAtlas(CharInfo *chars, int fontSize, int charsCount, int padding, int packMethod); // Generate image font atlas using chars info RLAPI void UnloadFont(Font font); // Unload Font from GPU memory (VRAM) // Text drawing functions diff --git a/release/libs/win32/mingw32/libraylib.a b/release/libs/win32/mingw32/libraylib.a index 3425c71aed98130df9eb86722b3fbe3d7b4f72b3..0bf3c42129d5bf6a3700448c84bd205fcdf150d6 100644 GIT binary patch delta 5415 zcmc(j4NO$o702%z9>c)AVVD&K6)n0?7gmaIU>Ig9jVR*>endt53_1=leAsbBm~m~^ z_*{YN1V>p#E_G!WSKBmZH|k1#cD1|U2Y#d*ZE7tOx&~uyv>UgsZP|9!PS3lSxoX>_ zCDAO&&HcUqIrrRi&$&E&UTbl*?sGJ!MCW8@*|Lt0n=@R#iG-qWame51=CHT?qEByV z{}md-kcZ;@5`5($W&7e2kcU>T|CvDiHW3YF$U|{{3BK}>vVHLh$U`gF3r|2ELcffC zo#;gm`M(8BXiG&ec{mF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zmT5gBAEP!P+V?)7HL~9y8C?dVwch}uk?#Sm6=cUHozd>J0nzSs1JTZ&0HUEsfoM%! zS2W;CAez1iv|Ns7AkmvLkT1F{R5>Q4IQ4!EuIsfTzMo(cQ5Zzb+q8qm}Z6DK|Zy{7Cul)#UolF@&kDh7` z5Ixo7K(vXSJqWEwP`?39eJ7ghCPuA{IvMR{^lL^J8C_*`ozcYJXylnd^>SK9rj_-= z{xq9fCVCjX$!HLW`d!}>J&&@z(aky+4foPOx;Dtn+I0W7{gv5W%=aN;6hTzqPQ94q9icnh& zLIvRYP+m z(~QX3SnF=AZCYFI^45aEYC=wTLlaP*jl7Z+KY?hJRiKX31@77}z(Z=e3 zkR+W&U1O7XgR3FSV$R7Xg|T`v4RTz%tjv*RvE;y!x?D|e39ZPvw$@c+1kSaR(OCUt zY$mBHeHzXsvsEy&kQFdfOW&2=8fOjpgG!%5d@B6}a$BX3S7h7BNtHgGh${VfNl7S& z-KB`xQbeeI#k@l2LU~s+OzhD~wv-JsK}VJ@V>UQxcU^t`{5t4|#bPmu#c}%kI1}Xh pTF)Bq+S=+YOO6@B)zme4S4#}*C8h=o@x<%9v60?`$qD)`{{@0QjY Calculate chars area -> guess texture size? + // Calculate texture size based on required pixel area + // NOTE: Texture is forced to be squared and POT float requiredArea = 0; for (int i = 0; i < charsCount; i++) requiredArea += ((chars[i].rec.width + 2*padding)*(chars[i].rec.height + 2*padding)); float guessSize = sqrtf(requiredArea)*1.25f; @@ -423,7 +415,7 @@ Image GenImageFontAtlas(CharInfo *chars, int charsCount, int fontSize, int packi atlas.format = UNCOMPRESSED_GRAYSCALE; atlas.mipmaps = 1; - if (packing == 0) // Use basic packing algorythm + if (packMethod == 0) // Use basic packing algorythm { int offsetX = padding; int offsetY = padding; @@ -455,7 +447,7 @@ Image GenImageFontAtlas(CharInfo *chars, int charsCount, int fontSize, int packi } } } - else if (packing == 1) // Use Skyline rect packing algorythm + else if (packMethod == 1) // Use Skyline rect packing algorythm (stb_pack_rect) { stbrp_context *context = (stbrp_context *)malloc(sizeof(*context)); stbrp_node *nodes = (stbrp_node *)malloc(charsCount*sizeof(*nodes)); @@ -498,7 +490,7 @@ Image GenImageFontAtlas(CharInfo *chars, int charsCount, int fontSize, int packi } // Convert image data from GRAYSCALE to GRAY_ALPHA - //ImageAlphaMask(&atlas, atlas); // WARNING: Not working in this case, requires manual operation + // WARNING: ImageAlphaMask(&atlas, atlas) does not work in this case, requires manual operation unsigned char *dataGrayAlpha = (unsigned char *)malloc(textureSize*textureSize*sizeof(unsigned char)*2); // Two channels for (int i = 0, k = 0; i < atlas.width*atlas.height; i++, k += 2)