]> git.mxchange.org Git - simgear.git/blob - simgear/screen/screen-dump.cxx
Canvas: improved clipping and new property clip-frame.
[simgear.git] / simgear / screen / screen-dump.cxx
1 // screen-dump.cxx -- dump a copy of the opengl screen buffer to a file
2 //
3 // Contributed by Richard Kaszeta <bofh@me.umn.edu>, started October 1999.
4 //
5 // This library is free software; you can redistribute it and/or
6 // modify it under the terms of the GNU Library General Public
7 // License as published by the Free Software Foundation; either
8 // version 2 of the License, or (at your option) any later version.
9 //
10 // This library is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13 // Library General Public License for more details.
14 //
15 // You should have received a copy of the GNU General Public License
16 // along with this program; if not, write to the Free Software
17 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
18 //
19 // $Id$
20
21
22 #ifdef HAVE_CONFIG_H
23 #  include <simgear_config.h>
24 #endif
25
26 #include <simgear/compiler.h>
27
28 #include <osg/Image>
29 #include <osgDB/WriteFile>
30
31 #include "screen-dump.hxx"
32
33
34 // dump the screen buffer to a png file, returns true on success
35 bool sg_glDumpWindow(const char *filename, int win_width, int win_height) {
36   osg::ref_ptr<osg::Image> img(new osg::Image);
37   img->readPixels(0,0, win_width, win_height, GL_RGB, GL_UNSIGNED_BYTE);
38   return osgDB::writeImageFile(*img, filename);
39 }
40