invisible

diff src/main.cc @ 2:b0b90ef993a0

backup
author Eleni Maria Stea <eleni@mutantstargoat.com>
date Wed, 09 Oct 2013 22:56:42 +0300
parents 80df8030105b
children 1ff5a1a50b41
line diff
     1.1 --- a/src/main.cc	Sat Oct 05 19:02:40 2013 +0300
     1.2 +++ b/src/main.cc	Wed Oct 09 22:56:42 2013 +0300
     1.3 @@ -1,17 +1,100 @@
     1.4 +#include <GL/glew.h>
     1.5 +#include <GL/glut.h>
     1.6  #include <stdio.h>
     1.7  
     1.8 +#include <pthread.h>
     1.9 +
    1.10  #include "kinect.h"
    1.11 +#include "frame.h"
    1.12  
    1.13  freenect_context *kin_ctx;
    1.14  freenect_device *kin_dev;
    1.15  KinectParams kin_params;
    1.16 +Frame *frame;
    1.17  
    1.18 -int main()
    1.19 +static void cleanup();
    1.20 +
    1.21 +static void display();
    1.22 +static void reshape(int w, int h);
    1.23 +static void keyb(unsigned char key, int x, int y);
    1.24 +static void idle();
    1.25 +
    1.26 +bool has_video;
    1.27 +bool has_depth;
    1.28 +
    1.29 +int main(int argc, char **argv)
    1.30  {
    1.31 -	printf("hi\n");
    1.32 -
    1.33  	if(!init_kinect(&kin_ctx, &kin_dev, &kin_params))
    1.34  		return 1;
    1.35  
    1.36 +	if(!init_kinect_frames(&kin_ctx, &kin_dev, &kin_params)) {
    1.37 +		stop_kinect(kin_ctx, kin_dev);
    1.38 +		return 1;
    1.39 +	}
    1.40 +
    1.41 +	glutInitWindowSize(800, 600);
    1.42 +	glutInit(&argc, argv);
    1.43 +	glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB);
    1.44 +	glutCreateWindow("Test Kinect");
    1.45 +
    1.46 +	glewInit();
    1.47 +
    1.48 +	glutDisplayFunc(display);
    1.49 +	glutReshapeFunc(reshape);
    1.50 +	glutKeyboardFunc(keyb);
    1.51 +	glutIdleFunc(idle);
    1.52 +
    1.53 +	glClearColor(1, 1, 1, 1);
    1.54 +
    1.55 +	atexit(cleanup);
    1.56 +	glutMainLoop();
    1.57 +}
    1.58 +
    1.59 +static void display()
    1.60 +{
    1.61 +	glClear(GL_COLOR_BUFFER_BIT);
    1.62 +
    1.63 +	glMatrixMode(GL_MODELVIEW);
    1.64 +	glLoadIdentity();
    1.65 +
    1.66 +	glClearColor(1, 0, 0, 1);
    1.67 +
    1.68 +	has_depth = false; has_video = false;
    1.69 +
    1.70 +	if(freenect_process_events(kin_ctx) != 0) {
    1.71 +		fprintf(stderr, "Failed to process events.\n");
    1.72 +		exit(0);
    1.73 +	}
    1.74 +	frame->process();
    1.75 +
    1.76 +	glutSwapBuffers();
    1.77 +}
    1.78 +
    1.79 +static void reshape(int w, int h)
    1.80 +{
    1.81 +	glViewport(0, 0, (GLsizei) w, (GLsizei) h);
    1.82 +	glMatrixMode(GL_PROJECTION);
    1.83 +	glLoadIdentity();
    1.84 +	gluPerspective(45, (float)w / (float)h, 1, 1000);
    1.85 +}
    1.86 +
    1.87 +static void keyb(unsigned char key, int x, int y)
    1.88 +{
    1.89 +	switch(key) {
    1.90 +	case 27:
    1.91 +		exit(0);
    1.92 +	default:
    1.93 +		break;
    1.94 +	}
    1.95 +}
    1.96 +
    1.97 +static void idle()
    1.98 +{
    1.99 +	glutPostRedisplay();
   1.100 +}
   1.101 +
   1.102 +static void cleanup()
   1.103 +{
   1.104 +	stop_kinect_frames(kin_dev);
   1.105  	stop_kinect(kin_ctx, kin_dev);
   1.106  }