rev |
line source |
eleni@2
|
1 #include <GL/glew.h>
|
eleni@2
|
2 #include <GL/glut.h>
|
eleni@0
|
3 #include <stdio.h>
|
eleni@0
|
4
|
eleni@2
|
5 #include <pthread.h>
|
eleni@2
|
6
|
eleni@0
|
7 #include "kinect.h"
|
eleni@2
|
8 #include "frame.h"
|
eleni@0
|
9
|
eleni@0
|
10 freenect_context *kin_ctx;
|
eleni@0
|
11 freenect_device *kin_dev;
|
eleni@0
|
12 KinectParams kin_params;
|
eleni@2
|
13 Frame *frame;
|
eleni@0
|
14
|
eleni@2
|
15 static void cleanup();
|
eleni@2
|
16
|
eleni@2
|
17 static void display();
|
eleni@2
|
18 static void reshape(int w, int h);
|
eleni@2
|
19 static void keyb(unsigned char key, int x, int y);
|
eleni@2
|
20 static void idle();
|
eleni@2
|
21
|
eleni@2
|
22 bool has_video;
|
eleni@2
|
23 bool has_depth;
|
eleni@2
|
24
|
eleni@2
|
25 int main(int argc, char **argv)
|
eleni@0
|
26 {
|
eleni@0
|
27 if(!init_kinect(&kin_ctx, &kin_dev, &kin_params))
|
eleni@0
|
28 return 1;
|
eleni@0
|
29
|
eleni@2
|
30 if(!init_kinect_frames(&kin_ctx, &kin_dev, &kin_params)) {
|
eleni@2
|
31 stop_kinect(kin_ctx, kin_dev);
|
eleni@2
|
32 return 1;
|
eleni@2
|
33 }
|
eleni@2
|
34
|
eleni@2
|
35 glutInitWindowSize(800, 600);
|
eleni@2
|
36 glutInit(&argc, argv);
|
eleni@2
|
37 glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB);
|
eleni@2
|
38 glutCreateWindow("Test Kinect");
|
eleni@2
|
39
|
eleni@2
|
40 glewInit();
|
eleni@2
|
41
|
eleni@2
|
42 glutDisplayFunc(display);
|
eleni@2
|
43 glutReshapeFunc(reshape);
|
eleni@2
|
44 glutKeyboardFunc(keyb);
|
eleni@2
|
45 glutIdleFunc(idle);
|
eleni@2
|
46
|
eleni@2
|
47 glClearColor(1, 1, 1, 1);
|
eleni@4
|
48 frame = new Frame();
|
eleni@2
|
49
|
eleni@2
|
50 atexit(cleanup);
|
eleni@2
|
51 glutMainLoop();
|
eleni@2
|
52 }
|
eleni@2
|
53
|
eleni@2
|
54 static void display()
|
eleni@2
|
55 {
|
eleni@2
|
56 glClear(GL_COLOR_BUFFER_BIT);
|
eleni@2
|
57
|
eleni@2
|
58 glMatrixMode(GL_MODELVIEW);
|
eleni@2
|
59 glLoadIdentity();
|
eleni@2
|
60
|
eleni@2
|
61 glClearColor(1, 0, 0, 1);
|
eleni@2
|
62
|
eleni@2
|
63 has_depth = false; has_video = false;
|
eleni@2
|
64
|
eleni@2
|
65 if(freenect_process_events(kin_ctx) != 0) {
|
eleni@2
|
66 fprintf(stderr, "Failed to process events.\n");
|
eleni@2
|
67 exit(0);
|
eleni@2
|
68 }
|
eleni@2
|
69 frame->process();
|
eleni@2
|
70
|
eleni@2
|
71 glutSwapBuffers();
|
eleni@2
|
72 }
|
eleni@2
|
73
|
eleni@2
|
74 static void reshape(int w, int h)
|
eleni@2
|
75 {
|
eleni@2
|
76 glViewport(0, 0, (GLsizei) w, (GLsizei) h);
|
eleni@2
|
77 glMatrixMode(GL_PROJECTION);
|
eleni@2
|
78 glLoadIdentity();
|
eleni@2
|
79 gluPerspective(45, (float)w / (float)h, 1, 1000);
|
eleni@2
|
80 }
|
eleni@2
|
81
|
eleni@2
|
82 static void keyb(unsigned char key, int x, int y)
|
eleni@2
|
83 {
|
eleni@2
|
84 switch(key) {
|
eleni@2
|
85 case 27:
|
eleni@2
|
86 exit(0);
|
eleni@2
|
87 default:
|
eleni@2
|
88 break;
|
eleni@2
|
89 }
|
eleni@2
|
90 }
|
eleni@2
|
91
|
eleni@2
|
92 static void idle()
|
eleni@2
|
93 {
|
eleni@2
|
94 glutPostRedisplay();
|
eleni@2
|
95 }
|
eleni@2
|
96
|
eleni@2
|
97 static void cleanup()
|
eleni@2
|
98 {
|
eleni@2
|
99 stop_kinect_frames(kin_dev);
|
eleni@0
|
100 stop_kinect(kin_ctx, kin_dev);
|
eleni@0
|
101 }
|