-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathFreeGlutGLView.cpp
More file actions
executable file
·181 lines (140 loc) · 3.52 KB
/
FreeGlutGLView.cpp
File metadata and controls
executable file
·181 lines (140 loc) · 3.52 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
//#include "FreeGlutGLView.hpp"
#include "Aluminum/Includes.hpp"
#include <iostream>
#include <sys/time.h>
//namespace Aluminum {
int width;
int height;
RendererLinux* renderer;
//static struct timeval lastTime;
static std::clock_t lastTime = std::clock();
FreeGlutGLView::FreeGlutGLView() {}
void reshape(GLint _w, GLint _h) {
width = _w;
height = _h;
renderer->width = width;
renderer->height = height;
glViewport(0,0,width,height);
printf("in reshape: %d %d\n", width, height);
GLuint bbb;
glGenVertexArrays(1, &bbb);
}
void display() {
renderer->tick();
//printf("in FreeGlutGLView : display()\n");
renderer->onFrame();
glutSwapBuffers();
}
void animate() {
renderer->frameCount++;
/*
time = glutGet(GLUT_ELAPSED_TIME);
if (time - timebase > 1000) {
printf("FPS:%4.2f\n",
renderer->frameCount*1000.0 / (time - timebase));
timebase = time;
renderer->frameCount = 0;
}
*/
/*
float dt;
struct timeval now;
gettimeofday(&now, NULL);
dt = (float)(now.tv_usec - lastTime.tv_usec);
lastTime = now;
*/
glutPostRedisplay();
}
void pressed(int button, int state, int x, int y ) {
// printf("button : %d %d %d %d\n", button, state, x, y);
//check state to see if sending down or up...
renderer->mouseDown(x,y);
}
void dragged(int x, int y ) {
// printf("motion : %d %d\n", x, y);
renderer->mouseDragged(x,y);
}
void moved(int x, int y ) {
// printf("motion : %d %d\n", x, y);
renderer->mouseMoved(x,y);
}
void keyboard(unsigned char key, int x, int y) {
renderer->keyboard(key,x,y);
switch(key) {
case 27:
exit(0);
break;
case '1':
printf("you pressed the number 1!\n");
glutFullScreen();
break;
case '2':
glutReshapeWindow(400,400);
break;
default:
printf("you pressed %c\n", key);
break;
}
printf("done pressing...\n");
}
void specialkeys(int key, int x, int y) {
renderer->specialkeys(key,x,y);
switch (key) {
case GLUT_KEY_UP:
std::cout << "UP\n";
break;
case GLUT_KEY_DOWN:
std::cout << "DOWN\n";
break;
case GLUT_KEY_RIGHT:
std::cout << "RIGHT\n";
break;
case GLUT_KEY_LEFT:
std::cout << "LEFT\n";
break;
}
}
FreeGlutGLView* FreeGlutGLView::start(void* _renderer) {
return FreeGlutGLView::start(_renderer, "allomin");
}
FreeGlutGLView* FreeGlutGLView::start(void* _renderer, std::string name) {
renderer = (RendererLinux*) _renderer;
/* annoying useless setup for glutInit */
char* argv[] = {strdup(name.c_str())};
int argc = 1;
glutInit(&argc, argv);
glutInitContextVersion(3,2);
//glutInitContextVersion(4,4);
glutInitContextFlags(GLUT_CORE_PROFILE | GLUT_DEBUG);
glutInitDisplayMode(GLUT_RGBA | GLUT_DOUBLE);
/*
glutInitDisplayMode(GLUT_RGBA | GLUT_DOUBLE | GLUT_MULTISAMPLE );
GLint buf, sample;
glGetIntegerv (GL_SAMPLE_BUFFERS, &buf);
glGetIntegerv (GL_SAMPLES, &sample);
std::cout << "buf: " << buf << " samples: " << sample << " \n";
glEnable(GL_MULTISAMPLE);
*/
glutInitWindowSize(200,200);
glutCreateWindow(name.c_str());
// glutGameModeString("1280x1024:32@60");
// glutEnterGameMode();
renderer->setStartTick();
renderer->onCreate();
glutDisplayFunc(&display);
glutReshapeFunc(&reshape);
glutKeyboardFunc(&keyboard);
glutSpecialFunc(&specialkeys);
glutMouseFunc(&pressed);
glutMotionFunc(&dragged);
glutPassiveMotionFunc(&moved);
glutIdleFunc(&animate);
//gettimeofday(&lastTime, NULL);
glutMainLoop();
//glutInitDisplayMode(GL_RGBA);
//glutInitWindowSize(200,200);
//glutCreateWindow("test");
return NULL;
//return glView;
}
//}