home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Cutting-Edge 3D Game Programming with C++
/
CE3DC++.ISO
/
BOOK
/
CHAP12
/
TEXTTYPE.CPP
< prev
next >
Wrap
C/C++ Source or Header
|
1996-05-30
|
2KB
|
123 lines
//
// File name: TextType.CPP
//
// Description:
//
// Author: John De Goes
//
// Project: Cutting Edge 3D Game Programming
//
#include <StdIO.H>
#define DOS
#ifdef DOS
#include <IOStream.H>
#endif
#include "TextType.HPP"
int ImageData::LoadINI ( char *FileName )
{
int ErrCode, FileCount = 0, N;
char String [ 256 ];
#ifdef DOS
double IPos;
#endif
FILE *InFile;
if ( ( InFile = fopen ( FileName, "rt" ) ) == 0 )
return 0;
for ( ;; )
{
ErrCode = fscanf ( InFile, "%s", String );
if ( ( ErrCode != 0 ) && ( ErrCode != EOF ) )
++FileCount;
else break;
}
rewind ( InFile );
TCount = FileCount;
if ( ( TMap = new BMPImage [ TCount ] ) == 0 )
{
fclose ( InFile );
return 0;
}
#ifdef DOS
cout << "\nLoading texture data:\n";
#endif
for ( N = 0; N < TCount; N++ )
{
#ifdef DOS
IPos = ( ( double ) N / ( double ) TCount ) * 101.0F;
cout << ( ( long ) IPos ) << "%\r";
#endif
fscanf ( InFile, "%s", String );
if ( TMap [ N ].Load ( String ) != BMPImage::Success )
{
fclose ( InFile );
return 0;
}
}
fclose ( InFile );
return 1;
}
int ImageData::LoadBT ( FILE *InFile )
{
int N;
#ifdef DOS
double IPos;
#endif
// Load the number of textures:
fread ( &TCount, sizeof TCount, 1, InFile );
// Allocate memory for bitmap images:
if ( ( TMap = new BMPImage [ TCount ] ) == 0 )
return 0;
// Load palette:
TMap [ 0 ].LoadPal ( InFile );
// Assign palette to all images:
for ( N = 1; N < TCount; N++ )
TMap [ N ].Palette = TMap [ 0 ].Palette;
#ifdef DOS
cout << "\nLoading texture data:\n";
#endif
// Load the textures:
for ( N = 0; N < TCount; N++ )
{
#ifdef DOS
IPos = ( ( double ) N / ( double ) TCount ) * 101.0F;
cout << ( ( long ) IPos ) << "%\r";
#endif
if ( TMap [ N ].LoadBT ( InFile ) == 0 )
return 0;
}
return 1;
}
int ImageData::SaveBT ( FILE *OutFile )
{
int N;
// Save the number of texture maps:
fwrite ( &TCount, sizeof TCount, 1, OutFile );
// Save the palette:
TMap [ 0 ].SavePal ( OutFile );
// Save the texture data:
for ( N = 0; N < TCount; N++ )
{
if ( TMap [ N ].SaveBT ( OutFile ) == 0 )
return 0;
}
return 1;
}