-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFadeRenderer.cpp
93 lines (76 loc) · 2.35 KB
/
FadeRenderer.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
// Author: mikedebo@gmail.com (Michael DiBernardo)
// Copyright Michael DiBernardo 2006
// Implementation of class FadeRenderer and related constructs.
#include "FadeRenderer.h"
#include "os.h"
#include "Config.h"
#include "Timer.h"
FadeRenderer::FadeRenderer(int secondsToFade, NextAction doneAction, Renderer* sceneToFade)
: durationBefore_(0),
duration_(secondsToFade * 1000),
doneAction_(doneAction),
target_(sceneToFade),
fadeTimer_(new Timer()) {
fadeTimer_->start();
}
FadeRenderer::FadeRenderer(int secondsBeforeFade, int secondsToFade, NextAction doneAction, Renderer* sceneToFade)
: durationBefore_(secondsBeforeFade * 1000),
duration_(secondsToFade * 1000),
doneAction_(doneAction),
target_(sceneToFade),
fadeTimer_(new Timer()) {
fadeTimer_->start();
}
FadeRenderer::~FadeRenderer() {
delete target_;
delete fadeTimer_;
}
void FadeRenderer::init() {
}
NextAction FadeRenderer::render() {
target_->render();
glMatrixMode(GL_PROJECTION);
glPushMatrix();
glLoadIdentity();
gluOrtho2D(0, Config::MAX_2D_COORD, 0, Config::MAX_2D_COORD);
glMatrixMode(GL_MODELVIEW);
double elapsed = fadeTimer_->getTimeInMilliseconds();
double fadeFactor = (elapsed - durationBefore_) / duration_;
if (fadeFactor < 0.0) fadeFactor = 0.0;
glColor4d(0, 0, 0, fadeFactor);
glBegin(GL_QUADS);
glVertex3f(0, 0, 0);
glVertex3f(Config::MAX_2D_COORD, 0, 0);
glVertex3f(Config::MAX_2D_COORD, Config::MAX_2D_COORD, 0);
glVertex3f(0, Config::MAX_2D_COORD, 0);
glEnd();
glMatrixMode(GL_PROJECTION);
glPopMatrix();
glMatrixMode(GL_MODELVIEW);
if (elapsed > (duration_ + durationBefore_)) {
return doneAction_;
} else {
return RA_REDISPLAY;
}
}
void FadeRenderer::reshape(int newWidth, int newHeight) {
target_->reshape(newWidth, newHeight);
}
void FadeRenderer::onKeyDown(unsigned char key, int x, int y) {
target_->onKeyDown(key, x, y);
}
void FadeRenderer::onKeyUp(unsigned char key, int x, int y) {
target_->onKeyUp(key, x, y);
}
void FadeRenderer::onSpecialKeyDown(int key, int x, int y) {
target_->onSpecialKeyDown(key, x, y);
}
void FadeRenderer::onSpecialKeyUp(int key, int x, int y) {
target_->onSpecialKeyUp(key, x, y);
}
bool FadeRenderer::shouldKeysRepeat() const {
return target_->shouldKeysRepeat();
}
const Renderer& FadeRenderer::getRenderer() const {
return *target_;
}