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