-
Notifications
You must be signed in to change notification settings - Fork 147
Expand file tree
/
Copy pathframebuffer.cpp
More file actions
26 lines (21 loc) · 785 Bytes
/
Copy pathframebuffer.cpp
File metadata and controls
26 lines (21 loc) · 785 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
#include <cassert>
#include "framebuffer.h"
#include "utils.h"
void FrameBuffer::set_pixel(const size_t x, const size_t y, const uint32_t color) {
assert(img.size()==w*h && x<w && y<h);
img[x+y*w] = color;
}
void FrameBuffer::draw_rectangle(const size_t rect_x, const size_t rect_y, const size_t rect_w, const size_t rect_h, const uint32_t color) {
assert(img.size()==w*h);
for (size_t i=0; i<rect_w; i++) {
for (size_t j=0; j<rect_h; j++) {
size_t cx = rect_x+i;
size_t cy = rect_y+j;
if (cx<w && cy<h) // no need to check for negative values (unsigned variables)
set_pixel(cx, cy, color);
}
}
}
void FrameBuffer::clear(const uint32_t color) {
img = std::vector<uint32_t>(w*h, color);
}