Corrected bug on spritefont loading

This commit is contained in:
raysan5 2015-12-03 13:44:45 +01:00
parent a6f5a0339a
commit 85908befea

View file

@ -240,20 +240,25 @@ SpriteFont LoadSpriteFont(const char *fileName)
else else
{ {
Image image = LoadImage(fileName); Image image = LoadImage(fileName);
if (image.data != NULL)
{
// Process bitmap font pixel data to get characters measures
// spriteFont chars data is filled inside the function and memory is allocated!
int numChars = ParseImageData(image, &spriteFont.charValues, &spriteFont.charRecs);
#if defined(PLATFORM_WEB) TraceLog(DEBUG, "[%s] SpriteFont data parsed correctly", fileName);
ImageToPOT(&image, MAGENTA); TraceLog(DEBUG, "[%s] SpriteFont num chars detected: %i", fileName, numChars);
#endif
// Process bitmap font pixel data to get characters measures
// spriteFont chars data is filled inside the function and memory is allocated!
int numChars = ParseImageData(image, &spriteFont.charValues, &spriteFont.charRecs);
TraceLog(DEBUG, "[%s] SpriteFont data parsed correctly", fileName); spriteFont.numChars = numChars;
TraceLog(DEBUG, "[%s] SpriteFont num chars detected: %i", fileName, numChars); spriteFont.texture = LoadTextureFromImage(image); // Convert loaded image to OpenGL texture
spriteFont.size = spriteFont.charRecs[0].height;
spriteFont.numChars = numChars; }
spriteFont.texture = LoadTextureFromImage(image); // Convert loaded image to OpenGL texture else
spriteFont.size = spriteFont.charRecs[0].height; {
TraceLog(WARNING, "[%s] SpriteFont could not be loaded, using default font", fileName, numChars);
spriteFont = GetDefaultFont();
}
UnloadImage(image); UnloadImage(image);
} }
@ -545,7 +550,9 @@ static SpriteFont LoadRBMF(const char *fileName)
if (rbmfFile == NULL) if (rbmfFile == NULL)
{ {
TraceLog(WARNING, "[%s] rBMF font file could not be opened", fileName); TraceLog(WARNING, "[%s] rBMF font file could not be opened, using default font", fileName);
spriteFont = GetDefaultFont();
} }
else else
{ {