add: Basic Font Rendering

This commit is contained in:
Simon Hardt
2022-03-05 02:37:08 +01:00
parent df1ce5583b
commit 0553927dad
15 changed files with 386 additions and 9 deletions

View File

@@ -142,6 +142,46 @@ namespace frame::render
{BottomRight.x, BottomRight.y - lw});
}
void RenderTarget::DrawImage(Vector topLeft, Image const& image)
{
auto pos = topLeft;
for(auto y = 0; y < image.getHeight(); ++y)
{
for(auto x = 0; x < image.getWidth(); ++x)
{
DrawPixel({pos.x + x, pos.y + y}, (Color)image.at(x, y));
}
}
}
Vector RenderTarget::DrawGlyph(Vector centerLine,
font::Glyph const& g,
Color color)
{
auto const& height = g.height;
Vector topleft = centerLine;
topleft.x += g.x_offset;
topleft.y += g.y_offset;
DrawImage(topleft, g.image);
centerLine.x += g.advance;
return centerLine;
}
void RenderTarget::DrawText(std::string_view pText,
Vector pCenterLineStart,
font::Font const& pFont,
uint8_t size)
{
auto pos = pCenterLineStart;
for(auto c : pText)
{
pos = DrawGlyph(pos, pFont.getGlyph(size, c));
}
}
void RenderTarget::DrawPointsMirrorCircle(Vector const& center,
Vector const& pos,
Color color)