mirror of
https://github.com/bailwillharr/engine.git
synced 2024-09-21 04:51:18 +00:00
do font stuff
This commit is contained in:
parent
04a7114e0e
commit
e495183019
@ -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++;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -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();
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user