summaryrefslogtreecommitdiffstatshomepage
path: root/3rdparty/bgfx/examples/11-fontsdf/fontsdf.cpp
diff options
context:
space:
mode:
Diffstat (limited to '3rdparty/bgfx/examples/11-fontsdf/fontsdf.cpp')
-rw-r--r--3rdparty/bgfx/examples/11-fontsdf/fontsdf.cpp46
1 files changed, 8 insertions, 38 deletions
diff --git a/3rdparty/bgfx/examples/11-fontsdf/fontsdf.cpp b/3rdparty/bgfx/examples/11-fontsdf/fontsdf.cpp
index 37a64abb72d..61591b5d6da 100644
--- a/3rdparty/bgfx/examples/11-fontsdf/fontsdf.cpp
+++ b/3rdparty/bgfx/examples/11-fontsdf/fontsdf.cpp
@@ -18,45 +18,15 @@
#include <stdio.h>
#include <string.h>
-long int fsize(FILE* _file)
-{
- long int pos = ftell(_file);
- fseek(_file, 0L, SEEK_END);
- long int size = ftell(_file);
- fseek(_file, pos, SEEK_SET);
- return size;
-}
-
-static char* loadText(const char* _filePath)
-{
- FILE* file = fopen(_filePath, "rb");
- if (NULL != file)
- {
- uint32_t size = (uint32_t)fsize(file);
- char* mem = (char*)malloc(size+1);
- size_t ignore = fread(mem, 1, size, file);
- BX_UNUSED(ignore);
- fclose(file);
- mem[size-1] = '\0';
- return mem;
- }
-
- return NULL;
-}
-
TrueTypeHandle loadTtf(FontManager* _fm, const char* _filePath)
{
- FILE* file = fopen(_filePath, "rb");
- if (NULL != file)
+ uint32_t size;
+ void* data = load(_filePath, &size);
+
+ if (NULL != data)
{
- uint32_t size = (uint32_t)fsize(file);
- uint8_t* mem = (uint8_t*)malloc(size+1);
- size_t ignore = fread(mem, 1, size, file);
- BX_UNUSED(ignore);
- fclose(file);
- mem[size-1] = '\0';
- TrueTypeHandle handle = _fm->createTtf(mem, size);
- free(mem);
+ TrueTypeHandle handle = _fm->createTtf( (uint8_t*)data, size);
+ BX_FREE(entry::getAllocator(), data);
return handle;
}
@@ -90,7 +60,7 @@ int _main_(int _argc, char** _argv)
// Imgui.
imguiCreate();
- char* bigText = loadText( "text/sherlock_holmes_a_scandal_in_bohemia_arthur_conan_doyle.txt");
+ char* bigText = (char*)load("text/sherlock_holmes_a_scandal_in_bohemia_arthur_conan_doyle.txt");
// Init the text rendering system.
FontManager* fontManager = new FontManager(512);
@@ -267,7 +237,7 @@ int _main_(int _argc, char** _argv)
imguiDestroy();
- free(bigText);
+ BX_FREE(entry::getAllocator(), bigText);
fontManager->destroyTtf(font);
// Destroy the fonts.