invisible

changeset 17:136460b6c9af

display lists
author Eleni Maria Stea <eleni@mutantstargoat.com>
date Sun, 10 Nov 2013 00:36:58 +0200
parents 97dad98482f5
children ad78eb81988d
files src/main.cc
diffstat 1 files changed, 46 insertions(+), 28 deletions(-) [+]
line diff
     1.1 --- a/src/main.cc	Wed Nov 06 21:04:45 2013 +0200
     1.2 +++ b/src/main.cc	Sun Nov 10 00:36:58 2013 +0200
     1.3 @@ -8,16 +8,21 @@
     1.4  #include "tesquad.h"
     1.5  #include "texture.h"
     1.6  
     1.7 +#define ASPECT 1
     1.8 +
     1.9  freenect_context *kin_ctx;
    1.10  freenect_device *kin_dev;
    1.11  KinectParams kin_params;
    1.12  Frame *frame;
    1.13  
    1.14  static const char *filename = "data/textures/wallpaper.jpg";
    1.15 +static unsigned int drawing;
    1.16 +static unsigned int debugging;
    1.17  static unsigned char tex;
    1.18  static bool show;
    1.19  
    1.20  static void cleanup();
    1.21 +static void init();
    1.22  
    1.23  static void display();
    1.24  static void reshape(int w, int h);
    1.25 @@ -50,18 +55,7 @@
    1.26  	glutIdleFunc(idle);
    1.27  
    1.28  	atexit(cleanup);
    1.29 -
    1.30 -	glClearColor(1, 1, 1, 1);
    1.31 -//	glGenList
    1.32 -//		glNewList
    1.33 -//		glEndList
    1.34 -//		glCallList
    1.35 -
    1.36 -    frame = new Frame;
    1.37 -	if(!(tex = load_texture(filename))) {
    1.38 -		fprintf(stderr, "Failed to load texture: %s\n", filename);
    1.39 -		exit(1);
    1.40 -	}
    1.41 +	init();
    1.42  
    1.43  	glutMainLoop();
    1.44  }
    1.45 @@ -72,7 +66,6 @@
    1.46  
    1.47  	glMatrixMode(GL_MODELVIEW);
    1.48  	glLoadIdentity();
    1.49 -	glClearColor(1, 1, 1, 1);
    1.50  
    1.51  	has_depth = false; has_video = false;
    1.52  	if(freenect_process_events(kin_ctx) != 0) {
    1.53 @@ -81,22 +74,11 @@
    1.54  	}
    1.55  	frame->process();
    1.56  
    1.57 -	glMatrixMode(GL_MODELVIEW);
    1.58 -	glPushMatrix();
    1.59 -	glTranslatef(0, 0, -24);
    1.60 -	glEnable(GL_TEXTURE_2D);
    1.61 -	glBindTexture(GL_TEXTURE_2D, tex);
    1.62 -	draw_tess_quad(-14, -10, 28, 20, 600, 800);
    1.63 -	glPopMatrix();
    1.64 -	glMatrixMode(GL_MODELVIEW);
    1.65 +	glCallList(drawing);
    1.66 +	if(show)
    1.67 +		glCallList(debugging);
    1.68  
    1.69 -	if(show) {
    1.70 -		glBindTexture(GL_TEXTURE_2D, frame->video_tex);
    1.71 -		draw_tess_quad(-1, -1, 1, 1, 1, 1, true);
    1.72 -		glBindTexture(GL_TEXTURE_2D, frame->depth_tex);
    1.73 -		draw_tess_quad(-1, 0, 1, 1, 1, 1, true);
    1.74 -	}
    1.75 -	glDisable(GL_TEXTURE_2D);
    1.76 +	glFlush();
    1.77  
    1.78  	glutSwapBuffers();
    1.79  }
    1.80 @@ -135,3 +117,39 @@
    1.81  	stop_kinect_frames(kin_dev);
    1.82  	stop_kinect(kin_ctx, kin_dev);
    1.83  }
    1.84 +
    1.85 +static void init()
    1.86 +{
    1.87 +	glClearColor(1, 1, 1, 1);
    1.88 +
    1.89 +    frame = new Frame;
    1.90 +	if(!(tex = load_texture(filename))) {
    1.91 +		fprintf(stderr, "Failed to load texture: %s\n", filename);
    1.92 +		exit(1);
    1.93 +	}
    1.94 +
    1.95 +	drawing = glGenLists(1);
    1.96 +	glNewList(drawing, GL_COMPILE);
    1.97 +
    1.98 +	/* drawing */
    1.99 +	glMatrixMode(GL_MODELVIEW);
   1.100 +	glPushMatrix();
   1.101 +	glTranslatef(0, 0, -24);
   1.102 +	glEnable(GL_TEXTURE_2D);
   1.103 +	glBindTexture(GL_TEXTURE_2D, tex);
   1.104 +	draw_tess_quad(-14, -14 * 1/ASPECT, 28, 28 * 1 / ASPECT, 850, 850 * 1 / ASPECT);
   1.105 +	glDisable(GL_TEXTURE_2D);
   1.106 +	glPopMatrix();
   1.107 +	glMatrixMode(GL_MODELVIEW);
   1.108 +	glEndList();
   1.109 +
   1.110 +	debugging = glGenLists(1);
   1.111 +	glNewList(debugging, GL_COMPILE);
   1.112 +	glEnable(GL_TEXTURE_2D);
   1.113 +	glBindTexture(GL_TEXTURE_2D, frame->video_tex);
   1.114 +	draw_tess_quad(-1, -1, 1, 2, 1, 1, true);
   1.115 +	glBindTexture(GL_TEXTURE_2D, frame->depth_tex);
   1.116 +	draw_tess_quad(0, -1, 1, 2, 1, 1, true);
   1.117 +	glDisable(GL_TEXTURE_2D);
   1.118 +	glEndList();
   1.119 +}