invisible
view src/main.cc @ 15:351dad433990
quick backup
author | Eleni Maria Stea <eleni@mutantstargoat.com> |
---|---|
date | Wed, 06 Nov 2013 20:36:31 +0200 |
parents | b6de02e21d82 |
children | 97dad98482f5 |
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);
56 frame = new Frame;
57 if(!(tex = load_texture(filename))) {
58 fprintf(stderr, "Failed to load texture: %s\n", filename);
59 exit(1);
60 }
62 glutMainLoop();
63 }
65 static void display()
66 {
67 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
69 glMatrixMode(GL_MODELVIEW);
70 glLoadIdentity();
71 glClearColor(1, 1, 1, 1);
73 has_depth = false; has_video = false;
74 if(freenect_process_events(kin_ctx) != 0) {
75 fprintf(stderr, "Failed to process events.\n");
76 exit(0);
77 }
78 frame->process();
80 glMatrixMode(GL_MODELVIEW);
81 glPushMatrix();
82 glTranslatef(0, 0, -10);
83 glEnable(GL_TEXTURE_2D);
84 glBindTexture(GL_TEXTURE_2D, tex);
85 draw_tess_quad(-10, -10, 20, 20, 600, 800);
86 glPopMatrix();
87 glMatrixMode(GL_MODELVIEW);
89 if(show) {
90 glBindTexture(GL_TEXTURE_2D, frame->video_tex);
91 draw_tess_quad(-1, -1, 1, 1, 1, 1, true);
92 glBindTexture(GL_TEXTURE_2D, frame->depth_tex);
93 draw_tess_quad(-1, 0, 1, 1, 1, 1, true);
94 }
95 glDisable(GL_TEXTURE_2D);
97 glutSwapBuffers();
98 }
100 static void reshape(int w, int h)
101 {
102 glViewport(0, 0, (GLsizei) w, (GLsizei) h);
103 glMatrixMode(GL_PROJECTION);
104 glLoadIdentity();
105 gluPerspective(45, (float)w / (float)h, 1, 1000);
106 }
108 static void keyb(unsigned char key, int x, int y)
109 {
110 switch(key) {
111 case 's':
112 if(show)
113 show = false;
114 else
115 show = true;
116 break;
117 case 27:
118 exit(0);
119 default:
120 break;
121 }
122 }
124 static void idle()
125 {
126 glutPostRedisplay();
127 }
129 static void cleanup()
130 {
131 stop_kinect_frames(kin_dev);
132 stop_kinect(kin_ctx, kin_dev);
133 }