cubemapper
changeset 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 |
files | src/app.cc src/app.h src/main.cc src/texture.cc src/texture.h |
diffstat | 5 files changed, 50 insertions(+), 1 deletions(-) [+] |
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 +}
2.1 --- a/src/app.h Thu Jul 27 20:36:12 2017 +0300 2.2 +++ b/src/app.h Fri Jul 28 07:44:35 2017 +0300 2.3 @@ -15,5 +15,6 @@ 2.4 void app_quit(); 2.5 void app_redisplay(); 2.6 void app_swap_buffers(); 2.7 +void app_resize(int x, int y); 2.8 2.9 #endif // APP_H_
3.1 --- a/src/main.cc Thu Jul 27 20:36:12 2017 +0300 3.2 +++ b/src/main.cc Fri Jul 28 07:44:35 2017 +0300 3.3 @@ -14,9 +14,9 @@ 3.4 3.5 int main(int argc, char **argv) 3.6 { 3.7 + glutInitWindowSize(1024, 768); 3.8 glutInit(&argc, argv); 3.9 glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE); 3.10 - glutInitWindowSize(1024, 768); 3.11 glutCreateWindow("cubemapper"); 3.12 3.13 glutDisplayFunc(display); 3.14 @@ -49,6 +49,11 @@ 3.15 glutSwapBuffers(); 3.16 } 3.17 3.18 +void app_resize(int x, int y) 3.19 +{ 3.20 + glutReshapeWindow(x, y); 3.21 +} 3.22 + 3.23 static void display() 3.24 { 3.25 app_draw();
4.1 --- a/src/texture.cc Thu Jul 27 20:36:12 2017 +0300 4.2 +++ b/src/texture.cc Fri Jul 28 07:44:35 2017 +0300 4.3 @@ -27,6 +27,16 @@ 4.4 return x + 1; 4.5 } 4.6 4.7 +int Texture::get_width() const 4.8 +{ 4.9 + return width; 4.10 +} 4.11 + 4.12 +int Texture::get_height() const 4.13 +{ 4.14 + return height; 4.15 +} 4.16 + 4.17 bool Texture::load(const char *fname) 4.18 { 4.19 img_pixmap img;
5.1 --- a/src/texture.h Thu Jul 27 20:36:12 2017 +0300 5.2 +++ b/src/texture.h Fri Jul 28 07:44:35 2017 +0300 5.3 @@ -14,6 +14,9 @@ 5.4 Texture(); 5.5 ~Texture(); 5.6 5.7 + int get_width() const; 5.8 + int get_height() const; 5.9 + 5.10 bool load(const char *fname); 5.11 5.12 const Mat4 &texture_matrix() const;