invisible

annotate 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
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@2 48
eleni@2 49 atexit(cleanup);
eleni@2 50 glutMainLoop();
eleni@2 51 }
eleni@2 52
eleni@2 53 static void display()
eleni@2 54 {
eleni@2 55 glClear(GL_COLOR_BUFFER_BIT);
eleni@2 56
eleni@2 57 glMatrixMode(GL_MODELVIEW);
eleni@2 58 glLoadIdentity();
eleni@2 59
eleni@2 60 glClearColor(1, 0, 0, 1);
eleni@2 61
eleni@2 62 has_depth = false; has_video = false;
eleni@2 63
eleni@2 64 if(freenect_process_events(kin_ctx) != 0) {
eleni@2 65 fprintf(stderr, "Failed to process events.\n");
eleni@2 66 exit(0);
eleni@2 67 }
eleni@2 68 frame->process();
eleni@2 69
eleni@2 70 glutSwapBuffers();
eleni@2 71 }
eleni@2 72
eleni@2 73 static void reshape(int w, int h)
eleni@2 74 {
eleni@2 75 glViewport(0, 0, (GLsizei) w, (GLsizei) h);
eleni@2 76 glMatrixMode(GL_PROJECTION);
eleni@2 77 glLoadIdentity();
eleni@2 78 gluPerspective(45, (float)w / (float)h, 1, 1000);
eleni@2 79 }
eleni@2 80
eleni@2 81 static void keyb(unsigned char key, int x, int y)
eleni@2 82 {
eleni@2 83 switch(key) {
eleni@2 84 case 27:
eleni@2 85 exit(0);
eleni@2 86 default:
eleni@2 87 break;
eleni@2 88 }
eleni@2 89 }
eleni@2 90
eleni@2 91 static void idle()
eleni@2 92 {
eleni@2 93 glutPostRedisplay();
eleni@2 94 }
eleni@2 95
eleni@2 96 static void cleanup()
eleni@2 97 {
eleni@2 98 stop_kinect_frames(kin_dev);
eleni@0 99 stop_kinect(kin_ctx, kin_dev);
eleni@0 100 }