cubemapper

diff src/app.cc @ 1:d7a29cb7ac8d

resize to the final cubemap face size
author John Tsiombikas <nuclear@member.fsf.org>
date Fri, 28 Jul 2017 07:44:35 +0300
parents 8fc9e1d3aad2
children e308561f9889
line diff
     1.1 --- a/src/app.cc	Thu Jul 27 20:36:12 2017 +0300
     1.2 +++ b/src/app.cc	Fri Jul 28 07:44:35 2017 +0300
     1.3 @@ -16,6 +16,8 @@
     1.4  static void draw_scene_inf();
     1.5  static bool parse_args(int argc, char **argv);
     1.6  
     1.7 +static void flip_image(float *pixels, int xsz, int ysz);
     1.8 +
     1.9  static const char *img_fname;
    1.10  static float cam_theta, cam_phi;
    1.11  
    1.12 @@ -64,6 +66,7 @@
    1.13  	if(!pano_tex->load(img_fname)) {
    1.14  		return false;
    1.15  	}
    1.16 +	printf("loaded image: %dx%d\n", pano_tex->get_width(), pano_tex->get_height());
    1.17  	return true;
    1.18  }
    1.19  
    1.20 @@ -126,6 +129,8 @@
    1.21  		draw_scene();
    1.22  
    1.23  		glReadPixels(0, 0, fbsize, fbsize, GL_RGB, GL_FLOAT, pixels);
    1.24 +		flip_image(pixels, fbsize, fbsize);
    1.25 +
    1.26  		if(img_save_pixels(fname[i], pixels, fbsize, fbsize, IMG_FMT_RGBF) == -1) {
    1.27  			fprintf(stderr, "failed to save %dx%d image: %s\n", fbsize, fbsize, fname[i]);
    1.28  			break;
    1.29 @@ -172,12 +177,19 @@
    1.30  
    1.31  void app_keyboard(int key, bool press)
    1.32  {
    1.33 +	int cubemap_size;
    1.34 +
    1.35  	if(press) {
    1.36  		switch(key) {
    1.37  		case 27:
    1.38  			app_quit();
    1.39  			break;
    1.40  
    1.41 +		case ' ':
    1.42 +			cubemap_size = pano_tex->get_width() / 4;
    1.43 +			app_resize(cubemap_size, cubemap_size);
    1.44 +			break;
    1.45 +
    1.46  		case 's':
    1.47  			printf("rendering cubemap\n");
    1.48  			render_cubemap();
    1.49 @@ -241,3 +253,21 @@
    1.50  
    1.51  	return true;
    1.52  }
    1.53 +
    1.54 +static void flip_image(float *pixels, int xsz, int ysz)
    1.55 +{
    1.56 +	float *top_ptr = pixels;
    1.57 +	float *bot_ptr = pixels + xsz * (ysz - 1) * 3;
    1.58 +	float *line = new float[xsz * 3];
    1.59 +	int scansz = xsz * 3 * sizeof(float);
    1.60 +
    1.61 +	for(int i=0; i<ysz / 2; i++) {
    1.62 +		memcpy(line, top_ptr, scansz);
    1.63 +		memcpy(top_ptr, bot_ptr, scansz);
    1.64 +		memcpy(bot_ptr, line, scansz);
    1.65 +		top_ptr += xsz * 3;
    1.66 +		bot_ptr -= xsz * 3;
    1.67 +	}
    1.68 +
    1.69 +	delete [] line;
    1.70 +}