aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/src/others/mimesh/g3dviewer-0.2.99.4/src/screenshot.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/others/mimesh/g3dviewer-0.2.99.4/src/screenshot.c')
-rw-r--r--src/others/mimesh/g3dviewer-0.2.99.4/src/screenshot.c73
1 files changed, 73 insertions, 0 deletions
diff --git a/src/others/mimesh/g3dviewer-0.2.99.4/src/screenshot.c b/src/others/mimesh/g3dviewer-0.2.99.4/src/screenshot.c
new file mode 100644
index 0000000..f304666
--- /dev/null
+++ b/src/others/mimesh/g3dviewer-0.2.99.4/src/screenshot.c
@@ -0,0 +1,73 @@
1/* $Id: screenshot.c 41 2006-05-22 12:23:29Z mmmaddd $ */
2
3/*
4 G3DViewer - 3D object viewer
5
6 Copyright (C) 2005, 2006 Markus Dahms <mad@automagically.de>
7
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2 of the License, or
11 (at your option) any later version.
12
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
17
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21*/
22
23#ifdef HAVE_CONFIG_H
24# include <config.h>
25#endif
26
27#include <gdk-pixbuf/gdk-pixbuf.h>
28#include <GL/gl.h>
29
30static guint8 *screenshot_get_pixels(guint32 width, guint32 height)
31{
32 guint8 *pixels;
33
34 pixels = g_new(guint8, width * height * 4);
35
36 glReadPixels(0, 0, width, height, GL_RGBA, GL_UNSIGNED_BYTE, pixels);
37
38 return pixels;
39}
40
41gboolean screenshot_save(const gchar *filename, guint32 width, guint32 height)
42{
43 guint8 *pixels;
44 GdkPixbuf *pixbuf, *flipped;
45
46 pixels = screenshot_get_pixels(width, height);
47
48 if(pixels == NULL)
49 return FALSE;
50
51 pixbuf = gdk_pixbuf_new_from_data(pixels,
52 GDK_COLORSPACE_RGB, TRUE,
53 8, width, height, width * 4,
54 NULL, NULL);
55
56 if(pixbuf == NULL)
57 return FALSE;
58
59 /* GL returns pixels starting from lower left corner */
60 flipped = gdk_pixbuf_flip(pixbuf, FALSE);
61
62 if(flipped == NULL)
63 return FALSE;
64
65 gdk_pixbuf_save(flipped, filename, "png", NULL, NULL);
66
67 g_free(pixels);
68
69 gdk_pixbuf_unref(pixbuf);
70 gdk_pixbuf_unref(flipped);
71
72 return TRUE;
73}