From e6e1e5deb60ccbb4fa175066820d81ad1bf1cefa Mon Sep 17 00:00:00 2001 From: John Tsiombikas Date: Thu, 8 Dec 2016 02:41:55 +0200 Subject: [PATCH] added the capability to crudely resize images by half in image.cc --- src/app.cc | 6 ++++++ src/image.cc | 28 ++++++++++++++++++++++++++++ src/image.h | 2 ++ src/texture.cc | 14 ++++++++++---- 4 files changed, 46 insertions(+), 4 deletions(-) diff --git a/src/app.cc b/src/app.cc index ca750fa..e135ddf 100644 --- a/src/app.cc +++ b/src/app.cc @@ -574,6 +574,7 @@ static void toggle_flight() static void calc_framerate() { + static int ncalc; static int nframes; static long prev_upd; @@ -582,6 +583,11 @@ static void calc_framerate() framerate = (float)nframes / (float)(elapsed * 0.001); nframes = 1; prev_upd = time_msec; + + if(++ncalc >= 5) { + printf("fps: %f\n", framerate); + ncalc = 0; + } } else { ++nframes; } diff --git a/src/image.cc b/src/image.cc index c245212..e79073d 100644 --- a/src/image.cc +++ b/src/image.cc @@ -143,6 +143,34 @@ void Image::rotate_180() flip_horizontal(); } +void Image::resize_half() +{ + int pixsz = pixel_size(fmt); + int newxsz = width / 2; + int newysz = height / 2; + + if(!newxsz || !newysz) return; + + unsigned char *newpix = new unsigned char[newxsz * newysz * pixsz]; + + unsigned char *sptr = (unsigned char*)pixels; + unsigned char *dptr = newpix; + + for(int i=0; i= 6) { return false; } @@ -276,7 +279,10 @@ bool Texture::set_image_cube(const Image &img, int idx) target = GL_TEXTURE_CUBE_MAP; glBindTexture(target, id); - assert(glGetError() == GL_NO_ERROR); + if((err = glGetError()) == GL_INVALID_OPERATION) { + return false; // probably not a cubemap + } + assert(err == GL_NO_ERROR); glTexParameteri(target, GL_TEXTURE_MIN_FILTER, GL_LINEAR); glTexParameteri(target, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glTexParameteri(target, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); @@ -301,15 +307,15 @@ bool Texture::set_image_cube(const Image &img) int xsz = img.get_width(); int ysz = img.get_height(); - if(xsz / 4 == ysz / 3) { + if((xsz << 8) / 4 == (ysz << 8) / 3) { // horizontal cross, assume the vertical bit is center-left return set_cube_multi(img, hcross[0], hcross[1], xsz / 4); } - if(xsz / 3 == ysz / 4) { + if((xsz << 8) / 3 == (ysz << 8) / 4) { // vertical cross, assume the horizontal bit is center-top (180-rotated image 5) return set_cube_multi(img, vcross[0], vcross[1], ysz / 4, (1 << 5)); } - if(xsz / 3 == ysz / 2) { + if((xsz << 8) / 3 == (ysz << 8) / 2) { // horizontal sixpack return set_cube_multi(img, hsix[0], hsix[1], ysz / 2); } -- 1.7.10.4