-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGLCallback.cpp.bak
197 lines (161 loc) · 4.15 KB
/
GLCallback.cpp.bak
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
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
#include "GLCallback.h"
#ifdef USE_GLEW
#include <GL/glew.h> // IMPORTANT, must be declared before freeglut !
#endif
#include <GL/freeglut.h>
#include <stdio.h>
using namespace GLScene;
// The GLScene entry point for the GLUT callback events
GLCallBack* _pGLCallBack = NULL;
// Error
static void OnError(const char *fmt, va_list ap)
{
_pGLCallBack->OnError(fmt, ap);
}
/// Display events
static void OnDisplay(void)
{
_pGLCallBack->OnDisplay();
}
static void OnReshape(int width, int height)
{
_pGLCallBack->OnReshape(width, height);
}
static void OnClose(void)
{
_pGLCallBack->OnClose();
}
static void OnIdle(void)
{
_pGLCallBack->OnIdle();
}
static void OnTimer(int id)
{
_pGLCallBack->OnTimer(id);
glutTimerFunc(_pGLCallBack->TimerStepms, OnTimer, id);
}
/// IHM events
static void OnkeyEnter(unsigned char key, int x, int y)
{
_pGLCallBack->OnkeyEnter(key, x, y);
}
static void OnkeyEnterUp(unsigned char key, int x, int y)
{
_pGLCallBack->OnkeyEnterUp(key, x, y);
}
static void OnSpecialKey(int key, int x, int y)
{
_pGLCallBack->OnSpecialKey(key, x, y);
}
static void OnSpecialKeyUp(int key, int x, int y)
{
_pGLCallBack->OnSpecialKeyUp(key, x, y);
}
static void OnMouseEnter(int state)
{
_pGLCallBack->OnMouseEnter(state);
}
static void OnMouseClick(int button, int updown, int x, int y)
{
_pGLCallBack->OnMouseClick(button, updown, x, y);
}
static void OnMouseMove(int x, int y)
{
_pGLCallBack->OnMouseMove(x, y);
}
static void OnMousePassiveMove(int x, int y)
{
_pGLCallBack->OnMousePassiveMove(x, y);
}
static void OnMouseWheel(int wheel, int direction, int x, int y)
{
_pGLCallBack->OnMouseWheel(wheel, direction, x, y);
}
static void OnMenuEntry(int value)
{
_pGLCallBack->OnMenuEntry(value);
}
// Callback for the sub window
static void OnSubDisplay(void)
{
_pGLCallBack->OnSubDisplay();
}
/**
* Forwarding the GLUT callback
*/
void GLScene::InitCallbacks(GLCallBack* _pGLScene)
{
_pGLCallBack = _pGLScene;
// Error
glutInitErrorFunc(OnError);
// Display events
glutDisplayFunc(OnDisplay);
glutReshapeFunc(OnReshape);
glutCloseFunc(OnClose);
glutIdleFunc(OnIdle);
// Keyboard events
glutKeyboardFunc(OnkeyEnter);
glutKeyboardUpFunc(OnkeyEnterUp);
glutSpecialFunc(OnSpecialKey);
glutSpecialUpFunc(OnSpecialKeyUp);
// Mouse events
glutEntryFunc(OnMouseEnter);
glutMouseFunc(OnMouseClick);
glutMotionFunc(OnMouseMove);
glutPassiveMotionFunc(OnMousePassiveMove);
glutMouseWheelFunc(OnMouseWheel);
glutTimerFunc(_pGLScene->TimerStepms, OnTimer, _pGLScene->Get_Window_ID());
}
void GLScene::InitSubCallbacks(GLCallBack* _pGLScene)
{
_pGLCallBack = _pGLScene;
// Error
glutInitErrorFunc(OnError);
// Display events
glutDisplayFunc(OnSubDisplay);
// glutReshapeFunc(OnSubReshape);
// Keyboard events
// glutKeyboardFunc(OnSubkeyEnter);
// glutKeyboardUpFunc(OnSubkeyEnter);
// glutSpecialFunc(OnSubSpecialKey);
// glutSpecialUpFunc(OnSubSpecialKey);
// Mouse events
// glutEntryFunc(OnSubMouseEnter);
// glutMouseFunc(OnSubMouseClick);
// glutMotionFunc(OnSubMouseMove);
// glutPassiveMotionFunc(OnSubMousePassiveMove);
// glutMouseWheelFunc(OnSubMouseWheel);
}
int GLScene::InitCallbackMenu(GLCallBack* _pGLScene)
{
_pGLCallBack = _pGLScene;
return glutCreateMenu(OnMenuEntry);
}
/**
* GLEW Initialization
*/
#ifdef USE_GLEW
void GLScene::InitGlew()
{
static bool glewInitialized = false;
if (!glewInitialized)
{
glewInitialized = true;
glewExperimental = true;
GLenum err = glewInit();
if (GLEW_OK != err) {
// Problem: glewInit failed, something is seriously wrong !
fprintf(stderr, "GLEW: ERROR: GLEW initialization failed! We're going to keep going anyways, but we will most likely crash.\n");
fprintf(stderr, "GLEW: ERROR: %s\n", glewGetErrorString(err));
}
fprintf(stdout, "GLEW: Using GLEW %s\n", glewGetString(GLEW_VERSION));
}
}
const char *GLScene::GetGlewVersion()
{
return (const char *)glewGetString(GLEW_VERSION);
}
#endif
// ********************************************************************************
// End of file
// ********************************************************************************