-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
101 lines (82 loc) · 1.71 KB
/
Copy pathmain.cpp
File metadata and controls
101 lines (82 loc) · 1.71 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
#include "main.hpp"
#include "keys.hpp"
#include "geometry.hpp"
#include "scene.hpp"
#include <cstdlib>
#include <iostream>
namespace
{
bool in_main_loop=false;
float tick_time=0;
int old_time=0;
void
display_func()
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
render_scene();
glutSwapBuffers();
}
void
idle_func()
{
if(!old_time)
{
old_time=glutGet(GLUT_ELAPSED_TIME);
}
else
{
int const i=glutGet(GLUT_ELAPSED_TIME);
tick_time=(i-old_time)/1000.0f;
old_time=i;
}
tick_scene();
tick_keys();
glutPostRedisplay();
}
void
reshape_func(int const w, int const h)
{
glViewport(0, 0, w, h);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
//gluPerspective(30, static_cast<float>(w)/h, 1.0, 100.0);
gluPerspective(45.0, static_cast<float>(w)/h, 0.1, 1000);
glMatrixMode(GL_MODELVIEW);
}
}
float
randf()
{
return std::abs(std::rand())/static_cast<float>(RAND_MAX);
}
float
get_time()
{
return tick_time;
}
int main(int argc, char** argv)
{
srand(time(0));
glutInitWindowSize(800, 600);
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE /*| GLUT_ALPHA */| GLUT_DEPTH| GLUT_ALPHA);
glutCreateWindow("Planeten");
glutSetCursor(GLUT_CURSOR_NONE);
init_keys();
init_geometry();
init_scene();
glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
glutReshapeFunc(reshape_func);
glutIdleFunc(idle_func);
glutDisplayFunc(display_func);
// glutCloseFunc gibts hier nicht :(
in_main_loop=true;
glutMainLoop();
}
void
error(char const*const what)
{
std::cerr << what << std::endl;
// glutLeaveMainLoop gibts hier auch nicht :(
exit(0);
}