-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmain.cpp
More file actions
121 lines (103 loc) · 2.92 KB
/
main.cpp
File metadata and controls
121 lines (103 loc) · 2.92 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
#include <cstdio>
#include <GL/freeglut.h>
#include "element.h"
#include "draw.h"
#include "model.h"
using namespace std;
int kbstat[256] = {0};
int mouseButton = 0;
int screenSize = 600;
int screenWidth = 600;
int screenHeight = 600;
// Initialization
void init(){
printf("--------Geometry test 0.0.0--------\n");
printf("OpenGL Version %s\n", glGetString(GL_VERSION));
initDisplay();
initModel();
fflush(stdout);
}
// Timer Callback
void timerCallback(int index){
switch (index) {
case 0:
glutTimerFunc(33, &timerCallback, 0);
update(kbstat);
if (glutGetWindow()) glutPostRedisplay();
break;
}
}
// Keyboard Callback
void keyboardCallback(unsigned char key, int _x, int _y){
switch (key) {
case '\x0D' :
case '\x1B' :
glutLeaveMainLoop();
break;
}
kbstat[key] = 1;
}
void keyboardUpCallback(unsigned char key, int x, int y){
kbstat[key] = 0;
}
// Mouse Callback
void mouseKey(int button, int state, int x, int y){
if (GLUT_DOWN == state) switch (button) {
case GLUT_LEFT_BUTTON:
mouseButton |= LEFT_MOUSE_BUTTON;
break;
case GLUT_MIDDLE_BUTTON:
mouseButton |= MIDDLE_MOUSE_BUTTON;
break;
case GLUT_RIGHT_BUTTON:
mouseButton |= RIGHT_MOUSE_BUTTON;
break;
}
else switch (button) {
case GLUT_LEFT_BUTTON:
mouseButton &= ~LEFT_MOUSE_BUTTON;
break;
case GLUT_MIDDLE_BUTTON:
mouseButton &= ~MIDDLE_MOUSE_BUTTON;
break;
case GLUT_RIGHT_BUTTON:
mouseButton &= ~RIGHT_MOUSE_BUTTON;
break;
}
renewMouseStat((double) 2.0*(x - screenWidth/2.0)/screenSize,
(double) 2.0*(screenHeight/2.0 - y)/screenSize,
mouseButton);
}
void mouseMotion(int x, int y){
renewMouseStat((double) 2.0*(x - screenWidth/2.0)/screenSize,
(double) 2.0*(screenHeight/2.0 - y)/screenSize,
mouseButton);
}
// Close Callback
void closeCallback(){
printf("Closing window.\n");
}
int main(int argc, char *argv[]){
//Window Initialization
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_RGB | GLUT_SINGLE | GLUT_MULTISAMPLE);
glutInitWindowPosition(100, 100);
glutInitWindowSize(screenWidth, screenHeight);
glutCreateWindow("Geometry");
glutSetOption(GLUT_ACTION_ON_WINDOW_CLOSE, GLUT_ACTION_GLUTMAINLOOP_RETURNS);
//Callback function registry
glutDisplayFunc(&display);
glutReshapeFunc(&reshape);
glutKeyboardFunc(&keyboardCallback);
glutKeyboardUpFunc(&keyboardUpCallback);
glutMouseFunc(&mouseKey);
glutMotionFunc(&mouseMotion);
glutPassiveMotionFunc(&mouseMotion);
glutTimerFunc(0, &timerCallback, 0);
glutCloseFunc(&closeCallback);
//Initialization
init();
//Main loop
glutMainLoop();
return 0;
}