invisible

view src/main.cc @ 14:b6de02e21d82

quick backup: todo: remove orthographic from background quad, calculate translation (fov), add subdivision
author Eleni Maria Stea <eleni@mutantstargoat.com>
date Wed, 06 Nov 2013 01:08:50 +0200
parents 65fd6d7c42b1
children 351dad433990
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 glEnable(GL_TEXTURE_2D);
81 glBindTexture(GL_TEXTURE_2D, tex);
82 draw_tess_quad(-1, -1, 2, 2, 1, 1, true);
84 if(show) {
85 glBindTexture(GL_TEXTURE_2D, frame->video_tex);
86 draw_tess_quad(-1, -1, 1, 1, 1, 1, true);
87 glBindTexture(GL_TEXTURE_2D, frame->depth_tex);
88 draw_tess_quad(-1, 0, 1, 1, 1, 1, true);
89 }
90 glDisable(GL_TEXTURE_2D);
92 glutSwapBuffers();
93 }
95 static void reshape(int w, int h)
96 {
97 glViewport(0, 0, (GLsizei) w, (GLsizei) h);
98 glMatrixMode(GL_PROJECTION);
99 glLoadIdentity();
100 gluPerspective(45, (float)w / (float)h, 1, 1000);
101 }
103 static void keyb(unsigned char key, int x, int y)
104 {
105 switch(key) {
106 case 's':
107 if(show)
108 show = false;
109 else
110 show = true;
111 break;
112 case 27:
113 exit(0);
114 default:
115 break;
116 }
117 }
119 static void idle()
120 {
121 glutPostRedisplay();
122 }
124 static void cleanup()
125 {
126 stop_kinect_frames(kin_dev);
127 stop_kinect(kin_ctx, kin_dev);
128 }