-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathframeGenerator.cpp
43 lines (39 loc) · 1.28 KB
/
frameGenerator.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#include <sys/stat.h>
#include <iostream>
#include <string>
#include <sstream>
#include <iomanip>
#include "frameGenerator.h"
#include "renderContext.h"
FrameGenerator::FrameGenerator() :
rend((RenderContext::getInstance()).getRenderer()),
window((RenderContext::getInstance()).getWindow()),
WIDTH( Gamedata::getInstance().getXmlInt("view/width") ),
HEIGHT( Gamedata::getInstance().getXmlInt("view/height") ),
USERNAME( Gamedata::getInstance().getXmlStr("username") ),
MAX_FRAMES( Gamedata::getInstance().getXmlInt("maxFrames") ),
frameCount(0)
{
struct stat info;
if( stat( "frames", &info ) != 0 ) {
mkdir("frames", 0755);
}
}
void FrameGenerator::makeFrame() {
if ( frameCount > MAX_FRAMES ) return;
SDL_SetRenderDrawColor( rend, 30, 144, 255, 255 );
SDL_Surface* screenCap = SDL_GetWindowSurface(window);
if ( screenCap ) {
SDL_RenderReadPixels(rend, NULL,
SDL_GetWindowPixelFormat(window),
screenCap->pixels, screenCap->pitch);
}
std::stringstream strm;
strm << "frames/" << USERNAME << '.'
<< std::setfill('0') << std::setw(4)
<< frameCount++ << ".bmp";
std::string filename( strm.str() );
std::cout << "Making frame: " << filename << std::endl;
SDL_SaveBMP(screenCap, filename.c_str());
SDL_FreeSurface(screenCap);
}