-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrender.cpp
111 lines (93 loc) · 2.03 KB
/
render.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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
#include "render.h"
using namespace std;
render::render(int width, int height, float backRed, float backGreen, float backBlue)
: backgroundColor(backRed, backGreen, backBlue)
{
this->width = width;
this->height = height;
buffer = new RendererColor*[this->width];
for (int i = 0; i < this->width; i++)
buffer[i] = new RendererColor[this->height];
reset();
}
render::~render()
{
for (int i = 0; i < this->width; i++)
delete[] buffer[i];
delete[] buffer;
}
void render::reset()
{
isDrawing = true;
x = 0;
y = 0;
}
RendererColor render::calculatePixel(int i, int j)
{
RendererColor color;
return color;
}
void render::keyboard(int key, int x, int y)
{
switch (key)
{
case '\27':
glutDestroyWindow(window);
exit(0);
default:
break;
}
glutPostRedisplay();
}
void render::initGL()
{
glClearColor(backgroundColor.getRed(), backgroundColor.getGreen(), backgroundColor.getBlue(), 0.0f);
}
void render::drawScene()
{
glClear(GL_COLOR_BUFFER_BIT);
glMatrixMode(GL_PROJECTION);
glOrtho(0.0, width, 0.0, height, 1, -1);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glBegin(GL_POINTS);
for (int i = 0; i < width; i++) {
for (int j = 0; j < height; j++) {
glColor3f(buffer[i][j].getRed(), buffer[i][j].getGreen(), buffer[i][j].getBlue());
}
}
glEnd();
glFlush();
}
void render::reshape(int width, int height)
{
this->width = width;
this->height = height;
for (int i = 0; i < this->width; i++)
delete[] buffer[i];
delete[] buffer;
buffer = new RendererColor*[this->width];
for (int i = 0; i < this->width; i++)
buffer[i] = new RendererColor[this->height];
reset();
}
void render::idle()
{
if(isDrawing) {
buffer[x][y] = calculatePixel(x, y);
++x;
if (x >= width) {
x = 0;
++y;
glutPostRedisplay();
}
if (y >= height) {
isDrawing = false;
glutPostRedisplay();
}
}
}
void render::saveImage()
{
//TODO Implement this
}