messed something up with git running it back to an older version

This commit is contained in:
DissolveDZ 2023-09-30 19:07:05 +02:00
parent 51dff665a6
commit 5c85cbaebd

View File

@ -215,7 +215,8 @@ extern void LoadFontDefault(void)
.width = 128, .width = 128,
.height = 128, .height = 128,
.mipmaps = 1, .mipmaps = 1,
.format = PIXELFORMAT_UNCOMPRESSED_GRAY_ALPHA}; .format = PIXELFORMAT_UNCOMPRESSED_GRAY_ALPHA
};
// Fill image.data with defaultFontData (convert from bit to pixel!) // Fill image.data with defaultFontData (convert from bit to pixel!)
for (int i = 0, counter = 0; i < imFont.width*imFont.height; i += 32) for (int i = 0, counter = 0; i < imFont.width*imFont.height; i += 32)
@ -228,8 +229,7 @@ extern void LoadFontDefault(void)
// we must consider data as little-endian order (alpha + gray) // we must consider data as little-endian order (alpha + gray)
((unsigned short *)imFont.data)[i + j] = 0xffff; ((unsigned short *)imFont.data)[i + j] = 0xffff;
} }
else else ((unsigned short *)imFont.data)[i + j] = 0x00ff;
((unsigned short *)imFont.data)[i + j] = 0x00ff;
} }
counter++; counter++;
@ -269,8 +269,7 @@ extern void LoadFontDefault(void)
defaultFont.recs[i].x = (float)charsDivisor; defaultFont.recs[i].x = (float)charsDivisor;
defaultFont.recs[i].y = (float)(charsDivisor + currentLine*(charsHeight + charsDivisor)); defaultFont.recs[i].y = (float)(charsDivisor + currentLine*(charsHeight + charsDivisor));
} }
else else currentPosX = testPosX;
currentPosX = testPosX;
// NOTE: On default font character offsets and xAdvance are not required // NOTE: On default font character offsets and xAdvance are not required
defaultFont.glyphs[i].offsetX = 0; defaultFont.glyphs[i].offsetX = 0;
@ -291,8 +290,7 @@ extern void LoadFontDefault(void)
// Unload raylib default font // Unload raylib default font
extern void UnloadFontDefault(void) extern void UnloadFontDefault(void)
{ {
for (int i = 0; i < defaultFont.glyphCount; i++) for (int i = 0; i < defaultFont.glyphCount; i++) UnloadImage(defaultFont.glyphs[i].image);
UnloadImage(defaultFont.glyphs[i].image);
UnloadTexture(defaultFont.texture); UnloadTexture(defaultFont.texture);
RL_FREE(defaultFont.glyphs); RL_FREE(defaultFont.glyphs);
RL_FREE(defaultFont.recs); RL_FREE(defaultFont.recs);
@ -330,19 +328,16 @@ Font LoadFont(const char *fileName)
Font font = { 0 }; Font font = { 0 };
#if defined(SUPPORT_FILEFORMAT_TTF) #if defined(SUPPORT_FILEFORMAT_TTF)
if (IsFileExtension(fileName, ".ttf") || IsFileExtension(fileName, ".otf")) if (IsFileExtension(fileName, ".ttf") || IsFileExtension(fileName, ".otf")) font = LoadFontEx(fileName, FONT_TTF_DEFAULT_SIZE, NULL, FONT_TTF_DEFAULT_NUMCHARS);
font = LoadFontEx(fileName, FONT_TTF_DEFAULT_SIZE, NULL, FONT_TTF_DEFAULT_NUMCHARS);
else else
#endif #endif
#if defined(SUPPORT_FILEFORMAT_FNT) #if defined(SUPPORT_FILEFORMAT_FNT)
if (IsFileExtension(fileName, ".fnt")) if (IsFileExtension(fileName, ".fnt")) font = LoadBMFont(fileName);
font = LoadBMFont(fileName);
else else
#endif #endif
{ {
Image image = LoadImage(fileName); Image image = LoadImage(fileName);
if (image.data != NULL) if (image.data != NULL) font = LoadFontFromImage(image, MAGENTA, FONT_TTF_DEFAULT_FIRST_CHAR);
font = LoadFontFromImage(image, MAGENTA, FONT_TTF_DEFAULT_FIRST_CHAR);
UnloadImage(image); UnloadImage(image);
} }
@ -378,8 +373,7 @@ Font LoadFontEx(const char *fileName, int fontSize, int *codepoints, int codepoi
UnloadFileData(fileData); UnloadFileData(fileData);
} }
else else font = GetFontDefault();
font = GetFontDefault();
return font; return font;
} }
@ -413,16 +407,13 @@ Font LoadFontFromImage(Image image, Color key, int firstChar)
{ {
for (x = 0; x < image.width; x++) for (x = 0; x < image.width; x++)
{ {
if (!COLOR_EQUAL(pixels[y * image.width + x], key)) if (!COLOR_EQUAL(pixels[y*image.width + x], key)) break;
break;
} }
if (!COLOR_EQUAL(pixels[y * image.width + x], key)) if (!COLOR_EQUAL(pixels[y*image.width + x], key)) break;
break;
} }
if ((x == 0) || (y == 0)) if ((x == 0) || (y == 0)) return font;
return font;
charSpacing = x; charSpacing = x;
lineSpacing = y; lineSpacing = y;
@ -430,8 +421,7 @@ Font LoadFontFromImage(Image image, Color key, int firstChar)
int charHeight = 0; int charHeight = 0;
int j = 0; int j = 0;
while (!COLOR_EQUAL(pixels[(lineSpacing + j) * image.width + charSpacing], key)) while (!COLOR_EQUAL(pixels[(lineSpacing + j)*image.width + charSpacing], key)) j++;
j++;
charHeight = j; charHeight = j;
@ -454,8 +444,7 @@ Font LoadFontFromImage(Image image, Color key, int firstChar)
int charWidth = 0; int charWidth = 0;
while (!COLOR_EQUAL(pixels[(lineSpacing + (charHeight + lineSpacing) * lineToRead) * image.width + xPosToRead + charWidth], key)) while (!COLOR_EQUAL(pixels[(lineSpacing + (charHeight+lineSpacing)*lineToRead)*image.width + xPosToRead + charWidth], key)) charWidth++;
charWidth++;
tempCharRecs[index].width = (float)charWidth; tempCharRecs[index].width = (float)charWidth;
@ -470,9 +459,7 @@ Font LoadFontFromImage(Image image, Color key, int firstChar)
// NOTE: We need to remove key color borders from image to avoid weird // NOTE: We need to remove key color borders from image to avoid weird
// artifacts on texture scaling when using TEXTURE_FILTER_BILINEAR or TEXTURE_FILTER_TRILINEAR // artifacts on texture scaling when using TEXTURE_FILTER_BILINEAR or TEXTURE_FILTER_TRILINEAR
for (int i = 0; i < image.height * image.width; i++) for (int i = 0; i < image.height*image.width; i++) if (COLOR_EQUAL(pixels[i], key)) pixels[i] = BLANK;
if (COLOR_EQUAL(pixels[i], key))
pixels[i] = BLANK;
// Create a new image with the processed color data (key color replaced by BLANK) // Create a new image with the processed color data (key color replaced by BLANK)
Image fontClear = { Image fontClear = {
@ -480,7 +467,8 @@ Font LoadFontFromImage(Image image, Color key, int firstChar)
.width = image.width, .width = image.width,
.height = image.height, .height = image.height,
.mipmaps = 1, .mipmaps = 1,
.format = PIXELFORMAT_UNCOMPRESSED_R8G8B8A8}; .format = PIXELFORMAT_UNCOMPRESSED_R8G8B8A8
};
// Set font with all data parsed from image // Set font with all data parsed from image
font.texture = LoadTextureFromImage(fontClear); // Convert processed image to OpenGL texture font.texture = LoadTextureFromImage(fontClear); // Convert processed image to OpenGL texture
@ -550,8 +538,7 @@ Font LoadFontFromMemory(const char *fileType, const unsigned char *fileData, int
TRACELOG(LOG_INFO, "FONT: Data loaded successfully (%i pixel size | %i glyphs)", font.baseSize, font.glyphCount); TRACELOG(LOG_INFO, "FONT: Data loaded successfully (%i pixel size | %i glyphs)", font.baseSize, font.glyphCount);
} }
else else font = GetFontDefault();
font = GetFontDefault();
} }
#else #else
font = GetFontDefault(); font = GetFontDefault();
@ -621,8 +608,7 @@ GlyphInfo *LoadFontData(const unsigned char *fileData, int dataSize, int fontSiz
if (codepoints == NULL) if (codepoints == NULL)
{ {
codepoints = (int *)RL_MALLOC(codepointCount*sizeof(int)); codepoints = (int *)RL_MALLOC(codepointCount*sizeof(int));
for (int i = 0; i < codepointCount; i++) for (int i = 0; i < codepointCount; i++) codepoints[i] = i + 32;
codepoints[i] = i + 32;
genFontChars = true; genFontChars = true;
} }
@ -640,12 +626,9 @@ GlyphInfo *LoadFontData(const unsigned char *fileData, int dataSize, int fontSiz
// stbtt_GetCodepointBitmapBox() -- how big the bitmap must be // stbtt_GetCodepointBitmapBox() -- how big the bitmap must be
// stbtt_MakeCodepointBitmap() -- renders into bitmap you provide // stbtt_MakeCodepointBitmap() -- renders into bitmap you provide
if (type != FONT_SDF) if (type != FONT_SDF) chars[i].image.data = stbtt_GetCodepointBitmap(&fontInfo, scaleFactor, scaleFactor, ch, &chw, &chh, &chars[i].offsetX, &chars[i].offsetY);
chars[i].image.data = stbtt_GetCodepointBitmap(&fontInfo, scaleFactor, scaleFactor, ch, &chw, &chh, &chars[i].offsetX, &chars[i].offsetY); else if (ch != 32) chars[i].image.data = stbtt_GetCodepointSDF(&fontInfo, scaleFactor, ch, FONT_SDF_CHAR_PADDING, FONT_SDF_ON_EDGE_VALUE, FONT_SDF_PIXEL_DIST_SCALE, &chw, &chh, &chars[i].offsetX, &chars[i].offsetY);
else if (ch != 32) else chars[i].image.data = NULL;
chars[i].image.data = stbtt_GetCodepointSDF(&fontInfo, scaleFactor, ch, FONT_SDF_CHAR_PADDING, FONT_SDF_ON_EDGE_VALUE, FONT_SDF_PIXEL_DIST_SCALE, &chw, &chh, &chars[i].offsetX, &chars[i].offsetY);
else
chars[i].image.data = NULL;
stbtt_GetCodepointHMetrics(&fontInfo, ch, &chars[i].advanceX, NULL); stbtt_GetCodepointHMetrics(&fontInfo, ch, &chars[i].advanceX, NULL);
chars[i].advanceX = (int)((float)chars[i].advanceX*scaleFactor); chars[i].advanceX = (int)((float)chars[i].advanceX*scaleFactor);
@ -666,7 +649,8 @@ GlyphInfo *LoadFontData(const unsigned char *fileData, int dataSize, int fontSiz
.width = chars[i].advanceX, .width = chars[i].advanceX,
.height = fontSize, .height = fontSize,
.mipmaps = 1, .mipmaps = 1,
.format = PIXELFORMAT_UNCOMPRESSED_GRAYSCALE}; .format = PIXELFORMAT_UNCOMPRESSED_GRAYSCALE
};
chars[i].image = imSpace; chars[i].image = imSpace;
} }
@ -677,10 +661,8 @@ GlyphInfo *LoadFontData(const unsigned char *fileData, int dataSize, int fontSiz
// NOTE: For optimum results, bitmap font should be generated at base pixel size // NOTE: For optimum results, bitmap font should be generated at base pixel size
for (int p = 0; p < chw*chh; p++) for (int p = 0; p < chw*chh; p++)
{ {
if (((unsigned char *)chars[i].image.data)[p] < FONT_BITMAP_ALPHA_THRESHOLD) if (((unsigned char *)chars[i].image.data)[p] < FONT_BITMAP_ALPHA_THRESHOLD) ((unsigned char *)chars[i].image.data)[p] = 0;
((unsigned char *)chars[i].image.data)[p] = 0; else ((unsigned char *)chars[i].image.data)[p] = 255;
else
((unsigned char *)chars[i].image.data)[p] = 255;
} }
} }
@ -694,11 +676,9 @@ GlyphInfo *LoadFontData(const unsigned char *fileData, int dataSize, int fontSiz
*/ */
} }
} }
else else TRACELOG(LOG_WARNING, "FONT: Failed to process TTF font data");
TRACELOG(LOG_WARNING, "FONT: Failed to process TTF font data");
if (genFontChars) if (genFontChars) RL_FREE(codepoints);
RL_FREE(codepoints);
} }
#endif #endif
@ -732,8 +712,7 @@ Image GenImageFontAtlas(const GlyphInfo *glyphs, Rectangle **glyphRecs, int glyp
for (int i = 0; i < glyphCount; i++) for (int i = 0; i < glyphCount; i++)
{ {
if (glyphs[i].image.width > maxGlyphWidth) if (glyphs[i].image.width > maxGlyphWidth) maxGlyphWidth = glyphs[i].image.width;
maxGlyphWidth = glyphs[i].image.width;
totalWidth += glyphs[i].image.width + 4*padding; totalWidth += glyphs[i].image.width + 4*padding;
} }
@ -866,8 +845,7 @@ Image GenImageFontAtlas(const GlyphInfo *glyphs, Rectangle **glyphRecs, int glyp
} }
} }
} }
else else TRACELOG(LOG_WARNING, "FONT: Failed to package character (%i)", i);
TRACELOG(LOG_WARNING, "FONT: Failed to package character (%i)", i);
} }
RL_FREE(rects); RL_FREE(rects);
@ -912,8 +890,7 @@ void UnloadFontData(GlyphInfo *glyphs, int glyphCount)
{ {
if (glyphs != NULL) if (glyphs != NULL)
{ {
for (int i = 0; i < glyphCount; i++) for (int i = 0; i < glyphCount; i++) UnloadImage(glyphs[i].image);
UnloadImage(glyphs[i].image);
RL_FREE(glyphs); RL_FREE(glyphs);
} }
@ -975,8 +952,7 @@ bool ExportFontAsCode(Font font, const char *fileName)
// Support font export and initialization // Support font export and initialization
// NOTE: This mechanism is highly coupled to raylib // NOTE: This mechanism is highly coupled to raylib
Image image = LoadImageFromTexture(font.texture); Image image = LoadImageFromTexture(font.texture);
if (image.format != PIXELFORMAT_UNCOMPRESSED_GRAY_ALPHA) if (image.format != PIXELFORMAT_UNCOMPRESSED_GRAY_ALPHA) TRACELOG(LOG_WARNING, "Font export as code: Font image format is not GRAY+ALPHA!");
TRACELOG(LOG_WARNING, "Font export as code: Font image format is not GRAY+ALPHA!");
int imageDataSize = GetPixelDataSize(image.width, image.height, image.format); int imageDataSize = GetPixelDataSize(image.width, image.height, image.format);
// Image data is usually GRAYSCALE + ALPHA and can be reduced to GRAYSCALE // Image data is usually GRAYSCALE + ALPHA and can be reduced to GRAYSCALE
@ -997,8 +973,7 @@ bool ExportFontAsCode(Font font, const char *fileName)
byteCount += sprintf(txtData + byteCount, "// Font image pixels data compressed (DEFLATE)\n"); byteCount += sprintf(txtData + byteCount, "// Font image pixels data compressed (DEFLATE)\n");
byteCount += sprintf(txtData + byteCount, "// NOTE: Original pixel data simplified to GRAYSCALE\n"); byteCount += sprintf(txtData + byteCount, "// NOTE: Original pixel data simplified to GRAYSCALE\n");
byteCount += sprintf(txtData + byteCount, "static unsigned char fontData_%s[COMPRESSED_DATA_SIZE_FONT_%s] = { ", fileNamePascal, TextToUpper(fileNamePascal)); byteCount += sprintf(txtData + byteCount, "static unsigned char fontData_%s[COMPRESSED_DATA_SIZE_FONT_%s] = { ", fileNamePascal, TextToUpper(fileNamePascal));
for (int i = 0; i < compDataSize - 1; i++) for (int i = 0; i < compDataSize - 1; i++) byteCount += sprintf(txtData + byteCount, ((i%TEXT_BYTES_PER_LINE == 0)? "0x%02x,\n " : "0x%02x, "), compData[i]);
byteCount += sprintf(txtData + byteCount, ((i % TEXT_BYTES_PER_LINE == 0) ? "0x%02x,\n " : "0x%02x, "), compData[i]);
byteCount += sprintf(txtData + byteCount, "0x%02x };\n\n", compData[compDataSize - 1]); byteCount += sprintf(txtData + byteCount, "0x%02x };\n\n", compData[compDataSize - 1]);
RL_FREE(compData); RL_FREE(compData);
#else #else
@ -1006,8 +981,7 @@ bool ExportFontAsCode(Font font, const char *fileName)
byteCount += sprintf(txtData + byteCount, "// Font image pixels data\n"); byteCount += sprintf(txtData + byteCount, "// Font image pixels data\n");
byteCount += sprintf(txtData + byteCount, "// NOTE: 2 bytes per pixel, GRAY + ALPHA channels\n"); byteCount += sprintf(txtData + byteCount, "// NOTE: 2 bytes per pixel, GRAY + ALPHA channels\n");
byteCount += sprintf(txtData + byteCount, "static unsigned char fontImageData_%s[%i] = { ", fileNamePascal, imageDataSize); byteCount += sprintf(txtData + byteCount, "static unsigned char fontImageData_%s[%i] = { ", fileNamePascal, imageDataSize);
for (int i = 0; i < imageDataSize - 1; i++) for (int i = 0; i < imageDataSize - 1; i++) byteCount += sprintf(txtData + byteCount, ((i%TEXT_BYTES_PER_LINE == 0)? "0x%02x,\n " : "0x%02x, "), ((unsigned char *)imFont.data)[i]);
byteCount += sprintf(txtData + byteCount, ((i % TEXT_BYTES_PER_LINE == 0) ? "0x%02x,\n " : "0x%02x, "), ((unsigned char *)imFont.data)[i]);
byteCount += sprintf(txtData + byteCount, "0x%02x };\n\n", ((unsigned char *)imFont.data)[imageDataSize - 1]); byteCount += sprintf(txtData + byteCount, "0x%02x };\n\n", ((unsigned char *)imFont.data)[imageDataSize - 1]);
#endif #endif
@ -1084,14 +1058,13 @@ bool ExportFontAsCode(Font font, const char *fileName)
RL_FREE(txtData); RL_FREE(txtData);
if (success != 0) if (success != 0) TRACELOG(LOG_INFO, "FILEIO: [%s] Font as code exported successfully", fileName);
TRACELOG(LOG_INFO, "FILEIO: [%s] Font as code exported successfully", fileName); else TRACELOG(LOG_WARNING, "FILEIO: [%s] Failed to export font as code", fileName);
else
TRACELOG(LOG_WARNING, "FILEIO: [%s] Failed to export font as code", fileName);
return success; return success;
} }
// Draw current FPS // Draw current FPS
// NOTE: Uses default font // NOTE: Uses default font
void DrawFPS(int posX, int posY) void DrawFPS(int posX, int posY)
@ -1099,10 +1072,8 @@ void DrawFPS(int posX, int posY)
Color color = LIME; // Good FPS Color color = LIME; // Good FPS
int fps = GetFPS(); int fps = GetFPS();
if ((fps < 30) && (fps >= 15)) if ((fps < 30) && (fps >= 15)) color = ORANGE; // Warning FPS
color = ORANGE; // Warning FPS else if (fps < 15) color = RED; // Low FPS
else if (fps < 15)
color = RED; // Low FPS
DrawText(TextFormat("%2i FPS", fps), posX, posY, 20, color); DrawText(TextFormat("%2i FPS", fps), posX, posY, 20, color);
} }
@ -1118,8 +1089,7 @@ void DrawText(const char *text, int posX, int posY, int fontSize, Color color)
Vector2 position = { (float)posX, (float)posY }; Vector2 position = { (float)posX, (float)posY };
int defaultFontSize = 10; // Default Font chars height in pixel int defaultFontSize = 10; // Default Font chars height in pixel
if (fontSize < defaultFontSize) if (fontSize < defaultFontSize) fontSize = defaultFontSize;
fontSize = defaultFontSize;
int spacing = fontSize/defaultFontSize; int spacing = fontSize/defaultFontSize;
DrawTextEx(GetFontDefault(), text, position, (float)fontSize, (float)spacing, color); DrawTextEx(GetFontDefault(), text, position, (float)fontSize, (float)spacing, color);
@ -1130,8 +1100,7 @@ void DrawText(const char *text, int posX, int posY, int fontSize, Color color)
// NOTE: chars spacing is NOT proportional to fontSize // NOTE: chars spacing is NOT proportional to fontSize
void DrawTextEx(Font font, const char *text, Vector2 position, float fontSize, float spacing, Color tint) void DrawTextEx(Font font, const char *text, Vector2 position, float fontSize, float spacing, Color tint)
{ {
if (font.texture.id == 0) if (font.texture.id == 0) font = GetFontDefault(); // Security check in case of not valid font
font = GetFontDefault(); // Security check in case of not valid font
int size = TextLength(text); // Total size in bytes of the text, scanned by codepoints in loop int size = TextLength(text); // Total size in bytes of the text, scanned by codepoints in loop
@ -1160,10 +1129,8 @@ void DrawTextEx(Font font, const char *text, Vector2 position, float fontSize, f
DrawTextCodepoint(font, codepoint, (Vector2){ position.x + textOffsetX, position.y + textOffsetY }, fontSize, tint); DrawTextCodepoint(font, codepoint, (Vector2){ position.x + textOffsetX, position.y + textOffsetY }, fontSize, tint);
} }
if (font.glyphs[index].advanceX == 0) if (font.glyphs[index].advanceX == 0) textOffsetX += ((float)font.recs[index].width*scaleFactor + spacing);
textOffsetX += ((float)font.recs[index].width * scaleFactor + spacing); else textOffsetX += ((float)font.glyphs[index].advanceX*scaleFactor + spacing);
else
textOffsetX += ((float)font.glyphs[index].advanceX * scaleFactor + spacing);
} }
i += codepointByteCount; // Move text bytes counter to next codepoint i += codepointByteCount; // Move text bytes counter to next codepoint
@ -1233,10 +1200,8 @@ void DrawTextCodepoints(Font font, const int *codepoints, int codepointCount, Ve
DrawTextCodepoint(font, codepoints[i], (Vector2){ position.x + textOffsetX, position.y + textOffsetY }, fontSize, tint); DrawTextCodepoint(font, codepoints[i], (Vector2){ position.x + textOffsetX, position.y + textOffsetY }, fontSize, tint);
} }
if (font.glyphs[index].advanceX == 0) if (font.glyphs[index].advanceX == 0) textOffsetX += ((float)font.recs[index].width*scaleFactor + spacing);
textOffsetX += ((float)font.recs[index].width * scaleFactor + spacing); else textOffsetX += ((float)font.glyphs[index].advanceX*scaleFactor + spacing);
else
textOffsetX += ((float)font.glyphs[index].advanceX * scaleFactor + spacing);
} }
} }
} }
@ -1256,8 +1221,7 @@ int MeasureText(const char *text, int fontSize)
if (GetFontDefault().texture.id != 0) if (GetFontDefault().texture.id != 0)
{ {
int defaultFontSize = 10; // Default Font chars height in pixel int defaultFontSize = 10; // Default Font chars height in pixel
if (fontSize < defaultFontSize) if (fontSize < defaultFontSize) fontSize = defaultFontSize;
fontSize = defaultFontSize;
int spacing = fontSize/defaultFontSize; int spacing = fontSize/defaultFontSize;
textSize = MeasureTextEx(GetFontDefault(), text, (float)fontSize, (float)spacing); textSize = MeasureTextEx(GetFontDefault(), text, (float)fontSize, (float)spacing);
@ -1271,8 +1235,7 @@ Vector2 MeasureTextEx(Font font, const char *text, float fontSize, float spacing
{ {
Vector2 textSize = { 0 }; Vector2 textSize = { 0 };
if ((font.texture.id == 0) || (text == NULL)) if ((font.texture.id == 0) || (text == NULL)) return textSize;
return textSize;
int size = TextLength(text); // Get size in bytes of text int size = TextLength(text); // Get size in bytes of text
int tempByteCounter = 0; // Used to count longer text line num chars int tempByteCounter = 0; // Used to count longer text line num chars
@ -1299,15 +1262,12 @@ Vector2 MeasureTextEx(Font font, const char *text, float fontSize, float spacing
if (letter != '\n') if (letter != '\n')
{ {
if (font.glyphs[index].advanceX != 0) if (font.glyphs[index].advanceX != 0) textWidth += font.glyphs[index].advanceX;
textWidth += font.glyphs[index].advanceX; else textWidth += (font.recs[index].width + font.glyphs[index].offsetX);
else
textWidth += (font.recs[index].width + font.glyphs[index].offsetX);
} }
else else
{ {
if (tempTextWidth < textWidth) if (tempTextWidth < textWidth) tempTextWidth = textWidth;
tempTextWidth = textWidth;
byteCounter = 0; byteCounter = 0;
textWidth = 0; textWidth = 0;
@ -1315,12 +1275,10 @@ Vector2 MeasureTextEx(Font font, const char *text, float fontSize, float spacing
textHeight += (float)textLineSpacing; textHeight += (float)textLineSpacing;
} }
if (tempByteCounter < byteCounter) if (tempByteCounter < byteCounter) tempByteCounter = byteCounter;
tempByteCounter = byteCounter;
} }
if (tempTextWidth < textWidth) if (tempTextWidth < textWidth) tempTextWidth = textWidth;
tempTextWidth = textWidth;
textSize.x = tempTextWidth*scaleFactor + (float)((tempByteCounter - 1)*spacing); textSize.x = tempTextWidth*scaleFactor + (float)((tempByteCounter - 1)*spacing);
textSize.y = textHeight*scaleFactor; textSize.y = textHeight*scaleFactor;
@ -1341,8 +1299,7 @@ int GetGlyphIndex(Font font, int codepoint)
// Look for character index in the unordered charset // Look for character index in the unordered charset
for (int i = 0; i < font.glyphCount; i++) for (int i = 0; i < font.glyphCount; i++)
{ {
if (font.glyphs[i].value == 63) if (font.glyphs[i].value == 63) fallbackIndex = i;
fallbackIndex = i;
if (font.glyphs[i].value == codepoint) if (font.glyphs[i].value == codepoint)
{ {
@ -1351,8 +1308,7 @@ int GetGlyphIndex(Font font, int codepoint)
} }
} }
if ((index == 0) && (font.glyphs[0].value != codepoint)) if ((index == 0) && (font.glyphs[0].value != codepoint)) index = fallbackIndex;
index = fallbackIndex;
#else #else
index = codepoint - 32; index = codepoint - 32;
#endif #endif
@ -1388,44 +1344,40 @@ Rectangle GetGlyphAtlasRec(Font font, int codepoint)
// Get text length in bytes, check for \0 character // Get text length in bytes, check for \0 character
unsigned int TextLength(const char *text) unsigned int TextLength(const char *text)
{ {
if (!text) unsigned int length = 0; //strlen(text)
return 0;
// use strlen since it uses vector operations if (text != NULL)
unsigned int length = strlen(text); {
while (*text++) length++;
}
return length; return length;
} }
// Formatting of text with variables to 'embed' // Formatting of text with variables to 'embed'
const char *TextFormat(const char *format, ...) // WARNING: String returned will expire after this function is called MAX_TEXTFORMAT_BUFFERS times
const char *TextFormat(const char *text, ...)
{ {
#ifndef MAX_TEXTFORMAT_BUFFERS
#define MAX_TEXTFORMAT_BUFFERS 4 // Maximum number of static buffers for text formatting
#endif
// We create an array of buffers so strings don't expire until MAX_TEXTFORMAT_BUFFERS invocations
static char buffers[MAX_TEXTFORMAT_BUFFERS][MAX_TEXT_BUFFER_LENGTH] = { 0 };
static int index = 0;
char *currentBuffer = buffers[index];
memset(currentBuffer, 0, MAX_TEXT_BUFFER_LENGTH); // Clear buffer before using
va_list args; va_list args;
va_start(args, format); va_start(args, text);
vsnprintf(currentBuffer, MAX_TEXT_BUFFER_LENGTH, text, args);
int length = vsnprintf(NULL, 0, format, args); // Determine the length of the formatted string
if (length < 0)
{
// Handle error
va_end(args);
return NULL;
}
char *result = (char *)malloc(length + 1); // Allocate memory for the formatted string (+1 for null terminator)
if (result == NULL)
{
// Handle memory allocation failure
va_end(args);
return NULL;
}
va_end(args); // Reset the va_list
va_start(args, format); // Start again for the actual formatting
vsnprintf(result, length + 1, format, args); // Format the string and copy it to the result buffer
va_end(args); va_end(args);
return result; index += 1; // Move to next buffer for next function call
if (index >= MAX_TEXTFORMAT_BUFFERS) index = 0;
return currentBuffer;
} }
// Get integer value from text // Get integer value from text
@ -1437,13 +1389,11 @@ int TextToInteger(const char *text)
if ((text[0] == '+') || (text[0] == '-')) if ((text[0] == '+') || (text[0] == '-'))
{ {
if (text[0] == '-') if (text[0] == '-') sign = -1;
sign = -1;
text++; text++;
} }
for (int i = 0; ((text[i] >= '0') && (text[i] <= '9')); i++) for (int i = 0; ((text[i] >= '0') && (text[i] <= '9')); i++) value = value*10 + (int)(text[i] - '0');
value = value * 10 + (int)(text[i] - '0');
return value*sign; return value*sign;
} }
@ -1477,8 +1427,10 @@ bool TextIsEqual(const char *text1, const char *text2)
{ {
bool result = false; bool result = false;
if (text1 && text2 && !strcmp(text1, text2)) if ((text1 != NULL) && (text2 != NULL))
result = true; {
if (strcmp(text1, text2) == 0) result = true;
}
return result; return result;
} }
@ -1486,8 +1438,8 @@ bool TextIsEqual(const char *text1, const char *text2)
// Get a piece of a text string // Get a piece of a text string
const char *TextSubtext(const char *text, int position, int length) const char *TextSubtext(const char *text, int position, int length)
{ {
if (!length || !text) static char buffer[MAX_TEXT_BUFFER_LENGTH] = { 0 };
return ""; memset(buffer, 0, MAX_TEXT_BUFFER_LENGTH);
int textLength = TextLength(text); int textLength = TextLength(text);
@ -1497,12 +1449,15 @@ const char *TextSubtext(const char *text, int position, int length)
length = 0; length = 0;
} }
if (length > textLength) if (length >= textLength) length = textLength;
length = textLength;
char *buffer = malloc(length + 1); for (int c = 0 ; c < length ; c++)
memcpy(buffer, text + position, length); {
buffer[length] = '\0'; *(buffer + c) = *(text + position);
text++;
}
*(buffer + length) = '\0';
return buffer; return buffer;
} }
@ -1513,8 +1468,7 @@ const char *TextSubtext(const char *text, int position, int length)
char *TextReplace(char *text, const char *replace, const char *by) char *TextReplace(char *text, const char *replace, const char *by)
{ {
// Sanity checks and initialization // Sanity checks and initialization
if (!text || !replace || !by) if (!text || !replace || !by) return NULL;
return NULL;
char *result = NULL; char *result = NULL;
@ -1526,21 +1480,18 @@ char *TextReplace(char *text, const char *replace, const char *by)
int count = 0; // Number of replacements int count = 0; // Number of replacements
replaceLen = TextLength(replace); replaceLen = TextLength(replace);
if (replaceLen == 0) if (replaceLen == 0) return NULL; // Empty replace causes infinite loop during count
return NULL; // Empty replace causes infinite loop during count
byLen = TextLength(by); byLen = TextLength(by);
// Count the number of replacements needed // Count the number of replacements needed
insertPoint = text; insertPoint = text;
for (count = 0; (temp = strstr(insertPoint, replace)); count++) for (count = 0; (temp = strstr(insertPoint, replace)); count++) insertPoint = temp + replaceLen;
insertPoint = temp + replaceLen;
// Allocate returning string and point temp to it // Allocate returning string and point temp to it
temp = result = (char *)RL_MALLOC(TextLength(text) + (byLen - replaceLen)*count + 1); temp = result = (char *)RL_MALLOC(TextLength(text) + (byLen - replaceLen)*count + 1);
if (!result) if (!result) return NULL; // Memory could not be allocated
return NULL; // Memory could not be allocated
// First time through the loop, all the variable are set correctly from here on, // First time through the loop, all the variable are set correctly from here on,
// - 'temp' points to the end of the result string // - 'temp' points to the end of the result string
@ -1570,12 +1521,9 @@ char *TextInsert(const char *text, const char *insert, int position)
char *result = (char *)RL_MALLOC(textLen + insertLen + 1); char *result = (char *)RL_MALLOC(textLen + insertLen + 1);
for (int i = 0; i < position; i++) for (int i = 0; i < position; i++) result[i] = text[i];
result[i] = text[i]; for (int i = position; i < insertLen + position; i++) result[i] = insert[i];
for (int i = position; i < insertLen + position; i++) for (int i = (insertLen + position); i < (textLen + insertLen); i++) result[i] = text[i];
result[i] = insert[i];
for (int i = (insertLen + position); i < (textLen + insertLen); i++)
result[i] = text[i];
result[textLen + insertLen] = '\0'; // Make sure text string is valid! result[textLen + insertLen] = '\0'; // Make sure text string is valid!
@ -1641,16 +1589,14 @@ const char **TextSplit(const char *text, char delimiter, int *count)
for (int i = 0; i < MAX_TEXT_BUFFER_LENGTH; i++) for (int i = 0; i < MAX_TEXT_BUFFER_LENGTH; i++)
{ {
buffer[i] = text[i]; buffer[i] = text[i];
if (buffer[i] == '\0') if (buffer[i] == '\0') break;
break;
else if (buffer[i] == delimiter) else if (buffer[i] == delimiter)
{ {
buffer[i] = '\0'; // Set an end of string at this point buffer[i] = '\0'; // Set an end of string at this point
result[counter] = buffer + i + 1; result[counter] = buffer + i + 1;
counter++; counter++;
if (counter == MAX_TEXTSPLIT_COUNT) if (counter == MAX_TEXTSPLIT_COUNT) break;
break;
} }
} }
} }
@ -1675,8 +1621,7 @@ int TextFindIndex(const char *text, const char *find)
char *ptr = strstr(text, find); char *ptr = strstr(text, find);
if (ptr != NULL) if (ptr != NULL) position = (int)(ptr - text);
position = (int)(ptr - text);
return position; return position;
} }
@ -1693,10 +1638,8 @@ const char *TextToUpper(const char *text)
{ {
for (int i = 0; (i < MAX_TEXT_BUFFER_LENGTH - 1) && (text[i] != '\0'); i++) for (int i = 0; (i < MAX_TEXT_BUFFER_LENGTH - 1) && (text[i] != '\0'); i++)
{ {
if ((text[i] >= 'a') && (text[i] <= 'z')) if ((text[i] >= 'a') && (text[i] <= 'z')) buffer[i] = text[i] - 32;
buffer[i] = text[i] - 32; else buffer[i] = text[i];
else
buffer[i] = text[i];
} }
} }
@ -1714,10 +1657,8 @@ const char *TextToLower(const char *text)
{ {
for (int i = 0; (i < MAX_TEXT_BUFFER_LENGTH - 1) && (text[i] != '\0'); i++) for (int i = 0; (i < MAX_TEXT_BUFFER_LENGTH - 1) && (text[i] != '\0'); i++)
{ {
if ((text[i] >= 'A') && (text[i] <= 'Z')) if ((text[i] >= 'A') && (text[i] <= 'Z')) buffer[i] = text[i] + 32;
buffer[i] = text[i] + 32; else buffer[i] = text[i];
else
buffer[i] = text[i];
} }
} }
@ -1734,21 +1675,17 @@ const char *TextToPascal(const char *text)
if (text != NULL) if (text != NULL)
{ {
// Upper case first character // Upper case first character
if ((text[0] >= 'a') && (text[0] <= 'z')) if ((text[0] >= 'a') && (text[0] <= 'z')) buffer[0] = text[0] - 32;
buffer[0] = text[0] - 32; else buffer[0] = text[0];
else
buffer[0] = text[0];
// Check for next separator to upper case another character // Check for next separator to upper case another character
for (int i = 1, j = 1; (i < MAX_TEXT_BUFFER_LENGTH - 1) && (text[j] != '\0'); i++, j++) for (int i = 1, j = 1; (i < MAX_TEXT_BUFFER_LENGTH - 1) && (text[j] != '\0'); i++, j++)
{ {
if (text[j] != '_') if (text[j] != '_') buffer[i] = text[j];
buffer[i] = text[j];
else else
{ {
j++; j++;
if ((text[j] >= 'a') && (text[j] <= 'z')) if ((text[j] >= 'a') && (text[j] <= 'z')) buffer[i] = text[j] - 32;
buffer[i] = text[j] - 32;
} }
} }
} }
@ -1777,8 +1714,7 @@ char *LoadUTF8(const int *codepoints, int length)
// Resize memory to text length + string NULL terminator // Resize memory to text length + string NULL terminator
void *ptr = RL_REALLOC(text, size + 1); void *ptr = RL_REALLOC(text, size + 1);
if (ptr != NULL) if (ptr != NULL) text = (char *)ptr;
text = (char *)ptr;
return text; return text;
} }
@ -1808,8 +1744,7 @@ int *LoadCodepoints(const char *text, int *count)
// Re-allocate buffer to the actual number of codepoints loaded // Re-allocate buffer to the actual number of codepoints loaded
int *temp = (int *)RL_REALLOC(codepoints, codepointCount*sizeof(int)); int *temp = (int *)RL_REALLOC(codepoints, codepointCount*sizeof(int));
if (temp != NULL) if (temp != NULL) codepoints = temp;
codepoints = temp;
*count = codepointCount; *count = codepointCount;
@ -1918,11 +1853,7 @@ int GetCodepoint(const char *text, int *codepointSize)
// [0]xC2-DF [1]UTF8-tail(x80-BF) // [0]xC2-DF [1]UTF8-tail(x80-BF)
unsigned char octet1 = text[1]; unsigned char octet1 = text[1];
if ((octet1 == '\0') || ((octet1 >> 6) != 2)) if ((octet1 == '\0') || ((octet1 >> 6) != 2)) { *codepointSize = 2; return codepoint; } // Unexpected sequence
{
*codepointSize = 2;
return codepoint;
} // Unexpected sequence
if ((octet >= 0xc2) && (octet <= 0xdf)) if ((octet >= 0xc2) && (octet <= 0xdf))
{ {
@ -1936,19 +1867,11 @@ int GetCodepoint(const char *text, int *codepointSize)
unsigned char octet1 = text[1]; unsigned char octet1 = text[1];
unsigned char octet2 = '\0'; unsigned char octet2 = '\0';
if ((octet1 == '\0') || ((octet1 >> 6) != 2)) if ((octet1 == '\0') || ((octet1 >> 6) != 2)) { *codepointSize = 2; return codepoint; } // Unexpected sequence
{
*codepointSize = 2;
return codepoint;
} // Unexpected sequence
octet2 = text[2]; octet2 = text[2];
if ((octet2 == '\0') || ((octet2 >> 6) != 2)) if ((octet2 == '\0') || ((octet2 >> 6) != 2)) { *codepointSize = 3; return codepoint; } // Unexpected sequence
{
*codepointSize = 3;
return codepoint;
} // Unexpected sequence
// [0]xE0 [1]xA0-BF [2]UTF8-tail(x80-BF) // [0]xE0 [1]xA0-BF [2]UTF8-tail(x80-BF)
// [0]xE1-EC [1]UTF8-tail [2]UTF8-tail(x80-BF) // [0]xE1-EC [1]UTF8-tail [2]UTF8-tail(x80-BF)
@ -1956,11 +1879,7 @@ int GetCodepoint(const char *text, int *codepointSize)
// [0]xEE-EF [1]UTF8-tail [2]UTF8-tail(x80-BF) // [0]xEE-EF [1]UTF8-tail [2]UTF8-tail(x80-BF)
if (((octet == 0xe0) && !((octet1 >= 0xa0) && (octet1 <= 0xbf))) || if (((octet == 0xe0) && !((octet1 >= 0xa0) && (octet1 <= 0xbf))) ||
((octet == 0xed) && !((octet1 >= 0x80) && (octet1 <= 0x9f)))) ((octet == 0xed) && !((octet1 >= 0x80) && (octet1 <= 0x9f)))) { *codepointSize = 2; return codepoint; }
{
*codepointSize = 2;
return codepoint;
}
if ((octet >= 0xe0) && (octet <= 0xef)) if ((octet >= 0xe0) && (octet <= 0xef))
{ {
@ -1971,45 +1890,28 @@ int GetCodepoint(const char *text, int *codepointSize)
else if ((octet & 0xf8) == 0xf0) else if ((octet & 0xf8) == 0xf0)
{ {
// Four octets // Four octets
if (octet > 0xf4) if (octet > 0xf4) return codepoint;
return codepoint;
unsigned char octet1 = text[1]; unsigned char octet1 = text[1];
unsigned char octet2 = '\0'; unsigned char octet2 = '\0';
unsigned char octet3 = '\0'; unsigned char octet3 = '\0';
if ((octet1 == '\0') || ((octet1 >> 6) != 2)) if ((octet1 == '\0') || ((octet1 >> 6) != 2)) { *codepointSize = 2; return codepoint; } // Unexpected sequence
{
*codepointSize = 2;
return codepoint;
} // Unexpected sequence
octet2 = text[2]; octet2 = text[2];
if ((octet2 == '\0') || ((octet2 >> 6) != 2)) if ((octet2 == '\0') || ((octet2 >> 6) != 2)) { *codepointSize = 3; return codepoint; } // Unexpected sequence
{
*codepointSize = 3;
return codepoint;
} // Unexpected sequence
octet3 = text[3]; octet3 = text[3];
if ((octet3 == '\0') || ((octet3 >> 6) != 2)) if ((octet3 == '\0') || ((octet3 >> 6) != 2)) { *codepointSize = 4; return codepoint; } // Unexpected sequence
{
*codepointSize = 4;
return codepoint;
} // Unexpected sequence
// [0]xF0 [1]x90-BF [2]UTF8-tail [3]UTF8-tail // [0]xF0 [1]x90-BF [2]UTF8-tail [3]UTF8-tail
// [0]xF1-F3 [1]UTF8-tail [2]UTF8-tail [3]UTF8-tail // [0]xF1-F3 [1]UTF8-tail [2]UTF8-tail [3]UTF8-tail
// [0]xF4 [1]x80-8F [2]UTF8-tail [3]UTF8-tail // [0]xF4 [1]x80-8F [2]UTF8-tail [3]UTF8-tail
if (((octet == 0xf0) && !((octet1 >= 0x90) && (octet1 <= 0xbf))) || if (((octet == 0xf0) && !((octet1 >= 0x90) && (octet1 <= 0xbf))) ||
((octet == 0xf4) && !((octet1 >= 0x80) && (octet1 <= 0x8f)))) ((octet == 0xf4) && !((octet1 >= 0x80) && (octet1 <= 0x8f)))) { *codepointSize = 2; return codepoint; } // Unexpected sequence
{
*codepointSize = 2;
return codepoint;
} // Unexpected sequence
if (octet >= 0xf0) if (octet >= 0xf0)
{ {
@ -2018,8 +1920,7 @@ int GetCodepoint(const char *text, int *codepointSize)
} }
} }
if (codepoint > 0x10ffff) if (codepoint > 0x10ffff) codepoint = 0x3f; // Codepoints after U+10ffff are invalid
codepoint = 0x3f; // Codepoints after U+10ffff are invalid
return codepoint; return codepoint;
} }
@ -2035,30 +1936,21 @@ int GetCodepointNext(const char *text, int *codepointSize)
if (0xf0 == (0xf8 & ptr[0])) if (0xf0 == (0xf8 & ptr[0]))
{ {
// 4 byte UTF-8 codepoint // 4 byte UTF-8 codepoint
if (((ptr[1] & 0xC0) ^ 0x80) || ((ptr[2] & 0xC0) ^ 0x80) || ((ptr[3] & 0xC0) ^ 0x80)) if(((ptr[1] & 0xC0) ^ 0x80) || ((ptr[2] & 0xC0) ^ 0x80) || ((ptr[3] & 0xC0) ^ 0x80)) { return codepoint; } //10xxxxxx checks
{
return codepoint;
} // 10xxxxxx checks
codepoint = ((0x07 & ptr[0]) << 18) | ((0x3f & ptr[1]) << 12) | ((0x3f & ptr[2]) << 6) | (0x3f & ptr[3]); codepoint = ((0x07 & ptr[0]) << 18) | ((0x3f & ptr[1]) << 12) | ((0x3f & ptr[2]) << 6) | (0x3f & ptr[3]);
*codepointSize = 4; *codepointSize = 4;
} }
else if (0xe0 == (0xf0 & ptr[0])) else if (0xe0 == (0xf0 & ptr[0]))
{ {
// 3 byte UTF-8 codepoint */ // 3 byte UTF-8 codepoint */
if (((ptr[1] & 0xC0) ^ 0x80) || ((ptr[2] & 0xC0) ^ 0x80)) if(((ptr[1] & 0xC0) ^ 0x80) || ((ptr[2] & 0xC0) ^ 0x80)) { return codepoint; } //10xxxxxx checks
{
return codepoint;
} // 10xxxxxx checks
codepoint = ((0x0f & ptr[0]) << 12) | ((0x3f & ptr[1]) << 6) | (0x3f & ptr[2]); codepoint = ((0x0f & ptr[0]) << 12) | ((0x3f & ptr[1]) << 6) | (0x3f & ptr[2]);
*codepointSize = 3; *codepointSize = 3;
} }
else if (0xc0 == (0xe0 & ptr[0])) else if (0xc0 == (0xe0 & ptr[0]))
{ {
// 2 byte UTF-8 codepoint // 2 byte UTF-8 codepoint
if ((ptr[1] & 0xC0) ^ 0x80) if((ptr[1] & 0xC0) ^ 0x80) { return codepoint; } //10xxxxxx checks
{
return codepoint;
} // 10xxxxxx checks
codepoint = ((0x1f & ptr[0]) << 6) | (0x3f & ptr[1]); codepoint = ((0x1f & ptr[0]) << 6) | (0x3f & ptr[1]);
*codepointSize = 2; *codepointSize = 2;
} }
@ -2081,14 +1973,12 @@ int GetCodepointPrevious(const char *text, int *codepointSize)
*codepointSize = 0; *codepointSize = 0;
// Move to previous codepoint // Move to previous codepoint
do do ptr--;
ptr--;
while (((0x80 & ptr[0]) != 0) && ((0xc0 & ptr[0]) == 0x80)); while (((0x80 & ptr[0]) != 0) && ((0xc0 & ptr[0]) == 0x80));
codepoint = GetCodepointNext(ptr, &cpSize); codepoint = GetCodepointNext(ptr, &cpSize);
if (codepoint != 0) if (codepoint != 0) *codepointSize = cpSize;
*codepointSize = cpSize;
return codepoint; return codepoint;
} }
@ -2104,9 +1994,7 @@ int GetCodepointPrevious(const char *text, int *codepointSize)
static int GetLine(const char *origin, char *buffer, int maxLength) static int GetLine(const char *origin, char *buffer, int maxLength)
{ {
int count = 0; int count = 0;
for (; count < maxLength; count++) for (; count < maxLength; count++) if (origin[count] == '\n') break;
if (origin[count] == '\n')
break;
memcpy(buffer, origin, count); memcpy(buffer, origin, count);
return count; return count;
} }
@ -2133,8 +2021,7 @@ static Font LoadBMFont(const char *fileName)
char *fileText = LoadFileText(fileName); char *fileText = LoadFileText(fileName);
if (fileText == NULL) if (fileText == NULL) return font;
return font;
char *fileTextPtr = fileText; char *fileTextPtr = fileText;
@ -2171,8 +2058,7 @@ static Font LoadBMFont(const char *fileName)
char *lastSlash = NULL; char *lastSlash = NULL;
lastSlash = strrchr(fileName, '/'); lastSlash = strrchr(fileName, '/');
if (lastSlash == NULL) if (lastSlash == NULL) lastSlash = strrchr(fileName, '\\');
lastSlash = strrchr(fileName, '\\');
if (lastSlash != NULL) if (lastSlash != NULL)
{ {
@ -2181,8 +2067,7 @@ static Font LoadBMFont(const char *fileName)
memcpy(imPath, fileName, TextLength(fileName) - TextLength(lastSlash) + 1); memcpy(imPath, fileName, TextLength(fileName) - TextLength(lastSlash) + 1);
memcpy(imPath + TextLength(fileName) - TextLength(lastSlash) + 1, imFileName, TextLength(imFileName)); memcpy(imPath + TextLength(fileName) - TextLength(lastSlash) + 1, imFileName, TextLength(imFileName));
} }
else else imPath = imFileName;
imPath = imFileName;
TRACELOGD(" > Image loading path: %s", imPath); TRACELOGD(" > Image loading path: %s", imPath);
@ -2196,7 +2081,8 @@ static Font LoadBMFont(const char *fileName)
.width = imFont.width, .width = imFont.width,
.height = imFont.height, .height = imFont.height,
.mipmaps = 1, .mipmaps = 1,
.format = PIXELFORMAT_UNCOMPRESSED_GRAY_ALPHA}; .format = PIXELFORMAT_UNCOMPRESSED_GRAY_ALPHA
};
for (int p = 0, i = 0; p < (imFont.width*imFont.height*2); p += 2, i++) for (int p = 0, i = 0; p < (imFont.width*imFont.height*2); p += 2, i++)
{ {
@ -2210,8 +2096,7 @@ static Font LoadBMFont(const char *fileName)
font.texture = LoadTextureFromImage(imFont); font.texture = LoadTextureFromImage(imFont);
if (lastSlash != NULL) if (lastSlash != NULL) RL_FREE(imPath);
RL_FREE(imPath);
// Fill font characters info data // Fill font characters info data
font.baseSize = fontSize; font.baseSize = fontSize;
@ -2251,8 +2136,7 @@ static Font LoadBMFont(const char *fileName)
font = GetFontDefault(); font = GetFontDefault();
TRACELOG(LOG_WARNING, "FONT: [%s] Failed to load texture, reverted to default font", fileName); TRACELOG(LOG_WARNING, "FONT: [%s] Failed to load texture, reverted to default font", fileName);
} }
else else TRACELOG(LOG_INFO, "FONT: [%s] Font loaded successfully (%i glyphs)", fileName, font.glyphCount);
TRACELOG(LOG_INFO, "FONT: [%s] Font loaded successfully (%i glyphs)", fileName, font.glyphCount);
return font; return font;
} }