-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathframebuffer.cpp
37 lines (32 loc) · 1.12 KB
/
framebuffer.cpp
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
26
27
28
29
30
31
32
33
34
35
36
37
#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);
}
void FrameBuffer::set_floor(const uint32_t color) {
assert(img.size()==w*h);
for (size_t i=0; i<w; i++) {
for (size_t j=h/2; j<h; j++) {
size_t cx = i;
size_t cy = j;
if (cx<w && cy<h) // no need to check for negative values (unsigned variables)
set_pixel(cx, cy, color);
}
}
}