Browse Source

use GraphicsWindow.saveScreenshot() to save screenshot

David Rose 22 years ago
parent
commit
0022871ce6

+ 7 - 12
direct/src/showbase/ShowBase.py

@@ -1380,19 +1380,14 @@ class ShowBase(DirectObject.DirectObject):
                 self.oobeCullFrustumVis = None
                 self.oobeCullFrustumVis = None
 
 
     def screenshot(self, namePrefix='screenshot'):
     def screenshot(self, namePrefix='screenshot'):
-        # Get the current date and time to uniquify the image (down to the second)
-        date = time.ctime(time.time())
-        # Get the current frame count to uniquify it even more
-        frameCount = globalClock.getFrameCount()
-        # Replace spaces with dashes because unix does not like spaces in the filename
-        date = date.replace(' ', '-')
-        date = date.replace(':', '-')
-        imageName = ('%s-%s-%d.%s' % (namePrefix, date, frameCount, self.screenshotExtension))
-        self.notify.info("Taking screenshot: " + imageName)
-
-        takeSnapshot(self.win, imageName)
+        filename = self.win.saveScreenshotDefault(namePrefix)
+        if filename.empty():
+            # The screenshot attempt failed for some reason.
+            return 0
+        
         # Announce to anybody that a screenshot has been taken
         # Announce to anybody that a screenshot has been taken
-        messenger.send('screenshot')
+        messenger.send('screenshot', [filename])
+        return 1
 
 
     def movie(self, namePrefix = 'movie', duration = 1.0, fps = 30,
     def movie(self, namePrefix = 'movie', duration = 1.0, fps = 30,
               format = 'rgb', sd = 4):
               format = 'rgb', sd = 4):

+ 0 - 19
direct/src/showbase/showBase.cxx

@@ -44,25 +44,6 @@ throw_new_frame() {
   throw_event("NewFrame");
   throw_event("NewFrame");
 }
 }
 
 
-
-void
-take_snapshot(GraphicsWindow *win, const string &name) {
-  GraphicsStateGuardian* gsg = win->get_gsg();
-  RenderBuffer rb = gsg->get_render_buffer(RenderBuffer::T_front);
-
-  CPT(DisplayRegion) dr = win->get_display_region(0);
-  nassertv(dr != (DisplayRegion *)NULL);
-
-  int width = dr->get_pixel_width();
-  int height = dr->get_pixel_height();
-
-  PixelBuffer p(width, height, 3, 1, PixelBuffer::T_unsigned_byte,
-                PixelBuffer::F_rgb);
-
-  p.copy(gsg, dr, rb);
-  p.write(name);
-}
-
 // Returns the configure object for accessing config variables from a
 // Returns the configure object for accessing config variables from a
 // scripting language.
 // scripting language.
 ConfigShowbase &
 ConfigShowbase &

+ 0 - 2
direct/src/showbase/showBase.h

@@ -43,8 +43,6 @@ EXPCL_DIRECT DSearchPath &get_particle_path();
 
 
 EXPCL_DIRECT void throw_new_frame();
 EXPCL_DIRECT void throw_new_frame();
 
 
-EXPCL_DIRECT void take_snapshot(GraphicsWindow *win, const string &name);
-
 EXPCL_DIRECT ConfigShowbase &get_config_showbase();
 EXPCL_DIRECT ConfigShowbase &get_config_showbase();