invisible

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