add progress bar to lightmap rendering

This commit is contained in:
2019-01-15 22:25:23 +01:00
parent c3220b5b15
commit f5c4aed4fd
8 changed files with 98 additions and 53 deletions

View File

@@ -17,6 +17,7 @@ bool Font::load(const char* ttf, int font_size)
auto bitmap = std::make_unique<uint8_t[]>(w*h);
chars.resize(num_chars);
stbtt_BakeFontBitmap(file.m_data, 0, (float)font_size*2, bitmap.get(), w, h, start_char, num_chars, chars.data());
calc_bounds();
font_tex.create(w, h, GL_R8, GL_RED, bitmap.get());
file.close();
size = font_size;
@@ -25,6 +26,21 @@ bool Font::load(const char* ttf, int font_size)
return false;
}
void Font::calc_bounds()
{
glm::vec2 bbmin(FLT_MAX);
glm::vec2 bbmax(-FLT_MAX);
for (int i = 0; i < num_chars; i++)
{
stbtt_aligned_quad q;
float x = 0, y = 0;
stbtt_GetBakedQuad(chars.data(), w, h, i, &x, &y, &q, true);
bbmin = glm::min(bbmin, { q.x0 / 2.f, q.y0 / 2.f });
bbmax = glm::max(bbmax, { q.x1 / 2.f, q.y1 / 2.f });
}
bounds = { glm::vec4(bbmin, bbmax) };
}
void FontManager::init()
{
m_sampler.create();