From 1a28393dabf4f4696bf433ddde52e7a25253c955 Mon Sep 17 00:00:00 2001 From: Stijn Buys Date: Thu, 16 Oct 2008 16:34:15 +0000 Subject: various user interface related updates --- src/render/image.cc | 25 +++++++++++++++++++++++++ src/render/image.h | 3 +++ src/render/render.cc | 17 ++++++++++++++--- src/render/render.h | 3 +++ 4 files changed, 45 insertions(+), 3 deletions(-) (limited to 'src/render') diff --git a/src/render/image.cc b/src/render/image.cc index 7ce8113..e740d56 100644 --- a/src/render/image.cc +++ b/src/render/image.cc @@ -44,6 +44,31 @@ void Image::swap_channels() } } +void Image::pad() +{ + unsigned int w = width(); + unsigned int h = height(); + + if ((w % 8) != 0) { + image_width = w + (8 - (w % 8)); + } + + if ((w % 8) != 0) { + image_height = h + (8 - (h % 8)); + } + + unsigned char *image_new = (unsigned char *) malloc(size()); + memset(image_new, 0, size()); + + for (size_t y =0; y < h; y++) { + memcpy((void *)&image_new[y * image_width * image_channels], + (void *)image_data[y * w * image_channels], (size_t) w); + } + + free(image_data); + image_data = image_new; +} + void Image::flip() { unsigned char line[image_width*image_channels]; diff --git a/src/render/image.h b/src/render/image.h index 3c82792..c7add6f 100644 --- a/src/render/image.h +++ b/src/render/image.h @@ -47,6 +47,9 @@ public: /// flip upside-down void flip(); + /// pad width and height up to 8 bytes + void pad(); + private: unsigned char *image_data; diff --git a/src/render/render.cc b/src/render/render.cc index fbbaba1..55756d9 100644 --- a/src/render/render.cc +++ b/src/render/render.cc @@ -43,9 +43,6 @@ void func_list_textures(std::string const &args) void reset_gl() { - // setup our viewport. - gl::viewport(0, 0, Camera::width(), Camera::height()); - // set clear color gl::clearcolor(0.0f, 0.0f, 0.0f, 1.0f); @@ -152,6 +149,13 @@ void init() func->set_info("list loaded textures"); } +void resize(int width, int height) +{ + // setup our viewport. + gl::viewport(0, 0, width, height); + Camera::resize(width, height); +} + // unload game assets (zone change) void unload() { @@ -313,8 +317,15 @@ void screenshot() image.flip(); if (filetype == TYPEPNG) { +/* if ((Camera::width() % 8 != 0 ) || (Camera::height() % 8 != 0 )) { + image.pad(); + }*/ render::PNG::save(filename.c_str(), image); } else if (filetype == TYPEJPG) { +/* if ((Camera::width() % 8 != 0 ) || (Camera::height() % 8 != 0 )) { + image.pad(); + } +*/ render::JPG::save(filename.c_str(), image, (int) screenshotquality->value()); } else if (filetype == TYPETGA) { render::TGA::save(filename.c_str(), image); diff --git a/src/render/render.h b/src/render/render.h index cd90953..a7aec70 100644 --- a/src/render/render.h +++ b/src/render/render.h @@ -38,6 +38,9 @@ namespace render { /// make a screenshot void screenshot(); + /// resize viewport + void resize(int w, int h); + extern core::Cvar *r_arraysize; extern core::Cvar *r_bbox; extern core::Cvar *r_grid; -- cgit v1.2.3