cubemapper

changeset 3:f5cc465eb735

save cubemaps of the same file format as the opened file
author John Tsiombikas <nuclear@member.fsf.org>
date Fri, 28 Jul 2017 15:50:00 +0300
parents e308561f9889
children 2bfafdced01a
files src/app.cc
diffstat 1 files changed, 16 insertions(+), 10 deletions(-) [+]
line diff
     1.1 --- a/src/app.cc	Fri Jul 28 13:24:34 2017 +0300
     1.2 +++ b/src/app.cc	Fri Jul 28 15:50:00 2017 +0300
     1.3 @@ -16,7 +16,7 @@
     1.4  
     1.5  static void flip_image(float *pixels, int xsz, int ysz);
     1.6  
     1.7 -static const char *img_fname;
     1.8 +static const char *img_fname, *img_suffix;
     1.9  static float cam_theta, cam_phi;
    1.10  
    1.11  static Texture *pano_tex;
    1.12 @@ -63,6 +63,10 @@
    1.13  	}
    1.14  	printf("loaded image: %dx%d\n", pano_tex->get_width(), pano_tex->get_height());
    1.15  
    1.16 +	if(!(img_suffix = strrchr(img_fname, '.'))) {
    1.17 +		img_suffix = ".jpg";
    1.18 +	}
    1.19 +
    1.20  	// create cubemap
    1.21  	cube_size = pano_tex->get_height();
    1.22  	glGenTextures(1, &cube_tex);
    1.23 @@ -149,14 +153,15 @@
    1.24  	viewmat[4].rotation_y(deg_to_rad(180));	// +Z
    1.25  
    1.26  	// this must coincide with the order of GL_TEXTURE_CUBE_MAP_* values
    1.27 -	static const char *fname[] = {
    1.28 -		"cubemap_px.jpg",
    1.29 -		"cubemap_nx.jpg",
    1.30 -		"cubemap_py.jpg",
    1.31 -		"cubemap_ny.jpg",
    1.32 -		"cubemap_pz.jpg",
    1.33 -		"cubemap_nz.jpg"
    1.34 +	static const char *fname_pattern[] = {
    1.35 +		"cubemap_px%s",
    1.36 +		"cubemap_nx%s",
    1.37 +		"cubemap_py%s",
    1.38 +		"cubemap_ny%s",
    1.39 +		"cubemap_pz%s",
    1.40 +		"cubemap_nz%s"
    1.41  	};
    1.42 +	static char fname[64];
    1.43  
    1.44  	glMatrixMode(GL_PROJECTION);
    1.45  	glPushMatrix();
    1.46 @@ -181,8 +186,9 @@
    1.47  		glGetTexImage(GL_TEXTURE_CUBE_MAP_POSITIVE_X + i, 0, GL_RGB, GL_FLOAT, pixels);
    1.48  		//flip_image(pixels, cube_size, cube_size);
    1.49  
    1.50 -		if(img_save_pixels(fname[i], pixels, cube_size, cube_size, IMG_FMT_RGBF) == -1) {
    1.51 -			fprintf(stderr, "failed to save %dx%d image: %s\n", cube_size, cube_size, fname[i]);
    1.52 +		sprintf(fname, fname_pattern[i], img_suffix);
    1.53 +		if(img_save_pixels(fname, pixels, cube_size, cube_size, IMG_FMT_RGBF) == -1) {
    1.54 +			fprintf(stderr, "failed to save %dx%d image: %s\n", cube_size, cube_size, fname);
    1.55  		}
    1.56  	}
    1.57