diff options
| author | raysan5 <raysan5@gmail.com> | 2015-12-03 13:44:45 +0100 |
|---|---|---|
| committer | raysan5 <raysan5@gmail.com> | 2015-12-03 13:44:45 +0100 |
| commit | 85908befeabecf34f04b983173d73a4f80fbf4b7 (patch) | |
| tree | 273a6fd908b02ff037f630fa20492a34ee4ec02c /src | |
| parent | a6f5a0339a00840c62c0cb0519d0f8482114bd54 (diff) | |
| download | raylib-85908befeabecf34f04b983173d73a4f80fbf4b7.tar.gz raylib-85908befeabecf34f04b983173d73a4f80fbf4b7.zip | |
Corrected bug on spritefont loading
Diffstat (limited to 'src')
| -rw-r--r-- | src/text.c | 37 |
1 files changed, 22 insertions, 15 deletions
@@ -240,20 +240,25 @@ SpriteFont LoadSpriteFont(const char *fileName) else { Image image = LoadImage(fileName); - -#if defined(PLATFORM_WEB) - ImageToPOT(&image, MAGENTA); -#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); - TraceLog(DEBUG, "[%s] SpriteFont num chars detected: %i", fileName, numChars); - - spriteFont.numChars = numChars; - spriteFont.texture = LoadTextureFromImage(image); // Convert loaded image to OpenGL texture - spriteFont.size = spriteFont.charRecs[0].height; + + 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); + + TraceLog(DEBUG, "[%s] SpriteFont data parsed correctly", fileName); + TraceLog(DEBUG, "[%s] SpriteFont num chars detected: %i", fileName, numChars); + + spriteFont.numChars = numChars; + spriteFont.texture = LoadTextureFromImage(image); // Convert loaded image to OpenGL texture + spriteFont.size = spriteFont.charRecs[0].height; + } + else + { + TraceLog(WARNING, "[%s] SpriteFont could not be loaded, using default font", fileName, numChars); + spriteFont = GetDefaultFont(); + } UnloadImage(image); } @@ -545,7 +550,9 @@ static SpriteFont LoadRBMF(const char *fileName) 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 { |
