home *** CD-ROM | disk | FTP | other *** search
/ Cutting-Edge 3D Game Programming with C++ / CE3DC++.ISO / BOOK / CHAP14 / TEXTTYPE.CPP < prev    next >
Encoding:
C/C++ Source or Header  |  1996-01-27  |  1.9 KB  |  96 lines

  1. //
  2. // File name: TextType.CPP
  3. //
  4. // Description:
  5. //
  6. // Author: John De Goes
  7. //
  8. // Project: Cutting Edge 3D Game Programming
  9. //
  10.  
  11. #include <StdIO.H>
  12.  
  13. #include "TextType.HPP"
  14.  
  15. int ImageData::LoadINI ( char *FileName )
  16.   {
  17.   int ErrCode, FileCount = 0, N;
  18.   char String [ 256 ];
  19.   FILE *InFile;
  20.   if ( ( InFile = fopen ( FileName, "rt" ) ) == 0 )
  21.      return 0;
  22.  
  23.   for ( ;; )
  24.       {
  25.       ErrCode = fscanf ( InFile, "%s", String );
  26.       if ( ( ErrCode != 0 ) && ( ErrCode != EOF ) )
  27.          ++FileCount;
  28.       else break;
  29.       }
  30.  
  31.   rewind ( InFile );
  32.  
  33.   TCount = FileCount;
  34.   if ( ( TMap = new BMPImage [ TCount ] ) == 0 )
  35.      {
  36.      fclose ( InFile );
  37.      return 0;
  38.      }
  39.  
  40.   for ( N = 0; N < TCount; N++ )
  41.       {
  42.       fscanf ( InFile, "%s", String );
  43.       if ( TMap [ N ].Load ( String ) != BMPImage::Success )
  44.          {
  45.          fclose ( InFile );
  46.          return 0;
  47.          }
  48.       }
  49.   return 1;
  50.   }
  51.  
  52. int ImageData::LoadBT ( FILE *InFile )
  53.   {
  54.   int N;
  55.  
  56.   // Load the number of textures:
  57.   fread ( &TCount, sizeof TCount, 1, InFile );
  58.  
  59.   // Allocate memory for bitmap images:
  60.   if ( ( TMap = new BMPImage [ TCount ] ) == 0 )
  61.      return 0;
  62.  
  63.   // Load palette:
  64.   TMap [ 0 ].LoadPal ( InFile );
  65.  
  66.   // Assign palette to all images:
  67.   for ( N = 1; N < TCount; N++ )
  68.       TMap [ N ].Palette = TMap [ 0 ].Palette;
  69.  
  70.   // Load the textures:
  71.   for ( N = 0; N < TCount; N++ )
  72.       {
  73.       if ( TMap [ N ].LoadBT ( InFile ) == 0 )
  74.          return 0;
  75.       }
  76.   return 1;
  77.   }
  78.  
  79. int ImageData::SaveBT ( FILE *OutFile )
  80.   {
  81.   int N;
  82.   // Save the number of texture maps:
  83.   fwrite ( &TCount, sizeof TCount, 1, OutFile );
  84.  
  85.   // Save the palette:
  86.   TMap [ 0 ].SavePal ( OutFile );
  87.  
  88.   // Save the texture data:
  89.   for ( N = 0; N < TCount; N++ )
  90.       {
  91.       if ( TMap [ N ].SaveBT ( OutFile ) == 0 )
  92.          return 0;
  93.       }
  94.   return 1;
  95.   }
  96.