forked from lquatrin/cpp_volume_rendering
-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathapp_freeglut.cpp
More file actions
189 lines (156 loc) · 4.61 KB
/
Copy pathapp_freeglut.cpp
File metadata and controls
189 lines (156 loc) · 4.61 KB
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
#include "app_freeglut.h"
#ifdef USING_FREEGLUT
#include "renderingmanager.h"
#include <GL/wglew.h>
void ApplicationFreeGLUT::glutSwapBuffer (void* data)
{
glutSwapBuffers();
}
void ApplicationFreeGLUT::Display (void)
{
RenderingManager::Instance()->Display();
}
void ApplicationFreeGLUT::s_Reshape (int w, int h)
{
RenderingManager::Instance()->Reshape(w, h);
// ImGui callback
ImGui_ImplGLUT_ReshapeFunc(w, h);
}
void ApplicationFreeGLUT::s_Keyboard (unsigned char key, int x, int y)
{
switch (key)
{
case 27:
RenderingManager::Instance()->DestroyInstance();
exit(EXIT_FAILURE);
return;
default:
break;
}
RenderingManager::Instance()->Keyboard(key, x, y);
// ImGui callback
ImGui_ImplGLUT_KeyboardFunc(key, x, y);
}
void ApplicationFreeGLUT::s_KeyboardUp (unsigned char c, int x, int y)
{
RenderingManager::Instance()->KeyboardUp(c, x, y);
// ImGui callback
ImGui_ImplGLUT_KeyboardUpFunc(c, x, y);
}
void ApplicationFreeGLUT::s_OnMouse (int glut_button, int state, int x, int y)
{
RenderingManager::Instance()->MouseButton(glut_button, state, x, y);
// ImGui callback
ImGui_ImplGLUT_MouseFunc(glut_button, state, x, y);
}
void ApplicationFreeGLUT::s_OnMotion (int x, int y)
{
// ImGui callback
ImGui_ImplGLUT_MotionFunc(x, y);
// If is modifying an imgui widget
if (!ImGui::IsAnyWindowFocused())
RenderingManager::Instance()->MouseMotion(x, y);
}
void ApplicationFreeGLUT::s_MouseWheel (int wheel, int direction, int x, int y)
{
RenderingManager::Instance()->MouseWheel(wheel, direction, x, y);
// ImGui callback
ImGui_ImplGLUT_MouseWheelFunc(wheel, direction, x, y);
}
void ApplicationFreeGLUT::s_SpecialFunc (int key, int x, int y)
{
// ImGui callback
ImGui_ImplGLUT_SpecialFunc(key, x, y);
}
void ApplicationFreeGLUT::s_SpecialUpFunc (int key, int x, int y)
{
// ImGui callback
ImGui_ImplGLUT_SpecialUpFunc(key, x, y);
}
void ApplicationFreeGLUT::s_PassiveMotionFunc (int x, int y)
{
// ImGui callback
ImGui_ImplGLUT_MotionFunc(x, y);
}
void ApplicationFreeGLUT::s_CloseFunc ()
{
RenderingManager::Instance()->DestroyInstance();
}
void ApplicationFreeGLUT::s_IdleFunc ()
{
RenderingManager::Instance()->IdleFunc();
}
ApplicationFreeGLUT::ApplicationFreeGLUT ()
{
}
ApplicationFreeGLUT::~ApplicationFreeGLUT ()
{
}
bool ApplicationFreeGLUT::Init (int argc, char** argv)
{
glutInit(&argc, argv);
#ifdef __FREEGLUT_EXT_H__
glutSetOption(GLUT_ACTION_ON_WINDOW_CLOSE, GLUT_ACTION_GLUTMAINLOOP_RETURNS);
#endif
glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGBA | GLUT_DEPTH | GLUT_STENCIL | GLUT_ALPHA);
glutInitWindowSize(RenderingManager::Instance()->GetScreenWidth(),
RenderingManager::Instance()->GetScreenHeight());
glutCreateWindow("CppVolRend [FreeGLUT]");
if (glewInit() != GLEW_OK)
{
printf("Glew didn't initialized!\n");
exit(EXIT_FAILURE);
}
printf("Running OpenGL %s\n\n", glGetString(GL_VERSION));
// Setup GLUT display function
glutDisplayFunc(ApplicationFreeGLUT::Display);
glutReshapeFunc(ApplicationFreeGLUT::s_Reshape);
glutKeyboardFunc(ApplicationFreeGLUT::s_Keyboard);
glutKeyboardUpFunc(ApplicationFreeGLUT::s_KeyboardUp);
glutMouseFunc(ApplicationFreeGLUT::s_OnMouse);
glutMotionFunc(ApplicationFreeGLUT::s_OnMotion);
#ifdef __FREEGLUT_EXT_H__
glutMouseWheelFunc(ApplicationFreeGLUT::s_MouseWheel);
#endif
glutSpecialFunc(ApplicationFreeGLUT::s_SpecialFunc);
glutSpecialUpFunc(ApplicationFreeGLUT::s_SpecialUpFunc);
glutPassiveMotionFunc(ApplicationFreeGLUT::s_PassiveMotionFunc);
glutCloseFunc(ApplicationFreeGLUT::s_CloseFunc);
glutIdleFunc(ApplicationFreeGLUT::s_IdleFunc);
RenderingManager::Instance()->f_swapbuffer = ApplicationFreeGLUT::glutSwapBuffer;
// VSYNC
if (wglGetSwapIntervalEXT() > 0)
wglSwapIntervalEXT(1);
return true;
}
bool ApplicationFreeGLUT::InitImGui ()
{
// Setup Dear ImGui context
IMGUI_CHECKVERSION();
ImGui::CreateContext();
ImGuiIO& io = ImGui::GetIO(); (void)io;
//io.ConfigFlags |= ImGuiConfigFlags_NavEnableKeyboard; // Enable Keyboard Controls
//io.ConfigFlags |= ImGuiConfigFlags_NavEnableGamepad; // Enable Gamepad Controls
// Setup Dear ImGui style
ImGui::StyleColorsDark();
//ImGui::StyleColorsClassic();
// Setup Platform/Renderer bindings
ImGui_ImplGLUT_Init();
// . Not install funcs for manual callback
//ImGui_ImplGLUT_InstallFuncs();
ImGui_ImplOpenGL2_Init();
return true;
}
void ApplicationFreeGLUT::MainLoop ()
{
glutMainLoop();
}
void ApplicationFreeGLUT::ImGuiDestroy ()
{
ImGui_ImplOpenGL2_Shutdown();
ImGui_ImplGLUT_Shutdown();
ImGui::DestroyContext();
}
void ApplicationFreeGLUT::Destroy ()
{}
#endif