invisible

annotate src/main.cc @ 16:97dad98482f5

foo
author Eleni Maria Stea <eleni@mutantstargoat.com>
date Wed, 06 Nov 2013 21:04:45 +0200
parents 351dad433990
children 136460b6c9af
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@16 55 // glGenList
eleni@16 56 // glNewList
eleni@16 57 // glEndList
eleni@16 58 // glCallList
eleni@14 59
eleni@12 60 frame = new Frame;
eleni@14 61 if(!(tex = load_texture(filename))) {
eleni@14 62 fprintf(stderr, "Failed to load texture: %s\n", filename);
eleni@14 63 exit(1);
eleni@14 64 }
eleni@2 65
eleni@2 66 glutMainLoop();
eleni@2 67 }
eleni@2 68
eleni@2 69 static void display()
eleni@2 70 {
eleni@14 71 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
eleni@2 72
eleni@2 73 glMatrixMode(GL_MODELVIEW);
eleni@2 74 glLoadIdentity();
eleni@14 75 glClearColor(1, 1, 1, 1);
eleni@2 76
eleni@2 77 has_depth = false; has_video = false;
eleni@2 78 if(freenect_process_events(kin_ctx) != 0) {
eleni@2 79 fprintf(stderr, "Failed to process events.\n");
eleni@2 80 exit(0);
eleni@2 81 }
eleni@2 82 frame->process();
eleni@2 83
eleni@15 84 glMatrixMode(GL_MODELVIEW);
eleni@15 85 glPushMatrix();
eleni@16 86 glTranslatef(0, 0, -24);
eleni@12 87 glEnable(GL_TEXTURE_2D);
eleni@14 88 glBindTexture(GL_TEXTURE_2D, tex);
eleni@16 89 draw_tess_quad(-14, -10, 28, 20, 600, 800);
eleni@15 90 glPopMatrix();
eleni@15 91 glMatrixMode(GL_MODELVIEW);
eleni@14 92
eleni@13 93 if(show) {
eleni@13 94 glBindTexture(GL_TEXTURE_2D, frame->video_tex);
eleni@14 95 draw_tess_quad(-1, -1, 1, 1, 1, 1, true);
eleni@13 96 glBindTexture(GL_TEXTURE_2D, frame->depth_tex);
eleni@14 97 draw_tess_quad(-1, 0, 1, 1, 1, 1, true);
eleni@13 98 }
eleni@12 99 glDisable(GL_TEXTURE_2D);
eleni@12 100
eleni@2 101 glutSwapBuffers();
eleni@2 102 }
eleni@2 103
eleni@2 104 static void reshape(int w, int h)
eleni@2 105 {
eleni@2 106 glViewport(0, 0, (GLsizei) w, (GLsizei) h);
eleni@2 107 glMatrixMode(GL_PROJECTION);
eleni@2 108 glLoadIdentity();
eleni@2 109 gluPerspective(45, (float)w / (float)h, 1, 1000);
eleni@2 110 }
eleni@2 111
eleni@2 112 static void keyb(unsigned char key, int x, int y)
eleni@2 113 {
eleni@2 114 switch(key) {
eleni@13 115 case 's':
eleni@13 116 if(show)
eleni@13 117 show = false;
eleni@13 118 else
eleni@13 119 show = true;
eleni@13 120 break;
eleni@2 121 case 27:
eleni@2 122 exit(0);
eleni@2 123 default:
eleni@2 124 break;
eleni@2 125 }
eleni@2 126 }
eleni@2 127
eleni@2 128 static void idle()
eleni@2 129 {
eleni@2 130 glutPostRedisplay();
eleni@2 131 }
eleni@2 132
eleni@2 133 static void cleanup()
eleni@2 134 {
eleni@2 135 stop_kinect_frames(kin_dev);
eleni@0 136 stop_kinect(kin_ctx, kin_dev);
eleni@0 137 }