unsigned char * Texture0;	/* the texture map			*/
unsigned char * Texture1;	/* the real texture map			*/
unsigned char * Texture2;	/* the real texture map			*/
unsigned char * Texture3;	/* the real texture map			*/
unsigned char * Texture4;	/* the real texture map			*/
unsigned char * Texture5;	/* the real texture map			*/
unsigned char * Texture6;	/* the real texture map			*/
unsigned char * Texture7;	/* the real texture map			*/
unsigned char * Texture8;	/* the real texture map			*/
unsigned int	TexName;	/* bound texture name			*/

unsigned char *		HalfSize( unsigned char *, int, int );
unsigned char *		RPPMToTexture( char *, int *, int * );



/**
 ** in InitGraphics():
 **/

	Texture0 = RPPMToTexture( filename, &Width, &Height );
	if( Texture0 == NULL )
	{
		fprintf( stderr, "RPPMToTexture() failed\n" );
		Quit();
	}

	if( Debug )
	{
		fprintf( stderr, "Texture '%s' read -- Width = %d, Height = %d\n",
			filename, Width, Height );
	}


	Texture1 = HalfSize( Texture0, Width/1,   Height/1   );
	Texture2 = HalfSize( Texture1, Width/2,   Height/2   );
	Texture3 = HalfSize( Texture2, Width/4,   Height/4   );
	Texture4 = HalfSize( Texture3, Width/8,   Height/8   );
	Texture5 = HalfSize( Texture4, Width/16,  Height/16  );
	Texture6 = HalfSize( Texture5, Width/32,  Height/32  );
	Texture7 = HalfSize( Texture6, Width/64,  Height/64  );
	Texture8 = HalfSize( Texture7, Width/128, Height/128 );


	glGenTextures( 1, &TexName );
	glBindTexture( GL_TEXTURE_2D, TexName );
	glTexImage2D( GL_TEXTURE_2D, 0, 3, Width/1,   Height/1,   0, GL_RGB, GL_UNSIGNED_BYTE, Texture0 );
	glTexImage2D( GL_TEXTURE_2D, 1, 3, Width/2,   Height/2,   0, GL_RGB, GL_UNSIGNED_BYTE, Texture1 );
	glTexImage2D( GL_TEXTURE_2D, 2, 3, Width/4,   Height/4,   0, GL_RGB, GL_UNSIGNED_BYTE, Texture2 );
	glTexImage2D( GL_TEXTURE_2D, 3, 3, Width/8,   Height/8,   0, GL_RGB, GL_UNSIGNED_BYTE, Texture3 );
	glTexImage2D( GL_TEXTURE_2D, 4, 3, Width/16,  Height/16,  0, GL_RGB, GL_UNSIGNED_BYTE, Texture4 );
	glTexImage2D( GL_TEXTURE_2D, 5, 3, Width/32,  Height/32,  0, GL_RGB, GL_UNSIGNED_BYTE, Texture5 );
	glTexImage2D( GL_TEXTURE_2D, 6, 3, Width/64,  Height/64,  0, GL_RGB, GL_UNSIGNED_BYTE, Texture6 );
	glTexImage2D( GL_TEXTURE_2D, 7, 3, Width/128, Height/128, 0, GL_RGB, GL_UNSIGNED_BYTE, Texture7 );
	glTexImage2D( GL_TEXTURE_2D, 8, 3, Width/256, Height/256, 0, GL_RGB, GL_UNSIGNED_BYTE, Texture8 );





/**
 ** in Display:
 **/

	glBindTexture( GL_TEXTURE_2D, TexName );
	glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, MagTexFilter );
	glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, MinTexFilter );
	glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, TexWrap );
	glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, TexWrap );





/**
 ** produce a half-sized texture map:
 **/

#define FULLIMG(a,b,c)	full[ 3*( fullw*(b) + (a) )  +  (c) ]
#define HALFIMG(a,b,c)	half[ 3*( halfw*(b) + (a) )  +  (c) ]

unsigned char *
HalfSize( unsigned char *full, int fullw, int fullh )
{
	int halfw, halfh;
	int jf, jh, kf, kh;
	int c;
	unsigned char *half;


	halfw = fullw / 2;
	halfh = fullh / 2;
	half = (unsigned char *) malloc( 3 * halfw * halfh );

	for( jh = 0, jf = 0; jh < halfw; jh++, jf += 2 )
	{
		for( kh = 0, kf = 0; kh < halfh; kh++, kf += 2 )
		{
			for( c = 0; c < 3; c++ )
			{
				HALFIMG(jh,kh,c) = ( FULLIMG(jf,kf,c) + FULLIMG(jf+1,kf,c) + FULLIMG(jf,kf+1,c) + FULLIMG(jf+1,kf+1,c)  ) / 4;
			}
		}
	}

	return half;
}