~ubuntu-branches/ubuntu/precise/plib/precise

« back to all changes in this revision

Viewing changes to src/ssgAux/ssgaScreenDump.cxx

  • Committer: Bazaar Package Importer
  • Author(s): Philipp Frauenfelder
  • Date: 2004-08-26 23:31:16 UTC
  • mfrom: (2.1.1 warty)
  • Revision ID: james.westby@ubuntu.com-20040826233116-vqusvk3ytn6lq3rl
Tags: 1.8.3-2
* Corrected C++ syntax in ssgAux/ssgaSky.h. Thanks to
  neuro.harald AT surfeu.at for the patch. Closes: #260355
* Build-Depends on libx11-dev, libxmu-dev instead of xlibs-dev
* Removed build depends on g++, libc6.
* Changed (build) depends on libgl-dev to xlibmesa-gl-dev | libgl-dev

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
     PLIB - A Suite of Portable Game Libraries
 
3
     Copyright (C) 1998,2002  Steve Baker
 
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 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
 
18
 
 
19
     For further information visit http://plib.sourceforge.net
 
20
 
 
21
     $Id: ssgaScreenDump.cxx,v 1.3 2004/02/16 02:26:28 sjbaker Exp $
 
22
*/
 
23
 
 
24
 
 
25
#include "ssgAux.h"
 
26
#include <string.h>
 
27
 
 
28
 
 
29
#include "ul.h"
 
30
 
 
31
static void writeByte ( FILE *fd, unsigned char x )
 
32
{
 
33
  fwrite ( & x, sizeof(unsigned char), 1, fd ) ;
 
34
}
 
35
 
 
36
 
 
37
static void writeShort ( FILE *fd, unsigned short x )
 
38
{
 
39
  x = ulEndianBig16 ( x ) ;
 
40
  fwrite ( & x, sizeof(unsigned short), 1, fd ) ;
 
41
}
 
42
 
 
43
 
 
44
static void writeInt ( FILE *fd, unsigned int x )
 
45
{
 
46
  x = ulEndianBig32 ( x ) ;
 
47
  fwrite ( & x, sizeof(unsigned int), 1, fd ) ;
 
48
}
 
49
 
 
50
 
 
51
void ssgaScreenDump ( char *filename, int xsize, int ysize, int frontBuffer )
 
52
{
 
53
  FILE *fd = fopen ( filename, "wb" ) ;
 
54
 
 
55
  if ( fd == NULL )
 
56
  {
 
57
    fprintf ( stderr, "Failed to open '%s' for writing screendump.\n", 
 
58
                       filename ) ;
 
59
    return ;
 
60
  }
 
61
 
 
62
  unsigned char *row    = new unsigned char [ xsize ] ;
 
63
  unsigned char *buffer = ssgaScreenDump ( xsize, ysize, frontBuffer ) ;
 
64
 
 
65
  char  type  =   0 /* RGB_IMG_VERBATIM */ ;
 
66
  short dim   =   3 ;
 
67
  short zsize =   3 ;
 
68
  char  bpp   =   1 ;
 
69
  int   min   =   0 ;
 
70
  int   max   = 255 ;
 
71
  short magic = 0x01DA /* RGB_IMG_MAGIC */ ;
 
72
  int   colormap = 0 ;
 
73
  int   i ;
 
74
 
 
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 */
 
85
 
 
86
  for ( i = 0 ; i < 80 ; i++ )
 
87
    writeByte ( fd, '\0' ) ;         /* Name field */
 
88
 
 
89
  writeInt ( fd, colormap ) ;
 
90
 
 
91
  for ( i = 0 ; i < 404 ; i++ )
 
92
    writeByte ( fd, 0 ) ;         /* Dummy field */
 
93
 
 
94
  for ( int z = 0 ; z < 3 ; z++ )
 
95
    for ( int y = 0 ; y < ysize ; y++ )
 
96
    {
 
97
      for ( i = 0 ; i < xsize ; i++ )
 
98
        row [ i ] = buffer [ ( y * xsize + i ) * 3 + z ] ;
 
99
 
 
100
      fseek ( fd, ( z * ysize + y ) * xsize + 512, SEEK_SET ) ;
 
101
      fwrite ( row, 1, xsize, fd ) ;
 
102
    }
 
103
 
 
104
  fclose ( fd ) ;
 
105
 
 
106
  delete row ;
 
107
  delete buffer ;
 
108
}
 
109
 
 
110
 
 
111
unsigned char *ssgaScreenDump ( int xsize, int ysize, int frontBuffer )
 
112
{
 
113
  unsigned char *buffer = new unsigned char [ xsize * ysize * 3 ] ;
 
114
 
 
115
  if ( frontBuffer )
 
116
    glReadBuffer ( GL_FRONT ) ;
 
117
 
 
118
  glReadPixels( 0, 0, xsize, ysize, GL_RGB, GL_UNSIGNED_BYTE,
 
119
                                                       (void *) buffer ) ;
 
120
  if ( frontBuffer )
 
121
    glReadBuffer ( GL_BACK ) ;
 
122
 
 
123
  return buffer ;
 
124
}
 
125
 
 
126