+namespace
+{
+ using namespace flightgear;
+
+ SGPath nextScreenshotPath(const std::string& screenshotDir)
+ {
+ char filename[32];
+ static int count = 1;
+ while (count < 1000) {
+ snprintf(filename, 32, "fgfs-screen-%03d.png", count++);
+
+ SGPath p(screenshotDir);
+ p.append(filename);
+ if (!p.exists()) {
+ return p;
+ }
+ }
+
+ return SGPath();
+ }
+
+ class GUISnapShotOperation :
+ public GraphicsContextOperation
+ {
+ public:
+
+ // start new snap shot
+ static bool start()
+ {
+ // allow only one snapshot at a time
+ if (_snapShotOp.valid())
+ return false;
+ _snapShotOp = new GUISnapShotOperation();
+ /* register with graphics context so actual snap shot is done
+ * in the graphics context (thread) */
+ osg::Camera* guiCamera = getGUICamera(CameraGroup::getDefault());
+ WindowSystemAdapter* wsa = WindowSystemAdapter::getWSA();
+ osg::GraphicsContext* gc = 0;
+ if (guiCamera)
+ gc = guiCamera->getGraphicsContext();
+ if (gc) {
+ gc->add(_snapShotOp.get());
+ } else {
+ wsa->windows[0]->gc->add(_snapShotOp.get());
+ }
+ return true;
+ }