invisible

view 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
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);
85 glFlush();
87 glutSwapBuffers();
88 }
90 static void reshape(int w, int h)
91 {
92 glViewport(0, 0, (GLsizei) w, (GLsizei) h);
93 glMatrixMode(GL_PROJECTION);
94 glLoadIdentity();
95 gluPerspective(45, (float)w / (float)h, 1, 1000);
96 }
98 static void keyb(unsigned char key, int x, int y)
99 {
100 switch(key) {
101 case 's':
102 if(show)
103 show = false;
104 else
105 show = true;
106 break;
107 case 27:
108 exit(0);
109 default:
110 break;
111 }
112 }
114 static void idle()
115 {
116 glutPostRedisplay();
117 }
119 static void cleanup()
120 {
121 stop_kinect_frames(kin_dev);
122 stop_kinect(kin_ctx, kin_dev);
123 }
125 static void init()
126 {
127 glClearColor(1, 1, 1, 1);
129 frame = new Frame;
130 if(!(tex = load_texture(filename))) {
131 fprintf(stderr, "Failed to load texture: %s\n", filename);
132 exit(1);
133 }
135 /* shaders setup */
136 // if(!(sprog = sdr_getprog(vsdr_path, fsdr_path))) {
137 // fprintf(stderr, "Failed to create shader program!\n");
138 // exit(1);
139 // }
141 /* drawing */
142 drawing = glGenLists(1);
143 glNewList(drawing, GL_COMPILE);
144 glMatrixMode(GL_MODELVIEW);
145 glPushMatrix();
146 glTranslatef(0, 0, -24);
147 glEnable(GL_TEXTURE_2D);
148 glBindTexture(GL_TEXTURE_2D, tex);
149 draw_tess_quad(-14, -14 * 1/ASPECT, 28, 28 * 1 / ASPECT, 850, 850 * 1 / ASPECT);
150 glDisable(GL_TEXTURE_2D);
151 glPopMatrix();
152 glMatrixMode(GL_MODELVIEW);
153 glEndList();
155 /* debugging */
156 debugging = glGenLists(1);
157 glNewList(debugging, GL_COMPILE);
158 glEnable(GL_TEXTURE_2D);
159 glBindTexture(GL_TEXTURE_2D, frame->video_tex);
160 draw_tess_quad(-1, -1, 1, 2, 1, 1, true);
161 glBindTexture(GL_TEXTURE_2D, frame->depth_tex);
162 draw_tess_quad(0, -1, 1, 2, 1, 1, true);
163 glDisable(GL_TEXTURE_2D);
164 glEndList();
165 }