rev |
line source |
eleni@2
|
1 #include <GL/glew.h>
|
eleni@2
|
2 #include <GL/glut.h>
|
eleni@12
|
3
|
eleni@12
|
4 #include <assert.h>
|
eleni@0
|
5 #include <stdio.h>
|
eleni@0
|
6
|
eleni@0
|
7 #include "kinect.h"
|
eleni@2
|
8 #include "frame.h"
|
eleni@12
|
9 #include "tesquad.h"
|
eleni@0
|
10
|
eleni@0
|
11 freenect_context *kin_ctx;
|
eleni@0
|
12 freenect_device *kin_dev;
|
eleni@0
|
13 KinectParams kin_params;
|
eleni@2
|
14 Frame *frame;
|
eleni@0
|
15
|
eleni@2
|
16 static void cleanup();
|
eleni@2
|
17
|
eleni@2
|
18 static void display();
|
eleni@2
|
19 static void reshape(int w, int h);
|
eleni@2
|
20 static void keyb(unsigned char key, int x, int y);
|
eleni@2
|
21 static void idle();
|
eleni@2
|
22
|
eleni@2
|
23 bool has_video;
|
eleni@2
|
24 bool has_depth;
|
eleni@2
|
25
|
eleni@2
|
26 int main(int argc, char **argv)
|
eleni@0
|
27 {
|
eleni@0
|
28 if(!init_kinect(&kin_ctx, &kin_dev, &kin_params))
|
eleni@0
|
29 return 1;
|
eleni@0
|
30
|
eleni@7
|
31 if(!init_kinect_frames(kin_ctx, kin_dev, &kin_params)) {
|
eleni@2
|
32 stop_kinect(kin_ctx, kin_dev);
|
eleni@2
|
33 return 1;
|
eleni@2
|
34 }
|
eleni@2
|
35
|
eleni@2
|
36 glutInitWindowSize(800, 600);
|
eleni@2
|
37 glutInit(&argc, argv);
|
eleni@2
|
38 glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB);
|
eleni@2
|
39 glutCreateWindow("Test Kinect");
|
eleni@2
|
40
|
eleni@2
|
41 glewInit();
|
eleni@2
|
42
|
eleni@2
|
43 glutDisplayFunc(display);
|
eleni@2
|
44 glutReshapeFunc(reshape);
|
eleni@2
|
45 glutKeyboardFunc(keyb);
|
eleni@2
|
46 glutIdleFunc(idle);
|
eleni@2
|
47
|
eleni@2
|
48 glClearColor(1, 1, 1, 1);
|
eleni@12
|
49 frame = new Frame;
|
eleni@2
|
50
|
eleni@2
|
51 atexit(cleanup);
|
eleni@2
|
52 glutMainLoop();
|
eleni@2
|
53 }
|
eleni@2
|
54
|
eleni@2
|
55 static void display()
|
eleni@2
|
56 {
|
eleni@2
|
57 glClear(GL_COLOR_BUFFER_BIT);
|
eleni@2
|
58
|
eleni@2
|
59 glMatrixMode(GL_MODELVIEW);
|
eleni@2
|
60 glLoadIdentity();
|
eleni@2
|
61
|
eleni@2
|
62 glClearColor(1, 0, 0, 1);
|
eleni@2
|
63
|
eleni@2
|
64 has_depth = false; has_video = false;
|
eleni@2
|
65
|
eleni@2
|
66 if(freenect_process_events(kin_ctx) != 0) {
|
eleni@2
|
67 fprintf(stderr, "Failed to process events.\n");
|
eleni@2
|
68 exit(0);
|
eleni@2
|
69 }
|
eleni@12
|
70 assert(glGetError() == GL_NO_ERROR);
|
eleni@2
|
71 frame->process();
|
eleni@2
|
72
|
eleni@12
|
73 glEnable(GL_TEXTURE_2D);
|
eleni@12
|
74 glBindTexture(GL_TEXTURE_2D, frame->video_tex);
|
eleni@12
|
75 assert(glGetError() == GL_NO_ERROR);
|
eleni@12
|
76 draw_tess_quad(-1, -1, 0.6, 0.6, 1, 1);
|
eleni@12
|
77 // glBindTexture(GL_TEXTURE_2D, frame->depth_tex);
|
eleni@12
|
78 // draw_tes..
|
eleni@12
|
79 glDisable(GL_TEXTURE_2D);
|
eleni@12
|
80
|
eleni@2
|
81 glutSwapBuffers();
|
eleni@12
|
82 assert(glGetError() == GL_NO_ERROR);
|
eleni@2
|
83 }
|
eleni@2
|
84
|
eleni@2
|
85 static void reshape(int w, int h)
|
eleni@2
|
86 {
|
eleni@2
|
87 glViewport(0, 0, (GLsizei) w, (GLsizei) h);
|
eleni@2
|
88 glMatrixMode(GL_PROJECTION);
|
eleni@2
|
89 glLoadIdentity();
|
eleni@2
|
90 gluPerspective(45, (float)w / (float)h, 1, 1000);
|
eleni@2
|
91 }
|
eleni@2
|
92
|
eleni@2
|
93 static void keyb(unsigned char key, int x, int y)
|
eleni@2
|
94 {
|
eleni@2
|
95 switch(key) {
|
eleni@2
|
96 case 27:
|
eleni@2
|
97 exit(0);
|
eleni@2
|
98 default:
|
eleni@2
|
99 break;
|
eleni@2
|
100 }
|
eleni@2
|
101 }
|
eleni@2
|
102
|
eleni@2
|
103 static void idle()
|
eleni@2
|
104 {
|
eleni@2
|
105 glutPostRedisplay();
|
eleni@2
|
106 }
|
eleni@2
|
107
|
eleni@2
|
108 static void cleanup()
|
eleni@2
|
109 {
|
eleni@2
|
110 stop_kinect_frames(kin_dev);
|
eleni@0
|
111 stop_kinect(kin_ctx, kin_dev);
|
eleni@0
|
112 }
|