invisible
view src/main.cc @ 4:1ff5a1a50b41
foo, TODO: fix conversions
author | Eleni Maria Stea <eleni@mutantstargoat.com> |
---|---|
date | Wed, 16 Oct 2013 15:41:08 +0300 |
parents | b0b90ef993a0 |
children | 4f1b8ddcd32e |
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);
48 frame = new Frame();
50 atexit(cleanup);
51 glutMainLoop();
52 }
54 static void display()
55 {
56 glClear(GL_COLOR_BUFFER_BIT);
58 glMatrixMode(GL_MODELVIEW);
59 glLoadIdentity();
61 glClearColor(1, 0, 0, 1);
63 has_depth = false; has_video = false;
65 if(freenect_process_events(kin_ctx) != 0) {
66 fprintf(stderr, "Failed to process events.\n");
67 exit(0);
68 }
69 frame->process();
71 glutSwapBuffers();
72 }
74 static void reshape(int w, int h)
75 {
76 glViewport(0, 0, (GLsizei) w, (GLsizei) h);
77 glMatrixMode(GL_PROJECTION);
78 glLoadIdentity();
79 gluPerspective(45, (float)w / (float)h, 1, 1000);
80 }
82 static void keyb(unsigned char key, int x, int y)
83 {
84 switch(key) {
85 case 27:
86 exit(0);
87 default:
88 break;
89 }
90 }
92 static void idle()
93 {
94 glutPostRedisplay();
95 }
97 static void cleanup()
98 {
99 stop_kinect_frames(kin_dev);
100 stop_kinect(kin_ctx, kin_dev);
101 }