eleni@2: #include eleni@2: #include eleni@12: eleni@0: #include eleni@0: eleni@0: #include "kinect.h" eleni@2: #include "frame.h" eleni@12: #include "tesquad.h" eleni@14: #include "texture.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@14: static const char *filename = "data/textures/wallpaper.jpg"; eleni@14: static unsigned char tex; eleni@13: static bool show; eleni@13: 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@7: 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@14: atexit(cleanup); eleni@14: eleni@2: glClearColor(1, 1, 1, 1); eleni@14: eleni@12: frame = new Frame; eleni@14: if(!(tex = load_texture(filename))) { eleni@14: fprintf(stderr, "Failed to load texture: %s\n", filename); eleni@14: exit(1); eleni@14: } eleni@2: eleni@2: glutMainLoop(); eleni@2: } eleni@2: eleni@2: static void display() eleni@2: { eleni@14: glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); eleni@2: eleni@2: glMatrixMode(GL_MODELVIEW); eleni@2: glLoadIdentity(); eleni@14: glClearColor(1, 1, 1, 1); eleni@2: eleni@2: has_depth = false; has_video = false; 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@12: glEnable(GL_TEXTURE_2D); eleni@14: glBindTexture(GL_TEXTURE_2D, tex); eleni@14: draw_tess_quad(-1, -1, 2, 2, 1, 1, true); eleni@14: eleni@13: if(show) { eleni@13: glBindTexture(GL_TEXTURE_2D, frame->video_tex); eleni@14: draw_tess_quad(-1, -1, 1, 1, 1, 1, true); eleni@13: glBindTexture(GL_TEXTURE_2D, frame->depth_tex); eleni@14: draw_tess_quad(-1, 0, 1, 1, 1, 1, true); eleni@13: } eleni@12: glDisable(GL_TEXTURE_2D); eleni@12: 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@13: case 's': eleni@13: if(show) eleni@13: show = false; eleni@13: else eleni@13: show = true; eleni@13: break; 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: }