invisible

annotate 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
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@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@13 15 static bool show;
eleni@13 16
eleni@2 17 static void cleanup();
eleni@2 18
eleni@2 19 static void display();
eleni@2 20 static void reshape(int w, int h);
eleni@2 21 static void keyb(unsigned char key, int x, int y);
eleni@2 22 static void idle();
eleni@2 23
eleni@2 24 bool has_video;
eleni@2 25 bool has_depth;
eleni@2 26
eleni@2 27 int main(int argc, char **argv)
eleni@0 28 {
eleni@0 29 if(!init_kinect(&kin_ctx, &kin_dev, &kin_params))
eleni@0 30 return 1;
eleni@0 31
eleni@7 32 if(!init_kinect_frames(kin_ctx, kin_dev, &kin_params)) {
eleni@2 33 stop_kinect(kin_ctx, kin_dev);
eleni@2 34 return 1;
eleni@2 35 }
eleni@2 36
eleni@2 37 glutInitWindowSize(800, 600);
eleni@2 38 glutInit(&argc, argv);
eleni@2 39 glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB);
eleni@2 40 glutCreateWindow("Test Kinect");
eleni@2 41
eleni@2 42 glewInit();
eleni@2 43
eleni@2 44 glutDisplayFunc(display);
eleni@2 45 glutReshapeFunc(reshape);
eleni@2 46 glutKeyboardFunc(keyb);
eleni@2 47 glutIdleFunc(idle);
eleni@2 48
eleni@2 49 glClearColor(1, 1, 1, 1);
eleni@12 50 frame = new Frame;
eleni@2 51
eleni@2 52 atexit(cleanup);
eleni@2 53 glutMainLoop();
eleni@2 54 }
eleni@2 55
eleni@2 56 static void display()
eleni@2 57 {
eleni@2 58 glClear(GL_COLOR_BUFFER_BIT);
eleni@2 59
eleni@2 60 glMatrixMode(GL_MODELVIEW);
eleni@2 61 glLoadIdentity();
eleni@2 62
eleni@2 63 glClearColor(1, 0, 0, 1);
eleni@2 64
eleni@2 65 has_depth = false; has_video = false;
eleni@2 66
eleni@2 67 if(freenect_process_events(kin_ctx) != 0) {
eleni@2 68 fprintf(stderr, "Failed to process events.\n");
eleni@2 69 exit(0);
eleni@2 70 }
eleni@2 71 frame->process();
eleni@2 72
eleni@12 73 glEnable(GL_TEXTURE_2D);
eleni@13 74 if(show) {
eleni@13 75 glBindTexture(GL_TEXTURE_2D, frame->video_tex);
eleni@13 76 draw_tess_quad(-1, -1, 1, 2, 1, 1);
eleni@13 77 glBindTexture(GL_TEXTURE_2D, frame->depth_tex);
eleni@13 78 draw_tess_quad(0, -1, 1, 2, 1, 1);
eleni@13 79 }
eleni@12 80 glDisable(GL_TEXTURE_2D);
eleni@12 81
eleni@2 82 glutSwapBuffers();
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@13 96 case 's':
eleni@13 97 if(show)
eleni@13 98 show = false;
eleni@13 99 else
eleni@13 100 show = true;
eleni@13 101 break;
eleni@2 102 case 27:
eleni@2 103 exit(0);
eleni@2 104 default:
eleni@2 105 break;
eleni@2 106 }
eleni@2 107 }
eleni@2 108
eleni@2 109 static void idle()
eleni@2 110 {
eleni@2 111 glutPostRedisplay();
eleni@2 112 }
eleni@2 113
eleni@2 114 static void cleanup()
eleni@2 115 {
eleni@2 116 stop_kinect_frames(kin_dev);
eleni@0 117 stop_kinect(kin_ctx, kin_dev);
eleni@0 118 }