invisible

view 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
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 "tesquad.h"
9 #include "texture.h"
11 freenect_context *kin_ctx;
12 freenect_device *kin_dev;
13 KinectParams kin_params;
14 Frame *frame;
16 static const char *filename = "data/textures/wallpaper.jpg";
17 static unsigned char tex;
18 static bool show;
20 static void cleanup();
22 static void display();
23 static void reshape(int w, int h);
24 static void keyb(unsigned char key, int x, int y);
25 static void idle();
27 bool has_video;
28 bool has_depth;
30 int main(int argc, char **argv)
31 {
32 if(!init_kinect(&kin_ctx, &kin_dev, &kin_params))
33 return 1;
35 if(!init_kinect_frames(kin_ctx, kin_dev, &kin_params)) {
36 stop_kinect(kin_ctx, kin_dev);
37 return 1;
38 }
40 glutInitWindowSize(800, 600);
41 glutInit(&argc, argv);
42 glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB);
43 glutCreateWindow("Test Kinect");
45 glewInit();
47 glutDisplayFunc(display);
48 glutReshapeFunc(reshape);
49 glutKeyboardFunc(keyb);
50 glutIdleFunc(idle);
52 atexit(cleanup);
54 glClearColor(1, 1, 1, 1);
55 // glGenList
56 // glNewList
57 // glEndList
58 // glCallList
60 frame = new Frame;
61 if(!(tex = load_texture(filename))) {
62 fprintf(stderr, "Failed to load texture: %s\n", filename);
63 exit(1);
64 }
66 glutMainLoop();
67 }
69 static void display()
70 {
71 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
73 glMatrixMode(GL_MODELVIEW);
74 glLoadIdentity();
75 glClearColor(1, 1, 1, 1);
77 has_depth = false; has_video = false;
78 if(freenect_process_events(kin_ctx) != 0) {
79 fprintf(stderr, "Failed to process events.\n");
80 exit(0);
81 }
82 frame->process();
84 glMatrixMode(GL_MODELVIEW);
85 glPushMatrix();
86 glTranslatef(0, 0, -24);
87 glEnable(GL_TEXTURE_2D);
88 glBindTexture(GL_TEXTURE_2D, tex);
89 draw_tess_quad(-14, -10, 28, 20, 600, 800);
90 glPopMatrix();
91 glMatrixMode(GL_MODELVIEW);
93 if(show) {
94 glBindTexture(GL_TEXTURE_2D, frame->video_tex);
95 draw_tess_quad(-1, -1, 1, 1, 1, 1, true);
96 glBindTexture(GL_TEXTURE_2D, frame->depth_tex);
97 draw_tess_quad(-1, 0, 1, 1, 1, 1, true);
98 }
99 glDisable(GL_TEXTURE_2D);
101 glutSwapBuffers();
102 }
104 static void reshape(int w, int h)
105 {
106 glViewport(0, 0, (GLsizei) w, (GLsizei) h);
107 glMatrixMode(GL_PROJECTION);
108 glLoadIdentity();
109 gluPerspective(45, (float)w / (float)h, 1, 1000);
110 }
112 static void keyb(unsigned char key, int x, int y)
113 {
114 switch(key) {
115 case 's':
116 if(show)
117 show = false;
118 else
119 show = true;
120 break;
121 case 27:
122 exit(0);
123 default:
124 break;
125 }
126 }
128 static void idle()
129 {
130 glutPostRedisplay();
131 }
133 static void cleanup()
134 {
135 stop_kinect_frames(kin_dev);
136 stop_kinect(kin_ctx, kin_dev);
137 }