KrisLibrary  1.0.0
GLScreenshotProgram.h
1 #ifndef GL_SCREENSHOT_PROGRAM_H
2 #define GL_SCREENSHOT_PROGRAM_H
3 
4 #include <KrisLibrary/Logger.h>
5 #include "GLScreenshot.h"
7 #include <KrisLibrary/Timer.h>
8 #include <string>
9 
10 namespace GLDraw {
11 
25 template <class BaseGUI>
26 class GLScreenshotProgram : public BaseGUI
27 {
28 public:
29  std::string screenshotFile;
30  bool saveMovie;
31  double lastScreenshotTime;
32  double frameTime;
33  Timer timer;
34  int verbose;
35 
37  {
38  saveMovie = false;
39  lastScreenshotTime = 0;
40  frameTime = 1.0/30.0;
41  screenshotFile = "image0000.ppm";
42  verbose = 1;
43  }
44 
45  virtual ~GLScreenshotProgram() {}
46 
47  void SaveScreenshot()
48  {
49  GLSaveScreenshotPPM(screenshotFile.c_str());
50  if(verbose) LOG4CXX_INFO(KrisLibrary::logger(),"Screenshot saved to "<<screenshotFile.c_str());
51  }
52 
53  void StartMovie()
54  {
55  saveMovie = true;
56  lastScreenshotTime = 0;
57  timer.Reset();
58  }
59 
60  void StopMovie()
61  {
62  saveMovie = false;
63  }
64 
65  void ToggleMovie()
66  {
67  if(saveMovie) StopMovie();
68  else StartMovie();
69  }
70 
71  //call this if you want a real-time movie
72  void MovieUpdate()
73  {
74  this->MovieUpdate(timer.ElapsedTime());
75  }
76 
77  //call this if you want to control movie time
78  void MovieUpdate(double t)
79  {
80  if(saveMovie) {
81  if(t >= lastScreenshotTime + frameTime) {
82  LOG4CXX_INFO(KrisLibrary::logger(),"Time "<<t<<" last "<<lastScreenshotTime<<", Saving "<<(int)Floor((t-lastScreenshotTime)/frameTime));
83  while(lastScreenshotTime+frameTime < t) {
84  SaveScreenshot();
85  IncrementStringDigits(screenshotFile);
86  lastScreenshotTime += frameTime;
87  }
88  }
89  }
90  }
91 };
92 
93 } //namespace GLDraw
94 
95 #endif
Contains all definitions in the GLDraw package.
Definition: AnyGeometry.h:14
The logging system used in KrisLibrary.
Utilities for string manipulation.
Definition: Timer.h:6
A plugin class that "automatically" saves a movie to disk in the form of PPM screenshots.
Definition: GLScreenshotProgram.h:26