43 lines
1.0 KiB
C++
43 lines
1.0 KiB
C++
|
|
#ifndef RENDERER_H
|
|
#define RENDERER_H
|
|
|
|
#include "fastmath.hpp"
|
|
#include "polygon.hpp"
|
|
#include "rendertarget.hpp"
|
|
#include <memory.h>
|
|
|
|
class Renderer {
|
|
|
|
public:
|
|
Rendertarget *target;
|
|
|
|
bool clearTarget = true;
|
|
Renderer() : clearTarget(false) {}
|
|
|
|
void render(polygon *p) {
|
|
decimal widthScale = decimal(1.0) / decimal((float)target->width);
|
|
decimal heightScale = decimal(1.0) / decimal((float)target->height);
|
|
// std::cout << widthScale << std::endl;
|
|
vec3 pos = vec3();
|
|
|
|
if (clearTarget) {
|
|
memset((wchar_t *)target->pixels, 0,
|
|
target->height * target->width * sizeof(target[0]));
|
|
}
|
|
|
|
for (int x = 0; x < target->height; x++) {
|
|
for (int y = 0; y < target->height; y++) {
|
|
if (p->contains(pos)) {
|
|
target->set(x, y, vec3(0.0, 255.0, 0.0));
|
|
}
|
|
pos.y() += heightScale;
|
|
}
|
|
pos.y() = decimal(0);
|
|
pos.x() += widthScale;
|
|
}
|
|
}
|
|
};
|
|
|
|
#endif
|