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