-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcopengl.cpp
132 lines (104 loc) · 3.13 KB
/
copengl.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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
#include "copengl.h"
namespace VSTGUI {
TestOpenGLView::TestOpenGLView(const CRect& size) : COpenGLView(size) {
xRotation = yRotation = zRotation = 0.f;
}
bool TestOpenGLView::attached(CView* parent)
{
if (COpenGLView::attached(parent))
{
updateViewPort();
remember();
addAnimation("XRotation", this, new Animation::RepeatTimingFunction(new Animation::LinearTimingFunction(4000), -1, false));
remember();
addAnimation("YRotation", this, new Animation::RepeatTimingFunction(new Animation::LinearTimingFunction(6000), -1, false));
remember();
addAnimation("ZRotation", this, new Animation::RepeatTimingFunction(new Animation::LinearTimingFunction(8000), -1, false));
return true;
}
return false;
}
bool TestOpenGLView::removed(CView* parent)
{
return COpenGLView::removed(parent);
}
void TestOpenGLView::setViewSize(const CRect& rect, bool invalid = true)
{
COpenGLView::setViewSize(rect, invalid);
updateViewPort();
}
void TestOpenGLView::parentSizeChanged()
{
COpenGLView::parentSizeChanged();
updateViewPort();
}
void TestOpenGLView::updateViewPort()
{
platformGLview = getPlatformOpenGLView();
if (platformGLview)
{
platformGLview->lockContext();
platformGLview->makeContextCurrent();
glEnable(GL_DEPTH_TEST);
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
CRect r(getViewSize());
glViewport(0, 0, r.getWidth(), r.getHeight());
glClearColor(0, 0, 0, 0);
platformGLview->unlockContext();
}
}
void TestOpenGLView::drawOpenGL(const CRect& updateRect)
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glScaled(0.5, 0.5, 0.2);
glRotated(xRotation, 1, 0, 0);
glRotated(yRotation, 0, 1, 0);
glRotated(zRotation, 0, 0, 1);
glBegin(GL_TRIANGLES);
glColor4f(0.0f, 0.0f, 1.0f, 0.5f);
glVertex3f(0.0f, 1.0f, 0.0f);
glVertex3f(-1.0f, -1.0f, 1.0f);
glVertex3f(1.0f, -1.0f, 1.0f);
glColor4f(1.0f, 0.0f, 0.0f, 0.5f);
glVertex3f(0.0f, 1.0f, 0.0f);
glVertex3f(1.0f, -1.0f, 1.0f);
glVertex3f(1.0f, -1.0f, -1.0f);
glColor4f(0.0f, 1.0f, 0.0f, 0.5f);
glVertex3f(0.0f, 1.0f, 0.0f);
glVertex3f(1.0f, -1.0f, -1.0f);
glVertex3f(-1.0f, -1.0f, -1.0f);
glColor4f(1.0f, 1.0f, 0.0f, 0.5f);
glVertex3f(0.0f, 1.0f, 0.0f);
glVertex3f(-1.0f, -1.0f, -1.0f);
glVertex3f(-1.0f, -1.0f, 1.0f);
glEnd();
glBegin(GL_QUADS);
glColor4f(0.5f, 0.5f, 0.5f, 0.9f);
glVertex3f(-1.f, -1.f, 1.f);
glVertex3f(1.f, -1.f, 1.f);
glVertex3f(1.f, -1.f, -1.f);
glVertex3f(-1.f, -1.f, -1.f);
glEnd();
glFlush();
if (platformGLview) {
platformGLview->swapBuffers();
}
}
void TestOpenGLView::animationStart(CView* view, IdStringPtr name) {}
void TestOpenGLView::animationTick(CView* view, IdStringPtr name, float pos)
{
if (strcmp(name, "XRotation") == 0)
xRotation = pos * 360.f;
else if (strcmp(name, "ZRotation") == 0)
zRotation = pos * 360.f;
else if (strcmp(name, "YRotation") == 0)
yRotation = pos * 360.f;
invalid();
}
void TestOpenGLView::animationFinished(CView* view, IdStringPtr name, bool wasCanceled) {}
}