-
Notifications
You must be signed in to change notification settings - Fork 0
/
basic.cpp
112 lines (81 loc) · 2.05 KB
/
basic.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
112
#include "fw1/fw1.h"
#define COLOUR_RED 0
#define COLOUR_GREEN 1
#define COLOUR_BLUE 2
#define COLOUR_ALPHA 3
class BasicApp : public FrameworkOneApp {
public:
BasicApp();
~BasicApp();
bool appMain();
void appInit();
void appQuit();
private:
SDLDisplay *display;
int colourIndex;
bool running;
void draw_colour(GLfloat r, GLfloat g, GLfloat b);
GLfloat *colour_for_time(int time);
};
BasicApp::BasicApp() {
this->display = NULL;
this->colourIndex = 0;
this->running = true;
}
BasicApp::~BasicApp() {
if (this->display != NULL) {
delete this->display;
}
}
void BasicApp::appInit() {
this->display = SDLDisplay::basicDisplay("I'm a window", 300, 400);
}
bool BasicApp::appMain() {
GLfloat *colour;
if (this->colourIndex >= 512) {
// We're done, exit
return false;
}
colour = colour_for_time(this->colourIndex);
this->colourIndex++;
draw_colour(colour[COLOUR_RED], colour[COLOUR_GREEN], colour[COLOUR_BLUE]);
display->swapBuffers();
display->mainLoop(*this);
SDL_Delay(100);
return this->running;
}
void BasicApp::appQuit() {
this->running = false;
}
void BasicApp::draw_colour(GLfloat r, GLfloat g, GLfloat b) {
Logger::logprintf(Logger::LOG_VERBOSEINFO, Logger::LOG_APPLICATION, "[%i] R:%f G:%f B:%f\n", this->colourIndex, r, g, b);
glClearColor(r, g, b, 1.0f);
glClear(GL_COLOR_BUFFER_BIT);
}
GLfloat *BasicApp::colour_for_time(int time) {
static GLfloat colour[4];
if ( time >= 256 ) {
colour[COLOUR_RED] = (512 - time) / 256.0f;
} else {
colour[COLOUR_RED] = time / 256.0f;
};
if ( time >= 256 ) {
colour[COLOUR_GREEN] = (time - 256) / 256.0f;
} else {
colour[COLOUR_GREEN] = 0.0f;
};
if ( time >= 256 ) {
colour[COLOUR_BLUE] = 0.0f;
} else {
colour[COLOUR_BLUE] = (256 - time) / 256.0f;
};
colour[COLOUR_ALPHA] = 1.0f;
return colour;
}
int main( int argc, char* args[] ) {
FrameworkOneApp *thisApp = new BasicApp();
thisApp->appInit();
while (thisApp->appMain()) { };
delete thisApp;
return 0;
}