do font stuff

This commit is contained in:
Bailey Harrison 2022-11-23 18:09:49 +00:00
parent 04a7114e0e
commit e495183019
2 changed files with 13 additions and 4 deletions

View File

@ -6,6 +6,8 @@
#include "util/files.hpp" #include "util/files.hpp"
#include "gfx_device.hpp" #include "gfx_device.hpp"
#include "log.hpp"
namespace engine::resources { namespace engine::resources {
Font::Font(const std::filesystem::path& resPath) : Resource(resPath, "font") 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{}; stbtt_fontinfo info{};
int res = stbtt_InitFont(&info, fontBuffer->data(), 0); int res = stbtt_InitFont(&info, fontBuffer->data(), 0);
if (res != 0) { if (!res) {
throw std::runtime_error("Failed to read font file: " + resPath.string()); 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; int32_t w, h, yoff;
const uint8_t* bitmap = stbtt_GetCodepointBitmap(&info, scale, scale, c, &w, &h, &xoff, &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<std::vector<uint32_t>>(w * h); auto colorBuffer = std::make_unique<std::vector<uint32_t>>(w * h);
int i = 0; int i = 0;
for (uint32_t& col : *colorBuffer) { for (uint32_t& col : *colorBuffer) {
col = bitmap[i]; if (bitmap[i] == 0) {
col = 0;
} else {
col = 0xFFFFFFFF;
}
i++; i++;
} }

View File

@ -11,6 +11,7 @@
#include "resource_manager.hpp" #include "resource_manager.hpp"
#include "resources/texture.hpp" #include "resources/texture.hpp"
#include "resources/font.hpp"
#include "util/model_loader.hpp" #include "util/model_loader.hpp"
@ -157,9 +158,9 @@ void playGame()
lego->transform.position = { 30.0f, -2.0f, 30.0f }; lego->transform.position = { 30.0f, -2.0f, 30.0f };
lego->transform.scale = { 0.1f, 0.1f, 0.1f }; lego->transform.scale = { 0.1f, 0.1f, 0.1f };
// END TESTING
app.scene()->printTree(); app.scene()->printTree();
auto myFont = app.resources()->get<engine::resources::Font>("fonts/LiberationMono-Regular.ttf");
app.gameLoop(); app.gameLoop();
} }