invisible

annotate src/main.cc @ 15:351dad433990

quick backup
author Eleni Maria Stea <eleni@mutantstargoat.com>
date Wed, 06 Nov 2013 20:36:31 +0200
parents b6de02e21d82
children 97dad98482f5
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@15 80 glMatrixMode(GL_MODELVIEW);
eleni@15 81 glPushMatrix();
eleni@15 82 glTranslatef(0, 0, -10);
eleni@12 83 glEnable(GL_TEXTURE_2D);
eleni@14 84 glBindTexture(GL_TEXTURE_2D, tex);
eleni@15 85 draw_tess_quad(-10, -10, 20, 20, 600, 800);
eleni@15 86 glPopMatrix();
eleni@15 87 glMatrixMode(GL_MODELVIEW);
eleni@14 88
eleni@13 89 if(show) {
eleni@13 90 glBindTexture(GL_TEXTURE_2D, frame->video_tex);
eleni@14 91 draw_tess_quad(-1, -1, 1, 1, 1, 1, true);
eleni@13 92 glBindTexture(GL_TEXTURE_2D, frame->depth_tex);
eleni@14 93 draw_tess_quad(-1, 0, 1, 1, 1, 1, true);
eleni@13 94 }
eleni@12 95 glDisable(GL_TEXTURE_2D);
eleni@12 96
eleni@2 97 glutSwapBuffers();
eleni@2 98 }
eleni@2 99
eleni@2 100 static void reshape(int w, int h)
eleni@2 101 {
eleni@2 102 glViewport(0, 0, (GLsizei) w, (GLsizei) h);
eleni@2 103 glMatrixMode(GL_PROJECTION);
eleni@2 104 glLoadIdentity();
eleni@2 105 gluPerspective(45, (float)w / (float)h, 1, 1000);
eleni@2 106 }
eleni@2 107
eleni@2 108 static void keyb(unsigned char key, int x, int y)
eleni@2 109 {
eleni@2 110 switch(key) {
eleni@13 111 case 's':
eleni@13 112 if(show)
eleni@13 113 show = false;
eleni@13 114 else
eleni@13 115 show = true;
eleni@13 116 break;
eleni@2 117 case 27:
eleni@2 118 exit(0);
eleni@2 119 default:
eleni@2 120 break;
eleni@2 121 }
eleni@2 122 }
eleni@2 123
eleni@2 124 static void idle()
eleni@2 125 {
eleni@2 126 glutPostRedisplay();
eleni@2 127 }
eleni@2 128
eleni@2 129 static void cleanup()
eleni@2 130 {
eleni@2 131 stop_kinect_frames(kin_dev);
eleni@0 132 stop_kinect(kin_ctx, kin_dev);
eleni@0 133 }