invisible

view src/main.cc @ 12:226073258785

quick backup: display video, draw tesselated quads
author Eleni Maria Stea <eleni@mutantstargoat.com>
date Mon, 04 Nov 2013 23:39:22 +0200
parents 4f1b8ddcd32e
children 65fd6d7c42b1
line source
1 #include <GL/glew.h>
2 #include <GL/glut.h>
4 #include <assert.h>
5 #include <stdio.h>
7 #include "kinect.h"
8 #include "frame.h"
9 #include "tesquad.h"
11 freenect_context *kin_ctx;
12 freenect_device *kin_dev;
13 KinectParams kin_params;
14 Frame *frame;
16 static void cleanup();
18 static void display();
19 static void reshape(int w, int h);
20 static void keyb(unsigned char key, int x, int y);
21 static void idle();
23 bool has_video;
24 bool has_depth;
26 int main(int argc, char **argv)
27 {
28 if(!init_kinect(&kin_ctx, &kin_dev, &kin_params))
29 return 1;
31 if(!init_kinect_frames(kin_ctx, kin_dev, &kin_params)) {
32 stop_kinect(kin_ctx, kin_dev);
33 return 1;
34 }
36 glutInitWindowSize(800, 600);
37 glutInit(&argc, argv);
38 glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB);
39 glutCreateWindow("Test Kinect");
41 glewInit();
43 glutDisplayFunc(display);
44 glutReshapeFunc(reshape);
45 glutKeyboardFunc(keyb);
46 glutIdleFunc(idle);
48 glClearColor(1, 1, 1, 1);
49 frame = new Frame;
51 atexit(cleanup);
52 glutMainLoop();
53 }
55 static void display()
56 {
57 glClear(GL_COLOR_BUFFER_BIT);
59 glMatrixMode(GL_MODELVIEW);
60 glLoadIdentity();
62 glClearColor(1, 0, 0, 1);
64 has_depth = false; has_video = false;
66 if(freenect_process_events(kin_ctx) != 0) {
67 fprintf(stderr, "Failed to process events.\n");
68 exit(0);
69 }
70 assert(glGetError() == GL_NO_ERROR);
71 frame->process();
73 glEnable(GL_TEXTURE_2D);
74 glBindTexture(GL_TEXTURE_2D, frame->video_tex);
75 assert(glGetError() == GL_NO_ERROR);
76 draw_tess_quad(-1, -1, 0.6, 0.6, 1, 1);
77 // glBindTexture(GL_TEXTURE_2D, frame->depth_tex);
78 // draw_tes..
79 glDisable(GL_TEXTURE_2D);
81 glutSwapBuffers();
82 assert(glGetError() == GL_NO_ERROR);
83 }
85 static void reshape(int w, int h)
86 {
87 glViewport(0, 0, (GLsizei) w, (GLsizei) h);
88 glMatrixMode(GL_PROJECTION);
89 glLoadIdentity();
90 gluPerspective(45, (float)w / (float)h, 1, 1000);
91 }
93 static void keyb(unsigned char key, int x, int y)
94 {
95 switch(key) {
96 case 27:
97 exit(0);
98 default:
99 break;
100 }
101 }
103 static void idle()
104 {
105 glutPostRedisplay();
106 }
108 static void cleanup()
109 {
110 stop_kinect_frames(kin_dev);
111 stop_kinect(kin_ctx, kin_dev);
112 }