|
127 | 127 | //---------------------------------------------------------------------------------- |
128 | 128 | // Global variables |
129 | 129 | //---------------------------------------------------------------------------------- |
130 | | -extern bool isGpuReady; |
131 | 130 | #if defined(SUPPORT_DEFAULT_FONT) |
132 | 131 | // Default font provided by raylib |
133 | 132 | // NOTE: Default font is loaded on InitWindow() and disposed on CloseWindow() [module: core] |
134 | 133 | static Font defaultFont = { 0 }; |
135 | 134 | #endif |
136 | | -static int textLineSpacing = 2; // Text vertical line spacing in pixels (between lines) |
| 135 | +static int textLineSpacing = 2; // Text vertical line spacing in pixels (between lines) |
137 | 136 |
|
138 | 137 | //---------------------------------------------------------------------------------- |
139 | 138 | // Other Modules Functions Declaration (required by text) |
@@ -164,8 +163,8 @@ extern void LoadFontDefault(void) |
164 | 163 | { |
165 | 164 | #define BIT_CHECK(a,b) ((a) & (1u << (b))) |
166 | 165 |
|
167 | | - // Check to see if we have allready allocated the font for an image, and if we don't need to upload, then just return |
168 | | - if ((defaultFont.glyphs != NULL) && !isGpuReady) return; |
| 166 | + // Check to see if we have already allocated the font for an image, and if we don't need to upload, then just return |
| 167 | + if (defaultFont.glyphs != NULL) return; |
169 | 168 |
|
170 | 169 | // NOTE: Using UTF-8 encoding table for Unicode U+0000..U+00FF Basic Latin + Latin-1 Supplement |
171 | 170 | // Ref: http://www.utf8-chartable.de/unicode-utf8-table.pl |
@@ -263,17 +262,14 @@ extern void LoadFontDefault(void) |
263 | 262 | counter++; |
264 | 263 | } |
265 | 264 |
|
266 | | - if (isGpuReady) |
267 | | - { |
268 | | - defaultFont.texture = LoadTextureFromImage(imFont); |
| 265 | + defaultFont.texture = LoadTextureFromImage(imFont); |
269 | 266 |
|
270 | | - // we have already loaded the font glyph data an image, and the GPU is ready, we are done |
271 | | - // if we don't do this, we will leak memory by reallocating the glyphs and rects |
272 | | - if (defaultFont.glyphs != NULL) |
273 | | - { |
274 | | - UnloadImage(imFont); |
275 | | - return; |
276 | | - } |
| 267 | + // we have already loaded the font glyph data an image, and the GPU is ready, we are done |
| 268 | + // if we don't do this, we will leak memory by reallocating the glyphs and rects |
| 269 | + if (defaultFont.glyphs != NULL) |
| 270 | + { |
| 271 | + UnloadImage(imFont); |
| 272 | + return; |
277 | 273 | } |
278 | 274 |
|
279 | 275 | // Reconstruct charSet using charsWidth[], charsHeight, charsDivisor, glyphCount |
@@ -330,7 +326,7 @@ extern void LoadFontDefault(void) |
330 | 326 | extern void UnloadFontDefault(void) |
331 | 327 | { |
332 | 328 | for (int i = 0; i < defaultFont.glyphCount; i++) UnloadImage(defaultFont.glyphs[i].image); |
333 | | - if (isGpuReady) UnloadTexture(defaultFont.texture); |
| 329 | + UnloadTexture(defaultFont.texture); |
334 | 330 | RL_FREE(defaultFont.glyphs); |
335 | 331 | RL_FREE(defaultFont.recs); |
336 | 332 | defaultFont.glyphCount = 0; |
@@ -384,17 +380,15 @@ Font LoadFont(const char *fileName) |
384 | 380 | { |
385 | 381 | Image image = LoadImage(fileName); |
386 | 382 | if (image.data != NULL) font = LoadFontFromImage(image, MAGENTA, FONT_TTF_DEFAULT_FIRST_CHAR); |
| 383 | + else font = GetFontDefault(); |
387 | 384 | UnloadImage(image); |
388 | 385 | } |
389 | 386 |
|
390 | | - if (isGpuReady) |
| 387 | + if (font.texture.id == 0) TRACELOG(LOG_WARNING, "FONT: [%s] Failed to load font texture -> Using default font", fileName); |
| 388 | + else |
391 | 389 | { |
392 | | - if (font.texture.id == 0) TRACELOG(LOG_WARNING, "FONT: [%s] Failed to load font texture -> Using default font", fileName); |
393 | | - else |
394 | | - { |
395 | | - SetTextureFilter(font.texture, TEXTURE_FILTER_POINT); // By default, we set point filter (the best performance) |
396 | | - TRACELOG(LOG_INFO, "FONT: Data loaded successfully (%i pixel size | %i glyphs)", font.baseSize, font.glyphCount); |
397 | | - } |
| 390 | + SetTextureFilter(font.texture, TEXTURE_FILTER_POINT); // By default, we set point filter (the best performance) |
| 391 | + TRACELOG(LOG_INFO, "FONT: Data loaded successfully (%i pixel size | %i glyphs)", font.baseSize, font.glyphCount); |
398 | 392 | } |
399 | 393 |
|
400 | 394 | return font; |
@@ -515,7 +509,7 @@ Font LoadFontFromImage(Image image, Color key, int firstChar) |
515 | 509 | }; |
516 | 510 |
|
517 | 511 | // Set font with all data parsed from image |
518 | | - if (isGpuReady) font.texture = LoadTextureFromImage(fontClear); // Convert processed image to OpenGL texture |
| 512 | + font.texture = LoadTextureFromImage(fontClear); // Convert processed image to OpenGL texture |
519 | 513 | font.glyphCount = index; |
520 | 514 | font.glyphPadding = 0; |
521 | 515 |
|
@@ -584,7 +578,7 @@ Font LoadFontFromMemory(const char *fileType, const unsigned char *fileData, int |
584 | 578 | font.glyphPadding = FONT_TTF_DEFAULT_CHARS_PADDING; |
585 | 579 |
|
586 | 580 | Image atlas = GenImageFontAtlas(font.glyphs, &font.recs, font.glyphCount, font.baseSize, font.glyphPadding, 0); |
587 | | - if (isGpuReady) font.texture = LoadTextureFromImage(atlas); |
| 581 | + font.texture = LoadTextureFromImage(atlas); |
588 | 582 |
|
589 | 583 | // Update glyphs[i].image to use alpha, required to be used on ImageDrawText() |
590 | 584 | for (int i = 0; i < font.glyphCount; i++) |
@@ -1008,7 +1002,7 @@ void UnloadFont(Font font) |
1008 | 1002 | if (font.texture.id != GetFontDefault().texture.id) |
1009 | 1003 | { |
1010 | 1004 | UnloadFontData(font.glyphs, font.glyphCount); |
1011 | | - if (isGpuReady) UnloadTexture(font.texture); |
| 1005 | + UnloadTexture(font.texture); |
1012 | 1006 | RL_FREE(font.recs); |
1013 | 1007 |
|
1014 | 1008 | TRACELOGD("FONT: Unloaded font data from RAM and VRAM"); |
@@ -1339,8 +1333,7 @@ Vector2 MeasureTextEx(Font font, const char *text, float fontSize, float spacing |
1339 | 1333 | { |
1340 | 1334 | Vector2 textSize = { 0 }; |
1341 | 1335 |
|
1342 | | - if ((isGpuReady && (font.texture.id == 0)) || |
1343 | | - (text == NULL) || (text[0] == '\0')) return textSize; // Security check |
| 1336 | + if ((font.texture.id == 0) || (text == NULL) || (text[0] == '\0')) return textSize; // Security check |
1344 | 1337 |
|
1345 | 1338 | int size = TextLength(text); // Get size in bytes of text |
1346 | 1339 | int tempByteCounter = 0; // Used to count longer text line num chars |
@@ -2481,7 +2474,7 @@ static Font LoadBMFont(const char *fileName) |
2481 | 2474 |
|
2482 | 2475 | RL_FREE(imFonts); |
2483 | 2476 |
|
2484 | | - if (isGpuReady) font.texture = LoadTextureFromImage(fullFont); |
| 2477 | + font.texture = LoadTextureFromImage(fullFont); |
2485 | 2478 |
|
2486 | 2479 | // Fill font characters info data |
2487 | 2480 | font.baseSize = fontSize; |
@@ -2523,7 +2516,7 @@ static Font LoadBMFont(const char *fileName) |
2523 | 2516 | UnloadImage(fullFont); |
2524 | 2517 | UnloadFileText(fileText); |
2525 | 2518 |
|
2526 | | - if (isGpuReady && (font.texture.id == 0)) |
| 2519 | + if (font.texture.id == 0) |
2527 | 2520 | { |
2528 | 2521 | UnloadFont(font); |
2529 | 2522 | font = GetFontDefault(); |
|
0 commit comments