-
Notifications
You must be signed in to change notification settings - Fork 0
/
widget.hpp
58 lines (50 loc) · 1.33 KB
/
widget.hpp
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
#pragma once
#include <GL/glew.h>
#include <GL/glut.h>
#include <GL/freeglut.h>
typedef void (*Function)();
typedef void (*Function2)(int, int);
typedef void (*Function3)(int, int, int, int);
class widget_t {
public:
void init(
int* argc, char** argv,
int width, int height, int pos_x, int pos_y,
const char* window_name,
Function display, Function2 reshape,
Function3 mouse = nullptr, Function3 mouseWheel = nullptr);
void flush();
void loop();
};
#if defined(WIDGET_IMPL) || defined(ALL_IMPL)
void widget_t::init(
int* argc, char** argv,
int width, int height,
int pos_x, int pos_y,
const char* window_name,
Function display,
Function2 reshape,
Function3 mouse = nullptr,
Function3 mouseWheel = nullptr)
{
glutInit(argc, argv);
glutInitDisplayMode(GLUT_RGBA | GLUT_DOUBLE | GLUT_DEPTH | GLUT_MULTISAMPLE);
glutInitWindowSize(width, height);
glutInitWindowPosition(pos_x, pos_y);
glutCreateWindow(window_name);
glewInit();
glutDisplayFunc(display);
glutReshapeFunc(reshape);
if (mouse != nullptr)
glutMouseFunc(mouse);
if (mouseWheel != nullptr)
glutMouseWheelFunc(mouseWheel);
}
void widget_t::flush()
{
glutSwapBuffers();
glutPostRedisplay();
}
inline void widget_t::loop()
{glutMainLoop();}
#endif