Exemple #1
0
ImageData ReadImage(char* fileName)
{
    // Check that fileName ends in either jpg or png, and dispatch if so
    if (strcmp("png", fileName + strlen(fileName) - 3) == 0)
        return ReadPNG(fileName);
    else if (strcmp("jpg", fileName + strlen(fileName) - 3) == 0)
        return ReadJPG(fileName);
    else {
        ImageData meta;
        meta.valid = false;
        return meta;
    }
}
//*************************************************************************************
//	
//*************************************************************************************
CTexture *	CTextureManager::Create( const CString & filename, bool warn )
{
	CTexture *		p_texture( NULL );
	CFile * const	p_file( CFileSystem::Open( filename, "rb" ) );

	if ( p_file != NULL )
	{
		const CString	extension( p_file->GetExtension() );

		if ( extension == "png" || extension == "PNG" )
		{
			p_texture = ReadPNG( p_file );
		}
		else if ( extension == "tga" || extension == "TGA" )
		{
			p_texture = ReadTGA( p_file );
		}
		else if ( extension == "jpg" || extension == "JPG" )
		{
			p_texture = ReadJPG( p_file );
		}
		else if ( extension == "bmp" || extension == "BMP" )
		{
			p_texture = ReadBMP( p_file );
		}
		else
		{
			TRACE( "Unrecognised image extension %s\n", extension.GetPtr() );
			ASSERT( 0, "" );
		}

		CFileSystem::Close( p_file );
	}

	if ( p_texture == NULL )
	{
		if ( warn == true )
		{
			TRACE( "Failed to load image %s\n", filename.GetPtr() );
			ASSERT( 0, "" );
		}
	}

	return p_texture;
}