diff --git a/source/g3d_viewer/main.cpp b/source/g3d_viewer/main.cpp index 87e5745a4..3996365e7 100644 --- a/source/g3d_viewer/main.cpp +++ b/source/g3d_viewer/main.cpp @@ -199,9 +199,9 @@ void printParameterHelp(const char *argv0, bool foundInvalidArgs) { printf("\n \t\t of the optional settings:"); printf("\n \t\ttransparent, enable_grid, enable_wireframe,"); printf("\n \t\tenable_normals, disable_grid, disable_wireframe,"); - printf("\n \t\tdisable_normals, saveas-"); + printf("\n \t\tdisable_normals, saveas-, resize-wxh"); printf("\n \t\texample:"); - printf("\n %s %s=transparent,disable_grid,saveas-test.png %s=techs/megapack/factions/tech/units/battle_machine/models/battle_machine_dying.g3d",extractFileFromDirectoryPath(argv0).c_str(),(const char *)wxConvCurrent->cWX2MB(GAME_ARGS[GAME_ARG_AUTO_SCREENSHOT]),(const char *)wxConvCurrent->cWX2MB(GAME_ARGS[GAME_ARG_LOAD_MODEL])); + printf("\n %s %s=transparent,disable_grid,saveas-test.png,resize-800x600 %s=techs/megapack/factions/tech/units/battle_machine/models/battle_machine_dying.g3d",extractFileFromDirectoryPath(argv0).c_str(),(const char *)wxConvCurrent->cWX2MB(GAME_ARGS[GAME_ARG_AUTO_SCREENSHOT]),(const char *)wxConvCurrent->cWX2MB(GAME_ARGS[GAME_ARG_LOAD_MODEL])); // "================================================================================" printf("\n%s=x",(const char *)wxConvCurrent->cWX2MB(GAME_ARGS[GAME_ARG_LOAD_PARTICLE])); @@ -950,6 +950,22 @@ void MainWindow::onMenumFileToggleScreenshotTransparent(wxCommandEvent &event) { void MainWindow::saveScreenshot() { try { + std::pair overrideSize(0,0); + for(unsigned int i = 0; i < autoScreenShotParams.size(); ++i) { + if(_strnicmp(autoScreenShotParams[i].c_str(),"resize-",7) == 0) { + printf("Screenshot option [%s]\n",autoScreenShotParams[i].c_str()); + + string resize = autoScreenShotParams[i]; + resize = resize.erase(0,7); + vector values; + Tokenize(resize,values,"x"); + overrideSize.first = strToInt(values[0]); + overrideSize.second = strToInt(values[1]); + + break; + } + } + int autoSaveScreenshotIndex = -1; for(unsigned int i = 0; i < autoScreenShotParams.size(); ++i) { if(_strnicmp(autoScreenShotParams[i].c_str(),"saveas-",7) == 0) { @@ -967,7 +983,7 @@ void MainWindow::saveScreenshot() { FILE *f= fopen(saveAsFilename.c_str(), "rb"); #endif if(f == NULL) { - renderer->saveScreen(saveAsFilename.c_str()); + renderer->saveScreen(saveAsFilename.c_str(),&overrideSize); } else { if(f) { @@ -1002,7 +1018,7 @@ void MainWindow::saveScreenshot() { FILE *f= fopen(path.c_str(), "rb"); #endif if(f == NULL) { - renderer->saveScreen(path); + renderer->saveScreen(path,&overrideSize); break; } else { diff --git a/source/g3d_viewer/renderer.cpp b/source/g3d_viewer/renderer.cpp index 7a5e15890..95d61d501 100644 --- a/source/g3d_viewer/renderer.cpp +++ b/source/g3d_viewer/renderer.cpp @@ -483,7 +483,7 @@ void Renderer::setAlphaColor(float alpha) { //printf("#3.1 The framebuffer uses %d bit(s) per the alpha component\n", alpha_bits); } -void Renderer::saveScreen(const string &path) { +void Renderer::saveScreen(const string &path,std::pair *overrideSize) { Pixmap2D *pixmapScreenShot = new Pixmap2D(width, height, 4); //glFinish(); @@ -494,6 +494,10 @@ void Renderer::saveScreen(const string &path) { glPixelStorei(GL_UNPACK_ALIGNMENT, 1); + if(overrideSize != NULL && overrideSize->first > 0 && overrideSize->second > 0) { + pixmapScreenShot->Scale(GL_RGBA,overrideSize->first,overrideSize->second); + } + pixmapScreenShot->save(path); delete pixmapScreenShot; } diff --git a/source/g3d_viewer/renderer.h b/source/g3d_viewer/renderer.h index 48b533e77..9a523bb76 100644 --- a/source/g3d_viewer/renderer.h +++ b/source/g3d_viewer/renderer.h @@ -157,7 +157,7 @@ public: void setBackgroundColor(float red, float green, float blue); void setAlphaColor(float alpha); - void saveScreen(const string &path); + void saveScreen(const string &path,std::pair *overrideSize); bool hasActiveParticleSystem(ParticleSystem::ParticleSystemType typeName) const; }; diff --git a/source/shared_lib/sources/graphics/pixmap.cpp b/source/shared_lib/sources/graphics/pixmap.cpp index d77933ebb..7e7b55601 100644 --- a/source/shared_lib/sources/graphics/pixmap.cpp +++ b/source/shared_lib/sources/graphics/pixmap.cpp @@ -916,20 +916,30 @@ Pixmap2D::~Pixmap2D() { void Pixmap2D::Scale(int format, int newW, int newH) { int useComponents = this->getComponents(); + int originalW = w; + int originalH = h; uint8 *newpixels= new uint8[newW * newH * useComponents]; glPixelStorei(GL_PACK_ALIGNMENT, 1); int error = gluScaleImage( format, w, h, GL_UNSIGNED_BYTE, pixels, newW, newH, GL_UNSIGNED_BYTE, newpixels); - if(error != GL_NO_ERROR) { + glPixelStorei(GL_UNPACK_ALIGNMENT, 1); + + if(error == GL_NO_ERROR) { init(newW,newH,this->components); pixels = newpixels; + + if(SystemFlags::VERBOSE_MODE_ENABLED) printf("Scaled image from [%d x %d] to [%d x %d]\n",originalW,originalH,w,h); } else { - assertGl(); + const char *errorString= reinterpret_cast(gluErrorString(error)); + printf("ERROR Scaling image from [%d x %d] to [%d x %d] error: %d [%s]\n",originalW,originalH,w,h,error,errorString); + + GLenum glErr = error; + assertGlWithErrorNumber(glErr); } - glPixelStorei(GL_UNPACK_ALIGNMENT, 1); + CalculatePixelsCRC(pixels,getPixelByteCount(), crc); }