rev |
line source |
nuclear@0
|
1 #include <stdlib.h>
|
nuclear@0
|
2 #include "opengl.h"
|
nuclear@0
|
3
|
nuclear@0
|
4 #ifdef __APPLE__
|
nuclear@0
|
5 #include <GLUT/glut.h>
|
nuclear@0
|
6 #else
|
nuclear@0
|
7 #include <GL/glut.h>
|
nuclear@0
|
8 #endif
|
nuclear@0
|
9
|
nuclear@0
|
10 #include "app.h"
|
nuclear@0
|
11
|
nuclear@0
|
12 static void display();
|
nuclear@0
|
13 static void reshape(int x, int y);
|
nuclear@0
|
14 static void key_down(unsigned char key, int x, int y);
|
nuclear@0
|
15 static void key_up(unsigned char key, int x, int y);
|
nuclear@0
|
16 static void mouse(int bn, int state, int x, int y);
|
nuclear@0
|
17 static void motion(int x, int y);
|
nuclear@2
|
18 static void sball_motion(int x, int y, int z);
|
nuclear@2
|
19 static void sball_rotate(int x, int y, int z);
|
nuclear@2
|
20 static void sball_button(int bn, int state);
|
nuclear@0
|
21
|
nuclear@0
|
22 static int win_width, win_height;
|
nuclear@0
|
23 static unsigned int mod;
|
nuclear@0
|
24
|
nuclear@0
|
25 int main(int argc, char **argv)
|
nuclear@0
|
26 {
|
nuclear@0
|
27 glutInit(&argc, argv);
|
nuclear@0
|
28
|
nuclear@0
|
29 glutInitWindowSize(1280, 720);
|
nuclear@0
|
30 glutInitDisplayMode(GLUT_RGB | GLUT_DEPTH | GLUT_DOUBLE);
|
nuclear@0
|
31 glutCreateWindow("VR file manager");
|
nuclear@0
|
32
|
nuclear@0
|
33 glutDisplayFunc(display);
|
nuclear@0
|
34 glutReshapeFunc(reshape);
|
nuclear@0
|
35 glutKeyboardFunc(key_down);
|
nuclear@0
|
36 glutKeyboardUpFunc(key_up);
|
nuclear@0
|
37 glutMouseFunc(mouse);
|
nuclear@0
|
38 glutMotionFunc(motion);
|
nuclear@0
|
39 glutPassiveMotionFunc(motion);
|
nuclear@2
|
40 glutSpaceballMotionFunc(sball_motion);
|
nuclear@2
|
41 glutSpaceballRotateFunc(sball_rotate);
|
nuclear@2
|
42 glutSpaceballButtonFunc(sball_button);
|
nuclear@0
|
43
|
nuclear@0
|
44 if(app_init() == -1) {
|
nuclear@0
|
45 return 1;
|
nuclear@0
|
46 }
|
nuclear@0
|
47
|
nuclear@0
|
48 glutMainLoop();
|
nuclear@0
|
49 return 0;
|
nuclear@0
|
50 }
|
nuclear@0
|
51
|
nuclear@0
|
52 void swap_buffers()
|
nuclear@0
|
53 {
|
nuclear@0
|
54 glutSwapBuffers();
|
nuclear@0
|
55 }
|
nuclear@0
|
56
|
nuclear@0
|
57 void redisplay()
|
nuclear@0
|
58 {
|
nuclear@0
|
59 glutPostRedisplay();
|
nuclear@0
|
60 }
|
nuclear@0
|
61
|
nuclear@0
|
62 void quit()
|
nuclear@0
|
63 {
|
nuclear@0
|
64 app_shutdown();
|
nuclear@0
|
65 exit(0);
|
nuclear@0
|
66 }
|
nuclear@0
|
67
|
nuclear@0
|
68 void get_window_size(int *xsz, int *ysz)
|
nuclear@0
|
69 {
|
nuclear@0
|
70 *xsz = win_width;
|
nuclear@0
|
71 *ysz = win_height;
|
nuclear@0
|
72 }
|
nuclear@0
|
73
|
nuclear@0
|
74 unsigned int get_modifiers()
|
nuclear@0
|
75 {
|
nuclear@0
|
76 return mod;
|
nuclear@0
|
77 }
|
nuclear@0
|
78
|
nuclear@0
|
79 static void display()
|
nuclear@0
|
80 {
|
nuclear@0
|
81 app_display();
|
nuclear@0
|
82 }
|
nuclear@0
|
83
|
nuclear@0
|
84 static void reshape(int x, int y)
|
nuclear@0
|
85 {
|
nuclear@0
|
86 win_width = x;
|
nuclear@0
|
87 win_height = y;
|
nuclear@0
|
88 app_reshape(x, y);
|
nuclear@0
|
89 }
|
nuclear@0
|
90
|
nuclear@0
|
91 static void key_down(unsigned char key, int x, int y)
|
nuclear@0
|
92 {
|
nuclear@0
|
93 mod = glutGetModifiers();
|
nuclear@0
|
94 app_keyboard(key, true, x, y);
|
nuclear@0
|
95 }
|
nuclear@0
|
96
|
nuclear@0
|
97 static void key_up(unsigned char key, int x, int y)
|
nuclear@0
|
98 {
|
nuclear@0
|
99 mod = glutGetModifiers();
|
nuclear@0
|
100 app_keyboard(key, false, x, y);
|
nuclear@0
|
101 }
|
nuclear@0
|
102
|
nuclear@0
|
103 static void mouse(int bn, int state, int x, int y)
|
nuclear@0
|
104 {
|
nuclear@0
|
105 mod = glutGetModifiers();
|
nuclear@0
|
106 app_mouse_button(bn - GLUT_LEFT_BUTTON, state == GLUT_DOWN ? 1 : 0, x, y);
|
nuclear@0
|
107 }
|
nuclear@0
|
108
|
nuclear@0
|
109 static void motion(int x, int y)
|
nuclear@0
|
110 {
|
nuclear@0
|
111 app_mouse_motion(x, y);
|
nuclear@0
|
112 }
|
nuclear@2
|
113
|
nuclear@2
|
114 static void sball_motion(int x, int y, int z)
|
nuclear@2
|
115 {
|
nuclear@2
|
116 app_sball_motion(x / 1000.0f, y / 1000.0f, z / 1000.0f);
|
nuclear@2
|
117 }
|
nuclear@2
|
118
|
nuclear@2
|
119 static void sball_rotate(int x, int y, int z)
|
nuclear@2
|
120 {
|
nuclear@2
|
121 app_sball_rotate(x / 1800.0f, y / 1800.0f, z / 1800.0f);
|
nuclear@2
|
122 }
|
nuclear@2
|
123
|
nuclear@2
|
124 static void sball_button(int bn, int state)
|
nuclear@2
|
125 {
|
nuclear@2
|
126 app_sball_button(bn, state == GLUT_DOWN);
|
nuclear@2
|
127 }
|