Commit: cf1f7a3db6e99e1f3ea05ddeffa9e8924cfe17e7
Parent: c4d55b6b374dc0307c057ec4e45dc6d3881ee2ce
Author: Randy Palamar
Date: Mon, 5 Aug 2024 15:08:46 -0600
replace gen_incs raylib code with a patch to raylib
Diffstat:
7 files changed, 267 insertions(+), 115 deletions(-)
diff --git a/.gitignore b/.gitignore
@@ -3,6 +3,4 @@ colourpicker
config.h
external/include
external/lib
-font_inc.h
gen_incs
-shader_inc.h
diff --git a/.gitmodules b/.gitmodules
@@ -1,3 +1,4 @@
[submodule "external/raylib"]
path = external/raylib
url = https://github.com/raysan5/raylib.git
+ ignore = all
diff --git a/build.sh b/build.sh
@@ -17,7 +17,8 @@ if [ "$system_raylib" ]; then
ldflags="-L/usr/local/lib $ldflags"
else
if [ ! -f external/lib/libraylib.a ]; then
- git submodule update --init --depth=1 external/raylib
+ git submodule update --init --checkout --depth=1 external/raylib
+ git -C external/raylib am --keep-non-patch --whitespace=nowarn "$PWD"/external/*.patch
cmake --install-prefix="${PWD}/external" \
-G "Ninja" -B external/raylib/build -S external/raylib \
-D CMAKE_INSTALL_LIBDIR=lib -D CMAKE_BUILD_TYPE="Release" \
@@ -31,9 +32,10 @@ fi
[ ! -s "config.h" ] && cp config.def.h config.h
-if [ ! -e "shader_inc.h" ] || [ "hsv_lerp.glsl" -nt "shader_inc.h" ]; then
+if [ ! -e "external/include/shader_inc.h" ] || [ "hsv_lerp.glsl" -nt "external/include/shader_inc.h" ]; then
${cc} $cflags -o gen_incs gen_incs.c $ldflags
./gen_incs
+ mv lora_sb*.h external/include/
fi
if [ "$debug" ]; then
diff --git a/external/0001-rtext-add-ExportFontAsCodeEx.patch b/external/0001-rtext-add-ExportFontAsCodeEx.patch
@@ -0,0 +1,253 @@
+From a466c6cf1f47620aa6ecdea19636c561879e9649 Mon Sep 17 00:00:00 2001
+From: Randy Palamar <randy@rnpnr.xyz>
+Date: Mon, 5 Aug 2024 12:07:33 -0600
+Subject: [PATCH] [rtext] add ExportFontAsCodeEx()
+
+ExportFontAsCode() loads image data from a font that is already
+uploaded to the GPU; this means that it requires a full graphics
+context/window. ExportFontAsCodeEx() loads the relevant font data
+into an atlas itself without ever creating a texture. This makes
+it possible to export font data as part of a build step when
+compiling a project when there is no GPU present (e.g. github CI).
+
+One minor change is that ExportFontAsCode() no longer converts the
+name to PascalCase. Its up to the user to pass the name in in that
+format if they want it.
+---
+ src/raylib.h | 1 +
+ src/rtext.c | 126 +++++++++++++++++++++++++++++++++++++--------------
+ 2 files changed, 93 insertions(+), 34 deletions(-)
+
+diff --git a/src/raylib.h b/src/raylib.h
+index 1cf34f00..c62d1909 100644
+--- a/src/raylib.h
++++ b/src/raylib.h
+@@ -1452,6 +1452,7 @@ RLAPI Image GenImageFontAtlas(const GlyphInfo *glyphs, Rectangle **glyphRecs, in
+ RLAPI void UnloadFontData(GlyphInfo *glyphs, int glyphCount); // Unload font chars info data (RAM)
+ RLAPI void UnloadFont(Font font); // Unload font from GPU memory (VRAM)
+ RLAPI bool ExportFontAsCode(Font font, const char *fileName); // Export font as code file, returns true on success
++RLAPI bool ExportFontAsCodeEx(const char *fontFileName, const char *outputFileName, int fontSize, int *codepoints, int codepointCount); // Export font as code file with extra parameters; returns true on success
+
+ // Text drawing functions
+ RLAPI void DrawFPS(int posX, int posY); // Draw current FPS
+diff --git a/src/rtext.c b/src/rtext.c
+index 755b15ef..a3d31028 100644
+--- a/src/rtext.c
++++ b/src/rtext.c
+@@ -953,20 +953,19 @@ void UnloadFont(Font font)
+ }
+ }
+
+-// Export font as code file, returns true on success
+-bool ExportFontAsCode(Font font, const char *fileName)
++
++static bool
++WriteOutputFontAsCode(Font font, Image atlas, const char *fileName)
+ {
+- bool success = false;
+-
+-#ifndef TEXT_BYTES_PER_LINE
+- #define TEXT_BYTES_PER_LINE 20
+-#endif
+-
+- #define MAX_FONT_DATA_SIZE 1024*1024 // 1 MB
+-
+ // Get file name from path
+- char fileNamePascal[256] = { 0 };
+- strncpy(fileNamePascal, TextToPascal(GetFileNameWithoutExt(fileName)), 256 - 1);
++ char baseFileName[256] = { 0 };
++ strncpy(baseFileName, GetFileNameWithoutExt(fileName), 256 - 1);
++
++ #ifndef TEXT_BYTES_PER_LINE
++ #define TEXT_BYTES_PER_LINE 20
++ #endif
++
++ #define MAX_FONT_DATA_SIZE 1024*1024
+
+ // NOTE: Text data buffer size is estimated considering image data size in bytes
+ // and requiring 6 char bytes for every byte: "0x00, "
+@@ -994,9 +993,8 @@ bool ExportFontAsCode(Font font, const char *fileName)
+
+ // Support font export and initialization
+ // NOTE: This mechanism is highly coupled to raylib
+- Image image = LoadImageFromTexture(font.texture);
+- if (image.format != PIXELFORMAT_UNCOMPRESSED_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);
++ if (atlas.format != PIXELFORMAT_UNCOMPRESSED_GRAY_ALPHA) TRACELOG(LOG_WARNING, "Font export as code: Font image format is not GRAY+ALPHA!");
++ int imageDataSize = GetPixelDataSize(atlas.width, atlas.height, atlas.format);
+
+ // Image data is usually GRAYSCALE + ALPHA and can be reduced to GRAYSCALE
+ //ImageFormat(&image, PIXELFORMAT_UNCOMPRESSED_GRAYSCALE);
+@@ -1009,13 +1007,13 @@ bool ExportFontAsCode(Font font, const char *fileName)
+
+ // Compress font image data
+ int compDataSize = 0;
+- unsigned char *compData = CompressData((const unsigned char *)image.data, imageDataSize, &compDataSize);
++ unsigned char *compData = CompressData((const unsigned char *)atlas.data, imageDataSize, &compDataSize);
+
+ // Save font image data (compressed)
+- byteCount += sprintf(txtData + byteCount, "#define COMPRESSED_DATA_SIZE_FONT_%s %i\n\n", TextToUpper(fileNamePascal), compDataSize);
++ byteCount += sprintf(txtData + byteCount, "#define COMPRESSED_DATA_SIZE_FONT_%s %i\n\n", TextToUpper(baseFileName), compDataSize);
+ 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, "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] = { ", baseFileName, TextToUpper(baseFileName));
+ 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, "0x%02x };\n\n", compData[compDataSize - 1]);
+ RL_FREE(compData);
+@@ -1023,14 +1021,14 @@ bool ExportFontAsCode(Font font, const char *fileName)
+ // Save font image data (uncompressed)
+ 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, "static unsigned char fontImageData_%s[%i] = { ", fileNamePascal, imageDataSize);
++ byteCount += sprintf(txtData + byteCount, "static unsigned char fontImageData_%s[%i] = { ", baseFileName, imageDataSize);
+ 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, "0x%02x };\n\n", ((unsigned char *)imFont.data)[imageDataSize - 1]);
+ #endif
+
+ // Save font recs data
+ byteCount += sprintf(txtData + byteCount, "// Font characters rectangles data\n");
+- byteCount += sprintf(txtData + byteCount, "static Rectangle fontRecs_%s[%i] = {\n", fileNamePascal, font.glyphCount);
++ byteCount += sprintf(txtData + byteCount, "static Rectangle fontRecs_%s[%i] = {\n", baseFileName, font.glyphCount);
+ for (int i = 0; i < font.glyphCount; i++)
+ {
+ byteCount += sprintf(txtData + byteCount, " { %1.0f, %1.0f, %1.0f , %1.0f },\n", font.recs[i].x, font.recs[i].y, font.recs[i].width, font.recs[i].height);
+@@ -1042,7 +1040,7 @@ bool ExportFontAsCode(Font font, const char *fileName)
+ // it could be generated from image and recs
+ byteCount += sprintf(txtData + byteCount, "// Font glyphs info data\n");
+ byteCount += sprintf(txtData + byteCount, "// NOTE: No glyphs.image data provided\n");
+- byteCount += sprintf(txtData + byteCount, "static GlyphInfo fontGlyphs_%s[%i] = {\n", fileNamePascal, font.glyphCount);
++ byteCount += sprintf(txtData + byteCount, "static GlyphInfo fontGlyphs_%s[%i] = {\n", baseFileName, font.glyphCount);
+ for (int i = 0; i < font.glyphCount; i++)
+ {
+ byteCount += sprintf(txtData + byteCount, " { %i, %i, %i, %i, { 0 }},\n", font.glyphs[i].value, font.glyphs[i].offsetX, font.glyphs[i].offsetY, font.glyphs[i].advanceX);
+@@ -1050,8 +1048,8 @@ bool ExportFontAsCode(Font font, const char *fileName)
+ byteCount += sprintf(txtData + byteCount, "};\n\n");
+
+ // Custom font loading function
+- byteCount += sprintf(txtData + byteCount, "// Font loading function: %s\n", fileNamePascal);
+- byteCount += sprintf(txtData + byteCount, "static Font LoadFont_%s(void)\n{\n", fileNamePascal);
++ byteCount += sprintf(txtData + byteCount, "// Font loading function: %s\n", baseFileName);
++ byteCount += sprintf(txtData + byteCount, "static Font LoadFont_%s(void)\n{\n", baseFileName);
+ byteCount += sprintf(txtData + byteCount, " Font font = { 0 };\n\n");
+ byteCount += sprintf(txtData + byteCount, " font.baseSize = %i;\n", font.baseSize);
+ byteCount += sprintf(txtData + byteCount, " font.glyphCount = %i;\n", font.glyphCount);
+@@ -1059,11 +1057,11 @@ bool ExportFontAsCode(Font font, const char *fileName)
+ byteCount += sprintf(txtData + byteCount, " // Custom font loading\n");
+ #if defined(SUPPORT_COMPRESSED_FONT_ATLAS)
+ byteCount += sprintf(txtData + byteCount, " // NOTE: Compressed font image data (DEFLATE), it requires DecompressData() function\n");
+- byteCount += sprintf(txtData + byteCount, " int fontDataSize_%s = 0;\n", fileNamePascal);
+- byteCount += sprintf(txtData + byteCount, " unsigned char *data = DecompressData(fontData_%s, COMPRESSED_DATA_SIZE_FONT_%s, &fontDataSize_%s);\n", fileNamePascal, TextToUpper(fileNamePascal), fileNamePascal);
+- byteCount += sprintf(txtData + byteCount, " Image imFont = { data, %i, %i, 1, %i };\n\n", image.width, image.height, image.format);
++ byteCount += sprintf(txtData + byteCount, " int fontDataSize_%s = 0;\n", baseFileName);
++ byteCount += sprintf(txtData + byteCount, " unsigned char *data = DecompressData(fontData_%s, COMPRESSED_DATA_SIZE_FONT_%s, &fontDataSize_%s);\n", baseFileName, TextToUpper(baseFileName), baseFileName);
++ byteCount += sprintf(txtData + byteCount, " Image imFont = { data, %i, %i, 1, %i };\n\n", atlas.width, atlas.height, atlas.format);
+ #else
+- byteCount += sprintf(txtData + byteCount, " Image imFont = { fontImageData_%s, %i, %i, 1, %i };\n\n", styleName, image.width, image.height, image.format);
++ byteCount += sprintf(txtData + byteCount, " Image imFont = { fontImageData_%s, %i, %i, 1, %i };\n\n", styleName, atlas.width, atlas.height, atlas.format);
+ #endif
+ byteCount += sprintf(txtData + byteCount, " // Load texture from image\n");
+ byteCount += sprintf(txtData + byteCount, " font.texture = LoadTextureFromImage(imFont);\n");
+@@ -1079,25 +1077,23 @@ bool ExportFontAsCode(Font font, const char *fileName)
+ byteCount += sprintf(txtData + byteCount, " // Copy glyph recs data from global fontRecs\n");
+ byteCount += sprintf(txtData + byteCount, " // NOTE: Required to avoid issues if trying to free font\n");
+ byteCount += sprintf(txtData + byteCount, " font.recs = (Rectangle *)malloc(font.glyphCount*sizeof(Rectangle));\n");
+- byteCount += sprintf(txtData + byteCount, " memcpy(font.recs, fontRecs_%s, font.glyphCount*sizeof(Rectangle));\n\n", fileNamePascal);
++ byteCount += sprintf(txtData + byteCount, " memcpy(font.recs, fontRecs_%s, font.glyphCount*sizeof(Rectangle));\n\n", baseFileName);
+
+ byteCount += sprintf(txtData + byteCount, " // Copy font glyph info data from global fontChars\n");
+ byteCount += sprintf(txtData + byteCount, " // NOTE: Required to avoid issues if trying to free font\n");
+ byteCount += sprintf(txtData + byteCount, " font.glyphs = (GlyphInfo *)malloc(font.glyphCount*sizeof(GlyphInfo));\n");
+- byteCount += sprintf(txtData + byteCount, " memcpy(font.glyphs, fontGlyphs_%s, font.glyphCount*sizeof(GlyphInfo));\n\n", fileNamePascal);
++ byteCount += sprintf(txtData + byteCount, " memcpy(font.glyphs, fontGlyphs_%s, font.glyphCount*sizeof(GlyphInfo));\n\n", baseFileName);
+ #else
+ byteCount += sprintf(txtData + byteCount, " // Assign glyph recs and info data directly\n");
+ byteCount += sprintf(txtData + byteCount, " // WARNING: This font data must not be unloaded\n");
+- byteCount += sprintf(txtData + byteCount, " font.recs = fontRecs_%s;\n", fileNamePascal);
+- byteCount += sprintf(txtData + byteCount, " font.glyphs = fontGlyphs_%s;\n\n", fileNamePascal);
++ byteCount += sprintf(txtData + byteCount, " font.recs = fontRecs_%s;\n", baseFileName);
++ byteCount += sprintf(txtData + byteCount, " font.glyphs = fontGlyphs_%s;\n\n", baseFileName);
+ #endif
+ byteCount += sprintf(txtData + byteCount, " return font;\n");
+ byteCount += sprintf(txtData + byteCount, "}\n");
+
+- UnloadImage(image);
+-
+ // NOTE: Text data size exported is determined by '\0' (NULL) character
+- success = SaveFileText(fileName, txtData);
++ bool success = SaveFileText(fileName, txtData);
+
+ RL_FREE(txtData);
+
+@@ -1107,6 +1103,68 @@ bool ExportFontAsCode(Font font, const char *fileName)
+ return success;
+ }
+
++// Export font as code file, returns true on success
++bool ExportFontAsCode(Font font, const char *fileName)
++{
++ Image atlas = LoadImageFromTexture(font.texture);
++ bool success = WriteOutputFontAsCode(font, atlas, fileName);
++ UnloadImage(atlas);
++ return success;
++}
++
++// Export font as code file with extra parameters; returns true on success
++bool ExportFontAsCodeEx(const char *fontFileName, const char *outputFileName, int fontSize, int *codepoints, int codepointCount)
++{
++ int dataSize = 0;
++ unsigned char *fileData = LoadFileData(fontFileName, &dataSize);
++
++ if (fileData == NULL) {
++ TRACELOG(LOG_WARNING, "FILEIO: [%s] Failed to export font as code", fontFileName);
++ return false;
++ }
++
++ Font font = {0};
++ font.baseSize = fontSize;
++ font.glyphCount = (codepointCount > 0)? codepointCount : 95;
++
++ char fileExtLower[16] = { 0 };
++ strncpy(fileExtLower, TextToLower(GetFileExtension(fontFileName)), 16 - 1);
++
++#if defined(SUPPORT_FILEFORMAT_TTF)
++ if (TextIsEqual(fileExtLower, ".ttf") ||
++ TextIsEqual(fileExtLower, ".otf"))
++ {
++ font.glyphs = LoadFontData(fileData, dataSize, font.baseSize, codepoints, font.glyphCount, FONT_DEFAULT);
++ }
++#endif
++#if defined(SUPPORT_FILEFORMAT_BDF)
++ if (TextIsEqual(fileExtLower, ".bdf"))
++ {
++ font.glyphs = LoadFontDataBDF(fileData, dataSize, codepoints, font.glyphCount, &font.baseSize);
++ }
++#endif
++
++ Image atlas;
++#if defined(SUPPORT_FILEFORMAT_TTF) || defined(SUPPORT_FILEFORMAT_BDF)
++ if (font.glyphs != NULL) {
++ font.glyphPadding = FONT_TTF_DEFAULT_CHARS_PADDING;
++ atlas = GenImageFontAtlas(font.glyphs, &font.recs, font.glyphCount, font.baseSize, font.glyphPadding, 0);
++ } else {
++ TRACELOG(LOG_WARNING, "FILEIO: [%s] Failed to export font as code", fontFileName);
++ }
++#endif
++
++ bool success = false;
++ if (font.glyphs != NULL) {
++ success = WriteOutputFontAsCode(font, atlas, outputFileName);
++ UnloadFileData(fileData);
++ UnloadFontData(font.glyphs, font.glyphCount);
++ UnloadImage(atlas);
++ }
++
++ return success;
++}
++
+ // Draw current FPS
+ // NOTE: Uses default font
+ void DrawFPS(int posX, int posY)
+--
+2.44.0
+
diff --git a/gen_incs.c b/gen_incs.c
@@ -52,120 +52,18 @@ get_line(s8 *s)
return res;
}
-static Font
-load_font(s8 font_data, Image *out, int font_size)
-{
- Font font = {0};
- font.baseSize = font_size;
- font.glyphCount = 95;
- font.glyphPadding = 0;
- font.glyphs = LoadFontData(font_data.data, font_data.len, font.baseSize, 0,
- font.glyphCount, FONT_DEFAULT);
-
- if (font.glyphs != NULL) {
- font.glyphPadding = 4;
- *out = GenImageFontAtlas(font.glyphs, &font.recs, font.glyphCount,
- font.baseSize, font.glyphPadding, 0);
- }
- return font;
-}
-
-/* NOTE: Modified from raylib. Used to save font data without opening a window */
-static void
-export_font_as_code(Font font, Image image, const char *fileName, char *txt)
-{
- #define TEXT_BYTES_PER_LINE 20
-
- // Get file name from path
- char fileNamePascal[256] = { 0 };
- strncpy(fileNamePascal, TextToPascal(GetFileNameWithoutExt(fileName)), 256 - 1);
-
- int off = 0;
- // Support font export and initialization
- // NOTE: This mechanism is highly coupled to raylib
- int imageDataSize = GetPixelDataSize(image.width, image.height, image.format);
-
- // Image data is usually GRAYSCALE + ALPHA and can be reduced to GRAYSCALE
- //ImageFormat(&image, PIXELFORMAT_UNCOMPRESSED_GRAYSCALE);
-
- // WARNING: Data is compressed using raylib CompressData() DEFLATE,
- // it requires to be decompressed with raylib DecompressData(), that requires
- // compiling raylib with SUPPORT_COMPRESSION_API config flag enabled
-
- // Compress font image data
- int compDataSize = 0;
- unsigned char *compData = CompressData((const unsigned char *)image.data, imageDataSize, &compDataSize);
-
- // Save font image data (compressed)
- off += sprintf(txt + off, "#define COMPRESSED_DATA_SIZE_FONT_%s %i\n\n", TextToUpper(fileNamePascal), compDataSize);
- off += sprintf(txt + off, "// Font image pixels data compressed (DEFLATE)\n");
- off += sprintf(txt + off, "// NOTE: Original pixel data simplified to GRAYSCALE\n");
- off += sprintf(txt + off, "static unsigned char fontData_%s[COMPRESSED_DATA_SIZE_FONT_%s] = { ", fileNamePascal, TextToUpper(fileNamePascal));
- for (int i = 0; i < compDataSize - 1; i++) off += sprintf(txt + off, ((i%TEXT_BYTES_PER_LINE == 0)? "0x%02x,\n " : "0x%02x, "), compData[i]);
- off += sprintf(txt + off, "0x%02x };\n\n", compData[compDataSize - 1]);
- RL_FREE(compData);
-
- // Save font recs data
- off += sprintf(txt + off, "// Font characters rectangles data\n");
- off += sprintf(txt + off, "static Rectangle fontRecs_%s[%i] = {\n", fileNamePascal, font.glyphCount);
- for (int i = 0; i < font.glyphCount; i++) {
- off += sprintf(txt + off, " { %1.0f, %1.0f, %1.0f , %1.0f },\n",
- font.recs[i].x, font.recs[i].y, font.recs[i].width, font.recs[i].height);
- }
- off += sprintf(txt + off, "};\n\n");
-
- // Save font glyphs data
- // NOTE: Glyphs image data not saved (grayscale pixels),
- // it could be generated from image and recs
- off += sprintf(txt + off, "// Font glyphs info data\n");
- off += sprintf(txt + off, "// NOTE: No glyphs.image data provided\n");
- off += sprintf(txt + off, "static GlyphInfo fontGlyphs_%s[%i] = {\n", fileNamePascal, font.glyphCount);
- for (int i = 0; i < font.glyphCount; i++) {
- off += sprintf(txt + off, " { %i, %i, %i, %i, { 0 }},\n",
- font.glyphs[i].value, font.glyphs[i].offsetX,
- font.glyphs[i].offsetY, font.glyphs[i].advanceX);
- }
- off += sprintf(txt + off, "};\n\n");
-
- // Custom font loading function
- off += sprintf(txt + off, "// Font loading function: %s\n", fileNamePascal);
- off += sprintf(txt + off, "static Font LoadFont_%s(void)\n{\n", fileNamePascal);
- off += sprintf(txt + off, " Font font = { 0 };\n\n");
- off += sprintf(txt + off, " font.baseSize = %i;\n", font.baseSize);
- off += sprintf(txt + off, " font.glyphCount = %i;\n", font.glyphCount);
- off += sprintf(txt + off, " font.glyphPadding = %i;\n\n", font.glyphPadding);
- off += sprintf(txt + off, " // Custom font loading\n");
- off += sprintf(txt + off, " // NOTE: Compressed font image data (DEFLATE), it requires DecompressData() function\n");
- off += sprintf(txt + off, " int fontDataSize_%s = 0;\n", fileNamePascal);
- off += sprintf(txt + off, " unsigned char *data = DecompressData(fontData_%s, COMPRESSED_DATA_SIZE_FONT_%s, &fontDataSize_%s);\n", fileNamePascal, TextToUpper(fileNamePascal), fileNamePascal);
- off += sprintf(txt + off, " Image imFont = { data, %i, %i, 1, %i };\n\n", image.width, image.height, image.format);
- off += sprintf(txt + off, " // Load texture from image\n");
- off += sprintf(txt + off, " font.texture = LoadTextureFromImage(imFont);\n");
- off += sprintf(txt + off, " UnloadImage(imFont); // Uncompressed data can be unloaded from memory\n\n");
- off += sprintf(txt + off, " // Assign glyph recs and info data directly\n");
- off += sprintf(txt + off, " // WARNING: This font data must not be unloaded\n");
- off += sprintf(txt + off, " font.recs = fontRecs_%s;\n", fileNamePascal);
- off += sprintf(txt + off, " font.glyphs = fontGlyphs_%s;\n\n", fileNamePascal);
- off += sprintf(txt + off, " return font;\n");
- off += sprintf(txt + off, "}\n");
-
- // NOTE: Text data size exported is determined by '\0' (NULL) character
- SaveFileText(fileName, txt);
-}
-
int
main(void)
{
- static char mem[2u * 1024u * 1024u];
- s8 smem = {.data = (uint8_t *)mem, .len = sizeof(mem)};
+ static uint8_t mem[2u * 1024u * 1024u];
+ s8 smem = {.data = mem, .len = sizeof(mem)};
SetTraceLogLevel(LOG_NONE);
- Image atlas;
- s8 font_data = read_whole_file("assets/Lora-SemiBold.ttf", smem);
- Font font = load_font(font_data, &atlas, FONT_SIZE);
- export_font_as_code(font, atlas, "font_inc.h", mem);
+ char *font_inc_name = "lora_sb_inc.h";
+ if (!ExportFontAsCodeEx("assets/Lora-SemiBold.ttf", font_inc_name, FONT_SIZE, 0, 0))
+ printf("Failed to export font: %s\n", font_inc_name);
- FILE *out_file = fopen("shader_inc.h", "w");
+ FILE *out_file = fopen("external/include/shader_inc.h", "w");
if (!out_file) {
fputs("Failed to open necessary files!\n", stdout);
return 1;
diff --git a/main.c b/main.c
@@ -152,8 +152,8 @@ main(i32 argc, char *argv[])
SetConfigFlags(FLAG_VSYNC_HINT);
InitWindow(ctx.window_size.w, ctx.window_size.h, "Colour Picker");
- ctx.font_size = FONT_SIZE;
- ctx.font = LoadFont_FontInc();
+ ctx.font = LoadFont_lora_sb_inc();
+ ctx.font_size = ctx.font.baseSize;
while(!WindowShouldClose()) {
do_debug();
diff --git a/util.c b/util.c
@@ -8,7 +8,7 @@
#include <stdint.h>
#include "shader_inc.h"
-#include "font_inc.h"
+#include "lora_sb_inc.h"
#include "config.h"
#ifndef asm