eleni@2: #include eleni@2: #include eleni@0: #include eleni@0: eleni@2: #include eleni@2: eleni@0: #include "kinect.h" eleni@2: #include "frame.h" eleni@0: eleni@0: freenect_context *kin_ctx; eleni@0: freenect_device *kin_dev; eleni@0: KinectParams kin_params; eleni@2: Frame *frame; eleni@0: eleni@2: static void cleanup(); eleni@2: eleni@2: static void display(); eleni@2: static void reshape(int w, int h); eleni@2: static void keyb(unsigned char key, int x, int y); eleni@2: static void idle(); eleni@2: eleni@2: bool has_video; eleni@2: bool has_depth; eleni@2: eleni@2: int main(int argc, char **argv) eleni@0: { eleni@0: if(!init_kinect(&kin_ctx, &kin_dev, &kin_params)) eleni@0: return 1; eleni@0: eleni@2: if(!init_kinect_frames(&kin_ctx, &kin_dev, &kin_params)) { eleni@2: stop_kinect(kin_ctx, kin_dev); eleni@2: return 1; eleni@2: } eleni@2: eleni@2: glutInitWindowSize(800, 600); eleni@2: glutInit(&argc, argv); eleni@2: glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB); eleni@2: glutCreateWindow("Test Kinect"); eleni@2: eleni@2: glewInit(); eleni@2: eleni@2: glutDisplayFunc(display); eleni@2: glutReshapeFunc(reshape); eleni@2: glutKeyboardFunc(keyb); eleni@2: glutIdleFunc(idle); eleni@2: eleni@2: glClearColor(1, 1, 1, 1); eleni@4: frame = new Frame(); eleni@2: eleni@2: atexit(cleanup); eleni@2: glutMainLoop(); eleni@2: } eleni@2: eleni@2: static void display() eleni@2: { eleni@2: glClear(GL_COLOR_BUFFER_BIT); eleni@2: eleni@2: glMatrixMode(GL_MODELVIEW); eleni@2: glLoadIdentity(); eleni@2: eleni@2: glClearColor(1, 0, 0, 1); eleni@2: eleni@2: has_depth = false; has_video = false; eleni@2: eleni@2: if(freenect_process_events(kin_ctx) != 0) { eleni@2: fprintf(stderr, "Failed to process events.\n"); eleni@2: exit(0); eleni@2: } eleni@2: frame->process(); eleni@2: eleni@2: glutSwapBuffers(); eleni@2: } eleni@2: eleni@2: static void reshape(int w, int h) eleni@2: { eleni@2: glViewport(0, 0, (GLsizei) w, (GLsizei) h); eleni@2: glMatrixMode(GL_PROJECTION); eleni@2: glLoadIdentity(); eleni@2: gluPerspective(45, (float)w / (float)h, 1, 1000); eleni@2: } eleni@2: eleni@2: static void keyb(unsigned char key, int x, int y) eleni@2: { eleni@2: switch(key) { eleni@2: case 27: eleni@2: exit(0); eleni@2: default: eleni@2: break; eleni@2: } eleni@2: } eleni@2: eleni@2: static void idle() eleni@2: { eleni@2: glutPostRedisplay(); eleni@2: } eleni@2: eleni@2: static void cleanup() eleni@2: { eleni@2: stop_kinect_frames(kin_dev); eleni@0: stop_kinect(kin_ctx, kin_dev); eleni@0: }