invisible

view src/main.cc @ 13:65fd6d7c42b1

foo: show/hide rgb video and depth frames
author Eleni Maria Stea <eleni@mutantstargoat.com>
date Tue, 05 Nov 2013 00:24:25 +0200
parents 226073258785
children b6de02e21d82
line source
1 #include <GL/glew.h>
2 #include <GL/glut.h>
4 #include <stdio.h>
6 #include "kinect.h"
7 #include "frame.h"
8 #include "tesquad.h"
10 freenect_context *kin_ctx;
11 freenect_device *kin_dev;
12 KinectParams kin_params;
13 Frame *frame;
15 static bool show;
17 static void cleanup();
19 static void display();
20 static void reshape(int w, int h);
21 static void keyb(unsigned char key, int x, int y);
22 static void idle();
24 bool has_video;
25 bool has_depth;
27 int main(int argc, char **argv)
28 {
29 if(!init_kinect(&kin_ctx, &kin_dev, &kin_params))
30 return 1;
32 if(!init_kinect_frames(kin_ctx, kin_dev, &kin_params)) {
33 stop_kinect(kin_ctx, kin_dev);
34 return 1;
35 }
37 glutInitWindowSize(800, 600);
38 glutInit(&argc, argv);
39 glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB);
40 glutCreateWindow("Test Kinect");
42 glewInit();
44 glutDisplayFunc(display);
45 glutReshapeFunc(reshape);
46 glutKeyboardFunc(keyb);
47 glutIdleFunc(idle);
49 glClearColor(1, 1, 1, 1);
50 frame = new Frame;
52 atexit(cleanup);
53 glutMainLoop();
54 }
56 static void display()
57 {
58 glClear(GL_COLOR_BUFFER_BIT);
60 glMatrixMode(GL_MODELVIEW);
61 glLoadIdentity();
63 glClearColor(1, 0, 0, 1);
65 has_depth = false; has_video = false;
67 if(freenect_process_events(kin_ctx) != 0) {
68 fprintf(stderr, "Failed to process events.\n");
69 exit(0);
70 }
71 frame->process();
73 glEnable(GL_TEXTURE_2D);
74 if(show) {
75 glBindTexture(GL_TEXTURE_2D, frame->video_tex);
76 draw_tess_quad(-1, -1, 1, 2, 1, 1);
77 glBindTexture(GL_TEXTURE_2D, frame->depth_tex);
78 draw_tess_quad(0, -1, 1, 2, 1, 1);
79 }
80 glDisable(GL_TEXTURE_2D);
82 glutSwapBuffers();
83 }
85 static void reshape(int w, int h)
86 {
87 glViewport(0, 0, (GLsizei) w, (GLsizei) h);
88 glMatrixMode(GL_PROJECTION);
89 glLoadIdentity();
90 gluPerspective(45, (float)w / (float)h, 1, 1000);
91 }
93 static void keyb(unsigned char key, int x, int y)
94 {
95 switch(key) {
96 case 's':
97 if(show)
98 show = false;
99 else
100 show = true;
101 break;
102 case 27:
103 exit(0);
104 default:
105 break;
106 }
107 }
109 static void idle()
110 {
111 glutPostRedisplay();
112 }
114 static void cleanup()
115 {
116 stop_kinect_frames(kin_dev);
117 stop_kinect(kin_ctx, kin_dev);
118 }