2
PLIB - A Suite of Portable Game Libraries
3
Copyright (C) 1998,2002 Steve Baker
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.
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.
15
You should have received a copy of the GNU Library General Public
16
License along with this library; if not, write to the Free Software
17
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19
For further information visit http://plib.sourceforge.net
21
$Id: ssgaScreenDump.cxx,v 1.3 2004/02/16 02:26:28 sjbaker Exp $
31
static void writeByte ( FILE *fd, unsigned char x )
33
fwrite ( & x, sizeof(unsigned char), 1, fd ) ;
37
static void writeShort ( FILE *fd, unsigned short x )
39
x = ulEndianBig16 ( x ) ;
40
fwrite ( & x, sizeof(unsigned short), 1, fd ) ;
44
static void writeInt ( FILE *fd, unsigned int x )
46
x = ulEndianBig32 ( x ) ;
47
fwrite ( & x, sizeof(unsigned int), 1, fd ) ;
51
void ssgaScreenDump ( char *filename, int xsize, int ysize, int frontBuffer )
53
FILE *fd = fopen ( filename, "wb" ) ;
57
fprintf ( stderr, "Failed to open '%s' for writing screendump.\n",
62
unsigned char *row = new unsigned char [ xsize ] ;
63
unsigned char *buffer = ssgaScreenDump ( xsize, ysize, frontBuffer ) ;
65
char type = 0 /* RGB_IMG_VERBATIM */ ;
71
short magic = 0x01DA /* RGB_IMG_MAGIC */ ;
75
writeShort ( fd, magic ) ;
76
writeByte ( fd, type ) ;
77
writeByte ( fd, bpp ) ;
78
writeShort ( fd, dim ) ;
79
writeShort ( fd, xsize ) ;
80
writeShort ( fd, ysize ) ;
81
writeShort ( fd, zsize ) ;
82
writeInt ( fd, min ) ;
83
writeInt ( fd, max ) ;
84
writeInt ( fd, 0 ) ; /* Dummy field */
86
for ( i = 0 ; i < 80 ; i++ )
87
writeByte ( fd, '\0' ) ; /* Name field */
89
writeInt ( fd, colormap ) ;
91
for ( i = 0 ; i < 404 ; i++ )
92
writeByte ( fd, 0 ) ; /* Dummy field */
94
for ( int z = 0 ; z < 3 ; z++ )
95
for ( int y = 0 ; y < ysize ; y++ )
97
for ( i = 0 ; i < xsize ; i++ )
98
row [ i ] = buffer [ ( y * xsize + i ) * 3 + z ] ;
100
fseek ( fd, ( z * ysize + y ) * xsize + 512, SEEK_SET ) ;
101
fwrite ( row, 1, xsize, fd ) ;
111
unsigned char *ssgaScreenDump ( int xsize, int ysize, int frontBuffer )
113
unsigned char *buffer = new unsigned char [ xsize * ysize * 3 ] ;
116
glReadBuffer ( GL_FRONT ) ;
118
glReadPixels( 0, 0, xsize, ysize, GL_RGB, GL_UNSIGNED_BYTE,
121
glReadBuffer ( GL_BACK ) ;