invisible

annotate src/main.cc @ 22:531a814d4d6b

foo
author Eleni Maria Stea <eleni@mutantstargoat.com>
date Sun, 10 Nov 2013 14:32:29 +0200
parents 53fe01a4e2f3
children b50ad2711f5f
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@21 8 #include "sdr.h"
eleni@12 9 #include "tesquad.h"
eleni@14 10 #include "texture.h"
eleni@0 11
eleni@17 12 #define ASPECT 1
eleni@17 13
eleni@0 14 freenect_context *kin_ctx;
eleni@0 15 freenect_device *kin_dev;
eleni@0 16 KinectParams kin_params;
eleni@2 17 Frame *frame;
eleni@0 18
eleni@14 19 static const char *filename = "data/textures/wallpaper.jpg";
eleni@21 20 //static const char *vsdr_path = "data/shaders/invisible.v.glsl";
eleni@21 21 //static const char *fsdr_path = "data/shaders/invisible.f.glsl";
eleni@17 22 static unsigned int drawing;
eleni@17 23 static unsigned int debugging;
eleni@21 24 //static unsigned int sprog;
eleni@14 25 static unsigned char tex;
eleni@13 26 static bool show;
eleni@13 27
eleni@2 28 static void cleanup();
eleni@17 29 static void init();
eleni@2 30
eleni@2 31 static void display();
eleni@2 32 static void reshape(int w, int h);
eleni@2 33 static void keyb(unsigned char key, int x, int y);
eleni@2 34 static void idle();
eleni@2 35
eleni@2 36 bool has_video;
eleni@2 37 bool has_depth;
eleni@2 38
eleni@2 39 int main(int argc, char **argv)
eleni@0 40 {
eleni@0 41 if(!init_kinect(&kin_ctx, &kin_dev, &kin_params))
eleni@0 42 return 1;
eleni@0 43
eleni@7 44 if(!init_kinect_frames(kin_ctx, kin_dev, &kin_params)) {
eleni@2 45 stop_kinect(kin_ctx, kin_dev);
eleni@2 46 return 1;
eleni@2 47 }
eleni@2 48
eleni@2 49 glutInitWindowSize(800, 600);
eleni@2 50 glutInit(&argc, argv);
eleni@2 51 glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB);
eleni@2 52 glutCreateWindow("Test Kinect");
eleni@2 53
eleni@2 54 glewInit();
eleni@2 55
eleni@2 56 glutDisplayFunc(display);
eleni@2 57 glutReshapeFunc(reshape);
eleni@2 58 glutKeyboardFunc(keyb);
eleni@2 59 glutIdleFunc(idle);
eleni@2 60
eleni@14 61 atexit(cleanup);
eleni@17 62 init();
eleni@2 63
eleni@2 64 glutMainLoop();
eleni@2 65 }
eleni@2 66
eleni@2 67 static void display()
eleni@2 68 {
eleni@14 69 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
eleni@2 70
eleni@2 71 glMatrixMode(GL_MODELVIEW);
eleni@2 72 glLoadIdentity();
eleni@2 73
eleni@2 74 has_depth = false; has_video = false;
eleni@2 75 if(freenect_process_events(kin_ctx) != 0) {
eleni@2 76 fprintf(stderr, "Failed to process events.\n");
eleni@2 77 exit(0);
eleni@2 78 }
eleni@2 79 frame->process();
eleni@2 80
eleni@22 81 // glUseProgram(sprog);
eleni@17 82 glCallList(drawing);
eleni@17 83 if(show)
eleni@17 84 glCallList(debugging);
eleni@17 85 glFlush();
eleni@12 86
eleni@2 87 glutSwapBuffers();
eleni@2 88 }
eleni@2 89
eleni@2 90 static void reshape(int w, int h)
eleni@2 91 {
eleni@2 92 glViewport(0, 0, (GLsizei) w, (GLsizei) h);
eleni@2 93 glMatrixMode(GL_PROJECTION);
eleni@2 94 glLoadIdentity();
eleni@2 95 gluPerspective(45, (float)w / (float)h, 1, 1000);
eleni@2 96 }
eleni@2 97
eleni@2 98 static void keyb(unsigned char key, int x, int y)
eleni@2 99 {
eleni@2 100 switch(key) {
eleni@13 101 case 's':
eleni@13 102 if(show)
eleni@13 103 show = false;
eleni@13 104 else
eleni@13 105 show = true;
eleni@13 106 break;
eleni@2 107 case 27:
eleni@2 108 exit(0);
eleni@2 109 default:
eleni@2 110 break;
eleni@2 111 }
eleni@2 112 }
eleni@2 113
eleni@2 114 static void idle()
eleni@2 115 {
eleni@2 116 glutPostRedisplay();
eleni@2 117 }
eleni@2 118
eleni@2 119 static void cleanup()
eleni@2 120 {
eleni@2 121 stop_kinect_frames(kin_dev);
eleni@0 122 stop_kinect(kin_ctx, kin_dev);
eleni@0 123 }
eleni@17 124
eleni@17 125 static void init()
eleni@17 126 {
eleni@17 127 glClearColor(1, 1, 1, 1);
eleni@17 128
eleni@17 129 frame = new Frame;
eleni@17 130 if(!(tex = load_texture(filename))) {
eleni@17 131 fprintf(stderr, "Failed to load texture: %s\n", filename);
eleni@17 132 exit(1);
eleni@17 133 }
eleni@17 134
eleni@21 135 /* shaders setup */
eleni@21 136 // if(!(sprog = sdr_getprog(vsdr_path, fsdr_path))) {
eleni@21 137 // fprintf(stderr, "Failed to create shader program!\n");
eleni@21 138 // exit(1);
eleni@21 139 // }
eleni@21 140
eleni@18 141 /* drawing */
eleni@17 142 drawing = glGenLists(1);
eleni@17 143 glNewList(drawing, GL_COMPILE);
eleni@17 144 glMatrixMode(GL_MODELVIEW);
eleni@17 145 glPushMatrix();
eleni@17 146 glTranslatef(0, 0, -24);
eleni@17 147 glEnable(GL_TEXTURE_2D);
eleni@17 148 glBindTexture(GL_TEXTURE_2D, tex);
eleni@17 149 draw_tess_quad(-14, -14 * 1/ASPECT, 28, 28 * 1 / ASPECT, 850, 850 * 1 / ASPECT);
eleni@17 150 glDisable(GL_TEXTURE_2D);
eleni@17 151 glPopMatrix();
eleni@17 152 glMatrixMode(GL_MODELVIEW);
eleni@17 153 glEndList();
eleni@17 154
eleni@18 155 /* debugging */
eleni@17 156 debugging = glGenLists(1);
eleni@17 157 glNewList(debugging, GL_COMPILE);
eleni@17 158 glEnable(GL_TEXTURE_2D);
eleni@17 159 glBindTexture(GL_TEXTURE_2D, frame->video_tex);
eleni@17 160 draw_tess_quad(-1, -1, 1, 2, 1, 1, true);
eleni@17 161 glBindTexture(GL_TEXTURE_2D, frame->depth_tex);
eleni@17 162 draw_tess_quad(0, -1, 1, 2, 1, 1, true);
eleni@17 163 glDisable(GL_TEXTURE_2D);
eleni@17 164 glEndList();
eleni@17 165 }