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@17: #define ASPECT 1 eleni@17: 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@17: static unsigned int drawing; eleni@17: static unsigned int debugging; eleni@14: static unsigned char tex; eleni@13: static bool show; eleni@13: eleni@2: static void cleanup(); eleni@17: static void init(); 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@17: init(); 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@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@17: glCallList(drawing); eleni@17: if(show) eleni@17: glCallList(debugging); eleni@14: eleni@17: glFlush(); 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: } eleni@17: eleni@17: static void init() eleni@17: { eleni@17: glClearColor(1, 1, 1, 1); eleni@17: eleni@17: frame = new Frame; eleni@17: if(!(tex = load_texture(filename))) { eleni@17: fprintf(stderr, "Failed to load texture: %s\n", filename); eleni@17: exit(1); eleni@17: } eleni@17: eleni@18: /* drawing */ eleni@17: drawing = glGenLists(1); eleni@17: glNewList(drawing, GL_COMPILE); eleni@17: glMatrixMode(GL_MODELVIEW); eleni@17: glPushMatrix(); eleni@17: glTranslatef(0, 0, -24); eleni@17: glEnable(GL_TEXTURE_2D); eleni@17: glBindTexture(GL_TEXTURE_2D, tex); eleni@17: draw_tess_quad(-14, -14 * 1/ASPECT, 28, 28 * 1 / ASPECT, 850, 850 * 1 / ASPECT); eleni@17: glDisable(GL_TEXTURE_2D); eleni@17: glPopMatrix(); eleni@17: glMatrixMode(GL_MODELVIEW); eleni@17: glEndList(); eleni@17: eleni@18: /* debugging */ eleni@17: debugging = glGenLists(1); eleni@17: glNewList(debugging, GL_COMPILE); eleni@17: glEnable(GL_TEXTURE_2D); eleni@17: glBindTexture(GL_TEXTURE_2D, frame->video_tex); eleni@17: draw_tess_quad(-1, -1, 1, 2, 1, 1, true); eleni@17: glBindTexture(GL_TEXTURE_2D, frame->depth_tex); eleni@17: draw_tess_quad(0, -1, 1, 2, 1, 1, true); eleni@17: glDisable(GL_TEXTURE_2D); eleni@17: glEndList(); eleni@17: }