add: RenderTarget
This commit is contained in:
49
frame/src/render/RenderTarget.cpp
Normal file
49
frame/src/render/RenderTarget.cpp
Normal 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
|
||||
Reference in New Issue
Block a user