-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathFramebuffer.cpp
More file actions
60 lines (47 loc) · 1.48 KB
/
Framebuffer.cpp
File metadata and controls
60 lines (47 loc) · 1.48 KB
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#include "Framebuffer.h"
#include <memory.h>
void Framebuffer::recreate(int width, int height){
this->width = width;
this->height = height;
colorbuffer = new colorbuffer_t[width * height];
depthbuffer = new depthbuffer_t[width * height];
}
void Framebuffer::clear(int clearColor){
memset(colorbuffer, clearColor, sizeof(colorbuffer_t) * width * height);
memset(depthbuffer, MAX_DEPTH_VALUE, sizeof(depthbuffer_t) * width * height);
}
void Framebuffer::setPixel(int x, int y, colorbuffer_t pixelcolor, depthbuffer_t depth){
int index = (y * width) + x;
if(depth < depthbuffer[index]){
colorbuffer[index] = pixelcolor;
depthbuffer[index] = depth;
}
}
colorbuffer_t Framebuffer::getColor(int x, int y){
int index = (y * width) + x;
return colorbuffer[index];
}
depthbuffer_t Framebuffer::getDepth(int x, int y){
int index = (y * width) + x;
return depthbuffer[index];
}
Framebuffer::Framebuffer(int width, int height)
:width(width), height(height)
{
recreate(width, height);
}
Framebuffer::~Framebuffer(){
delete[] colorbuffer;
delete[] depthbuffer;
}
void Framebuffer::print(){
for(int i = 0; i < width; i++){
for(int j = 0; j < height; j++){
int index = (width * j) + i;
//if(!colorbuffer[index]) continue;
int color = (char)(colorbuffer[index] >> 8);
attron(COLOR_PAIR(color));
mvprintw(j, i, "%c", (char)colorbuffer[index]);
}
}
}