Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: Taking multiple screenshots in succession  (Read 2128 times)

0 Members and 2 Guests are viewing this topic.

gws923

  • Jr. Member
  • **
  • Posts: 60
    • View Profile
Taking multiple screenshots in succession
« on: October 04, 2014, 09:46:47 pm »
Hi guys.  I haven't turned to you all for help in quite a while, but you're always so helpful when I do.  Anyway, if anyone can help I will very much appreciate it.

I have essentially built a level editor to create large maps for a game.  I'd like to compile a whole map into one image so I can edit it in photoshop (my artist takes the "skeletons" I create in the editor and then fills them in.  Like color-by-numbers).

I've compiled a few maps by manually moving the screen, taking a screenshot, then pasting it into paint and fitting all the screenshots together.  Needless to say, this is a huge pain in the ass.  So, I'd like to convince my program to do it for me.  Here's my code:
void SaveLoad::saveLevelImage(std::string fileName)
{
    // Loop through and capture each section of the level.
    for(int viewX = 0; viewX < _editor->_mapWidth; viewX += 1920)
    {
        for(int viewY = 0; viewY < _editor->_mapHeight; viewY += 1080)
        {
            std::stringstream path;
            path << "levels/" << fileName << "/map/" << fileName << viewX << "." << viewY << ".png";

            sf::Image screenToSave;
            screenToSave = _editor->renderWindow()->capture();
            screenToSave.saveToFile(path.str());

            _editor->_contentView.move(0, 1080);
        }
        // After completing a column, return the window back to the top.
        _editor->_contentView.setCenter(_editor->_contentView.getCenter().x, 540);

        // Move over to the next row and start over.
        _editor->_contentView.move(1920, 0);
    }
}
 

When I run the code, the expected files appear in the directory I specified, but they're all blank.  I don't know if SFML simply can't handle my request to capture the screen and save it so many times so quickly or what. 

I was thinking I'd later use a python script to actually combine the images into one, but if I can't get this part to work, then that's not going to be useful.  However, if anyone has any thoughts about combining both steps into one, that would be awesome as well.

Thank you!

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: Taking multiple screenshots in succession
« Reply #1 on: October 04, 2014, 10:36:35 pm »
What you do before each capture is just moving some view. Maybe you would see something if you apply this view, draw stuff, and display it on your window every time you move the view ;)
Laurent Gomila - SFML developer

gws923

  • Jr. Member
  • **
  • Posts: 60
    • View Profile
Re: Taking multiple screenshots in succession
« Reply #2 on: October 04, 2014, 10:39:32 pm »
Laurent, you are a good dude.  Thanks for the help! (And thanks, of course, for SFML).

P.s.  I am a dumb dumb.

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: Taking multiple screenshots in succession
« Reply #3 on: October 04, 2014, 10:46:59 pm »
Note that since this whole process is supposed to happen off-screen, you can use a sf::RenderTexture instead of drawing to your window.
Laurent Gomila - SFML developer

 

anything