invisible

annotate src/main.cc @ 21:53fe01a4e2f3

foo - backup
author Eleni Maria Stea <eleni@mutantstargoat.com>
date Sun, 10 Nov 2013 14:18:41 +0200
parents ad78eb81988d
children 531a814d4d6b
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@21 81 //glUseProgram(sprog)
eleni@17 82 glCallList(drawing);
eleni@17 83 if(show)
eleni@17 84 glCallList(debugging);
eleni@14 85
eleni@17 86 glFlush();
eleni@12 87
eleni@2 88 glutSwapBuffers();
eleni@2 89 }
eleni@2 90
eleni@2 91 static void reshape(int w, int h)
eleni@2 92 {
eleni@2 93 glViewport(0, 0, (GLsizei) w, (GLsizei) h);
eleni@2 94 glMatrixMode(GL_PROJECTION);
eleni@2 95 glLoadIdentity();
eleni@2 96 gluPerspective(45, (float)w / (float)h, 1, 1000);
eleni@2 97 }
eleni@2 98
eleni@2 99 static void keyb(unsigned char key, int x, int y)
eleni@2 100 {
eleni@2 101 switch(key) {
eleni@13 102 case 's':
eleni@13 103 if(show)
eleni@13 104 show = false;
eleni@13 105 else
eleni@13 106 show = true;
eleni@13 107 break;
eleni@2 108 case 27:
eleni@2 109 exit(0);
eleni@2 110 default:
eleni@2 111 break;
eleni@2 112 }
eleni@2 113 }
eleni@2 114
eleni@2 115 static void idle()
eleni@2 116 {
eleni@2 117 glutPostRedisplay();
eleni@2 118 }
eleni@2 119
eleni@2 120 static void cleanup()
eleni@2 121 {
eleni@2 122 stop_kinect_frames(kin_dev);
eleni@0 123 stop_kinect(kin_ctx, kin_dev);
eleni@0 124 }
eleni@17 125
eleni@17 126 static void init()
eleni@17 127 {
eleni@17 128 glClearColor(1, 1, 1, 1);
eleni@17 129
eleni@17 130 frame = new Frame;
eleni@17 131 if(!(tex = load_texture(filename))) {
eleni@17 132 fprintf(stderr, "Failed to load texture: %s\n", filename);
eleni@17 133 exit(1);
eleni@17 134 }
eleni@17 135
eleni@21 136 /* shaders setup */
eleni@21 137 // if(!(sprog = sdr_getprog(vsdr_path, fsdr_path))) {
eleni@21 138 // fprintf(stderr, "Failed to create shader program!\n");
eleni@21 139 // exit(1);
eleni@21 140 // }
eleni@21 141
eleni@18 142 /* drawing */
eleni@17 143 drawing = glGenLists(1);
eleni@17 144 glNewList(drawing, GL_COMPILE);
eleni@17 145 glMatrixMode(GL_MODELVIEW);
eleni@17 146 glPushMatrix();
eleni@17 147 glTranslatef(0, 0, -24);
eleni@17 148 glEnable(GL_TEXTURE_2D);
eleni@17 149 glBindTexture(GL_TEXTURE_2D, tex);
eleni@17 150 draw_tess_quad(-14, -14 * 1/ASPECT, 28, 28 * 1 / ASPECT, 850, 850 * 1 / ASPECT);
eleni@17 151 glDisable(GL_TEXTURE_2D);
eleni@17 152 glPopMatrix();
eleni@17 153 glMatrixMode(GL_MODELVIEW);
eleni@17 154 glEndList();
eleni@17 155
eleni@18 156 /* debugging */
eleni@17 157 debugging = glGenLists(1);
eleni@17 158 glNewList(debugging, GL_COMPILE);
eleni@17 159 glEnable(GL_TEXTURE_2D);
eleni@17 160 glBindTexture(GL_TEXTURE_2D, frame->video_tex);
eleni@17 161 draw_tess_quad(-1, -1, 1, 2, 1, 1, true);
eleni@17 162 glBindTexture(GL_TEXTURE_2D, frame->depth_tex);
eleni@17 163 draw_tess_quad(0, -1, 1, 2, 1, 1, true);
eleni@17 164 glDisable(GL_TEXTURE_2D);
eleni@17 165 glEndList();
eleni@17 166 }