GLuint texture[8]; 

double frame;

GLuint LoadTexture( const char * filename, int width, int height )
{
	GLuint texture;
	unsigned char * data;
	FILE * file;

	//The following code will read in our RAW file
	file = fopen( filename, "rb" );
	if ( file == NULL ) return 0;
	data = (unsigned char *)malloc( width * height * 3 );
	fread( data, width * height * 3, 1, file );
	fclose( file );

	glGenTextures( 1, &texture ); //generate the texture with the loaded data
	glBindTexture( GL_TEXTURE_2D, texture ); //bind the texture to it's array
	glTexEnvf( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE ); //set texture environment parameters

	//here we are setting what textures to use and when. The MIN filter is which quality to show
	//when the texture is near the view, and the MAG filter is which quality to show when the texture
	//is far from the view.

	//The qualities are (in order from worst to best)
	//GL_NEAREST
	//GL_LINEAR
	//GL_LINEAR_MIPMAP_NEAREST
	//GL_LINEAR_MIPMAP_LINEAR

	//And if you go and use extensions, you can use Anisotropic filtering textures which are of an
	//even better quality, but this will do for now.
	glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR );
	glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR_MIPMAP_LINEAR );

	//Here we are setting the parameter to repeat the texture instead of clamping the texture
	//to the edge of our shape. 
	glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT );
	glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT );

	//Generate the texture with mipmaps
	gluBuild2DMipmaps( GL_TEXTURE_2D, 3, width, height, GL_RGB, GL_UNSIGNED_BYTE, data ); 
	free( data ); //free the texture
	return texture; //return whether it was successfull
}

void FreeTexture( GLuint texture )
{
  glDeleteTextures( 1, &texture ); 
}




void drawl(int count1)
{        
        glLoadIdentity();
        //glTranslatef ( coord1, coord2, coord3 );
                //   over  up  distance-view
 // frame = 1;
//glEnable( GL_TEXTURE_2D );
      glTranslatef(soldier[count1].X , soldier[count1].Y , -10.0f );




	//glTranslatef(soldier[count1].Xf,soldier[count1].Yf,-30.0f);
        //glRotatef( 100.0, 100.0, 100.0, 500.0 );
/*
	if(soldier[count1].type==0) {
        	glColor3f( 1.0, 1.0, 0.0 );
	} else if(soldier[count1].type==1) {
		glColor3f( 1.0, 0.0, 0.0 );
	}else{
		glColor3f( 0.0, 0.0, 1.0 );
	}
*/


//background color
//glClearColor(0.7f, 0.9f, 1.0f, 1.0f);

	if(soldier[count1].team == 0) {
		glColor3f( 1.0, 1.0, 0.0 );
	}else if(soldier[count1].team == 1){
		glColor3f( 1.0, 0.0, 0.0 );
	}
	//glVertexfv(10.0);
//glRotatef(rtri,0.0f,1.0f,0.0f);
//glBegin(GL_TRIANGLES);


//glEnable( GL_TEXTURE_2D );

//glEnable (GL_TEXTURE_RECTANGLE_ARB);

//texture[0] = LoadTexture( "soldier.bmp", 32, 32 );
//LoadTexture( "soldier.png", 1, 1 );

//	glBindTexture( GL_TEXTURE_2D, texture[0] );
//	glScalef(1,1,1);


/*GL_ARB_texture_rectangle
	glBegin (GL_QUADS);
	glTexCoord2d(0,0); 
	glVertex3f(-1,1,0);
    glTexCoord2d(1,0); 
	glVertex3f(1,1,0);
    glTexCoord2d(1,1); 
	glVertex3f(1,-1,0);
    glTexCoord2d(0,1); 
	glVertex3f(-1,-1,0);
	glEnd();

*/


//glColor3f( 1.0, 1.0, 0.0 );


/*
glBegin(GL_QUADS);
//		glColor3f(1.0f,1.0f,0.0f);			
		glTexCoord2d(0,0);
		glVertex3f( -1, 1, 1);			


//		glColor3f(0.0f,1.0f,0.0f);
		glTexCoord2d(1,0);			
		glVertex3f(1, 1, 1);			

//		glColor3f(0.0f,0.0f,1.0f);
		glTexCoord2d(1,1);		
		glVertex3f( 1, -1, 1);		


//		glColor3f(1.0f,0.0f,0.0f);
		glTexCoord2d(0,1);		
		glVertex3f( -1, -1, 1);




		glColor3f(0.0f,0.0f,1.0f);			// Blue
		glVertex3f( 1.0f,-1.0f, 1.0f);			// Left Of Triangle (Right)

		glColor3f(0.0f,1.0f,0.0f);			// Green
		glVertex3f( 1.0f,-1.0f, -1.0f);			// Right Of Triangle (Right)


glEnd();
*/



//glColor3f(0.0f,1.0f,0.0f);
/*
glBegin(GL_QUADS);
            glTexCoord2f(0.0f, 0.0f); glVertex2f(0.0f, 0.0f);
            glTexCoord2f(0.0f, 1.0f); glVertex2f(0.0f, 1.0f);
            glTexCoord2f(1.0f, 1.0f); glVertex2f(1.0f, 1.0f);
            glTexCoord2f(1.0f, 0.0f); glVertex2f(1.0f, 0.0f);
glEnd();
*/



//glVertex2f(1.50f, 1.50f); // origin of the line
//glVertex2f(-1.50f, -1.50f); // ending point of the line


//glTranslatef(soldier[count1].X , soldier[count1].Y + 5 , -30.0f );
//glutSolidSphere( .1, 5, 5 );


glBegin(GL_LINES);

//left leg
glVertex3f(-.25, -.25, .0001); // origin of the line
glVertex3f(-.1, -.1, .0001); // ending point of the line

//right leg
glVertex3f(.25, -.25, .0001); // origin of the line
glVertex3f(.1, -.1, .0001); // ending point of the line

//body
glVertex3f(0, -.1, .0001); // origin of the line
glVertex3f(0, .25, .0001); // ending point of the line

//left arm
glVertex3f(0, .25, .0001); // origin of the line
glVertex3f(-.25, .1, .0001); // ending point of the line

//right arm
glVertex3f(0, .25, .0001); // origin of the line
glVertex3f(.25, .1, .0001); // ending point of the line

//head
//glTranslatef(soldier[count1].X , soldier[count1].Y + 5 , -30.0f );
//glutSolidSphere( .1, 5, 5 );



//glVertex2f(1.50f, -1.50f); // origin of the line
//glVertex2f(-1.50f, 1.50f); // ending point of the line



glEnd( );


glLoadIdentity();
//head
glTranslatef(soldier[count1].X, soldier[count1].Y + .5, -10.0f );
glutSolidSphere( .1, 15, 15 );






//	glTexCoord2d(0,0);
//        glutSolidSphere( .5, 15, 15 );
}

