diff --git a/src/resources/font.cpp b/src/resources/font.cpp index 2c80c59..0c92896 100644 --- a/src/resources/font.cpp +++ b/src/resources/font.cpp @@ -6,6 +6,8 @@ #include "util/files.hpp" #include "gfx_device.hpp" +#include "log.hpp" + namespace engine::resources { Font::Font(const std::filesystem::path& resPath) : Resource(resPath, "font") @@ -16,7 +18,7 @@ Font::Font(const std::filesystem::path& resPath) : Resource(resPath, "font") stbtt_fontinfo info{}; int res = stbtt_InitFont(&info, fontBuffer->data(), 0); - if (res != 0) { + if (!res) { throw std::runtime_error("Failed to read font file: " + resPath.string()); } @@ -31,10 +33,16 @@ Font::Font(const std::filesystem::path& resPath) : Resource(resPath, "font") int32_t w, h, yoff; const uint8_t* bitmap = stbtt_GetCodepointBitmap(&info, scale, scale, c, &w, &h, &xoff, &yoff); + DEBUG("char width: {} char height: {}", w, h); + auto colorBuffer = std::make_unique>(w * h); int i = 0; for (uint32_t& col : *colorBuffer) { - col = bitmap[i]; + if (bitmap[i] == 0) { + col = 0; + } else { + col = 0xFFFFFFFF; + } i++; } diff --git a/test/src/game.cpp b/test/src/game.cpp index bc89398..52593e8 100644 --- a/test/src/game.cpp +++ b/test/src/game.cpp @@ -11,6 +11,7 @@ #include "resource_manager.hpp" #include "resources/texture.hpp" +#include "resources/font.hpp" #include "util/model_loader.hpp" @@ -157,9 +158,9 @@ void playGame() lego->transform.position = { 30.0f, -2.0f, 30.0f }; lego->transform.scale = { 0.1f, 0.1f, 0.1f }; - // END TESTING - app.scene()->printTree(); + auto myFont = app.resources()->get("fonts/LiberationMono-Regular.ttf"); + app.gameLoop(); }