# HG changeset patch # User John Tsiombikas # Date 1501420617 -10800 # Node ID 614295b723417b79fc70788fde39a532fbc96699 # Parent 2bfafdced01aac8da6b4bc26f5ae75b4aefe4174 minor fixes, and redundant code removal diff -r 2bfafdced01a -r 614295b72341 src/app.cc --- a/src/app.cc Sun Jul 30 16:11:19 2017 +0300 +++ b/src/app.cc Sun Jul 30 16:16:57 2017 +0300 @@ -31,13 +31,11 @@ static void draw_cubemap(); static bool parse_args(int argc, char **argv); -static void flip_image(float *pixels, int xsz, int ysz); - static const char *img_fname, *img_suffix; static float cam_theta, cam_phi; -static Texture *pano_tex; -static Mesh *pano_mesh; +static Texture *tex; +static Mesh *mesh; static int win_width, win_height; static int show_cubemap; @@ -64,28 +62,28 @@ glEnable(GL_MULTISAMPLE); Mesh::use_custom_sdr_attr = false; - pano_mesh = new Mesh; - gen_sphere(pano_mesh, 1.0, 80, 40); - pano_mesh->flip(); + mesh = new Mesh; + gen_sphere(mesh, 1.0, 80, 40); + mesh->flip(); Mat4 xform; xform.rotation_y(-M_PI / 2.0); // rotate the sphere to face the "front" part of the image - pano_mesh->apply_xform(xform, xform); + mesh->apply_xform(xform, xform); xform.scaling(-1, 1, 1); // flip horizontal texcoord since we're inside the sphere - pano_mesh->texcoord_apply_xform(xform); + mesh->texcoord_apply_xform(xform); - pano_tex = new Texture; - if(!pano_tex->load(img_fname)) { + tex = new Texture; + if(!tex->load(img_fname)) { return false; } - printf("loaded image: %dx%d\n", pano_tex->get_width(), pano_tex->get_height()); + printf("loaded image: %dx%d\n", tex->get_width(), tex->get_height()); if(!(img_suffix = strrchr(img_fname, '.'))) { img_suffix = ".jpg"; } // create cubemap - cube_size = pano_tex->get_height(); + cube_size = tex->get_height(); glGenTextures(1, &cube_tex); glBindTexture(GL_TEXTURE_CUBE_MAP, cube_tex); glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR); @@ -116,8 +114,8 @@ void app_cleanup() { - delete pano_mesh; - delete pano_tex; + delete mesh; + delete tex; } void app_draw() @@ -199,9 +197,7 @@ draw_equilateral(); - //glReadPixels(0, 0, cube_size, cube_size, GL_RGB, GL_FLOAT, pixels); glGetTexImage(GL_TEXTURE_CUBE_MAP_POSITIVE_X + i, 0, GL_RGB, GL_FLOAT, pixels); - //flip_image(pixels, cube_size, cube_size); sprintf(fname, fname_pattern[i], img_suffix); if(img_save_pixels(fname, pixels, cube_size, cube_size, IMG_FMT_RGBF) == -1) { @@ -223,9 +219,9 @@ static void draw_equilateral() { - pano_tex->bind(); + tex->bind(); glEnable(GL_TEXTURE_2D); - pano_mesh->draw(); + mesh->draw(); glDisable(GL_TEXTURE_2D); } @@ -239,7 +235,7 @@ glEnable(GL_TEXTURE_GEN_T); glEnable(GL_TEXTURE_GEN_R); - pano_mesh->draw(); + mesh->draw(); glPopAttrib(); } @@ -271,6 +267,8 @@ case 'c': render_cubemap(); + show_cubemap = 1; + app_redisplay(); break; } } @@ -311,15 +309,8 @@ { for(int i=1; i