- added ability to specify scaled image size of screenshots in g3d viewer example:

./megaglest_g3dviewer --load-unit=techs/megapack/factions/romans/units/catapult,attack_skill --auto-screenshot=resize-1024x768
This commit is contained in:
Mark Vejvoda 2012-01-06 18:49:33 +00:00
parent 8e4ed05159
commit d449517872
4 changed files with 39 additions and 9 deletions

View File

@ -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-<filename>");
printf("\n \t\tdisable_normals, saveas-<filename>, 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<int,int> 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<string> 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 {

View File

@ -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<int,int> *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;
}

View File

@ -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<int,int> *overrideSize);
bool hasActiveParticleSystem(ParticleSystem::ParticleSystemType typeName) const;
};

View File

@ -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<const char*>(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);
}