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