add: RenderTarget

This commit is contained in:
Simon Hardt
2022-03-03 19:43:37 +01:00
parent 02562095d8
commit 420d4c9dc1
7 changed files with 161 additions and 21 deletions

View File

@@ -0,0 +1,49 @@
#include "RenderTarget.hpp"
namespace frame::render
{
RenderTarget::RenderTarget(Size size)
: image(size)
{
}
void RenderTarget::DrawPixel(Vector const& position, Color color)
{
image.at(position.x, position.y) = color;
}
void RenderTarget::DrawLine(Vector const& start,
Vector const& end,
Color color)
{
auto const deltaX = std::abs(start.x - end.x);
auto const deltaY = std::abs(start.y - end.y);
auto const rX = start.x < end.x ? 1 : -1;
auto const rY = start.y < end.y ? 1 : -1;
auto pos = start;
auto E = 2 * deltaY - deltaX;
DrawPixel(pos, color);
while(pos != end)
{
if(E <= 0)
{
pos.x += rX;
E += 2 * deltaY;
} else
{
pos.x += rX;
pos.y += rY;
E += 2 * deltaY - 2 * deltaX;
}
DrawPixel(pos, color);
}
}
} // namespace frame::render