struct CUBELETTER{
	float x,y,z;
	int letter;
	int rotox,rotoy,rotoz;
	bool done;
};

void glPrintString(char string[],float x,float y,float size,float fade)
{
  char letter;
  int i,j;
  float cx=1,cy=1,cwx,cwy;
  float fWidth = 16;
  float fHeight = 37;
  cwx         = (1.0f / 256.0F) * fWidth;
  cwy         = (1.0f / 256.0f) * fHeight;	
 glBlendFunc(GL_ONE, GL_ONE);
 glEnable(GL_BLEND);

 glPushMatrix();
 glLoadIdentity();
 glTranslatef(-.55,.356,-1);
 for(i=0;i<strlen(string);i++){
 
 letter=string[i];
 
 if(letter=='-'){cx=10;cy=2;}
 //if(letter=='!' {cx=12; cy=2;}
 //if(letter>'1' {cx=letter-'l'; cy=2;}
 if(letter>=49){cx=letter-49; cy=2;}
 if(letter==48){cx=9; cy=2;}
 if(letter>64){cx=letter-65; cy=0;}
 if(letter>=78){cx=letter-78; cy=1;}
 
 if(letter!=32){
 glBindTexture(GL_TEXTURE_2D, Font);	
	glColor4f(fade,fade,fade,fade);	
	glBegin(GL_QUADS);	
		glTexCoord2f(cwx*cx   , -(cwy*cy+cwy)); glVertex2f(x+(i*size) , y);
		glTexCoord2f(cwx*cx+cwx, -(cwy*cy+cwy)); glVertex2f(x+(i*size)+size,y);
		glTexCoord2f(cwx*cx+cwx, -(cwy*cy)); glVertex2f(x+(i*size)+size,y+size);
		glTexCoord2f(cwx*cx   , -(cwy*cy)); glVertex2f(x+(i*size),y+size);
	glEnd(); 
 }
 }
	glPopMatrix();


	

}
struct PARTICLE{
float x,y,z,xok,yok,zok;
float red,green,blue;
};

struct EXPLOSION{
	PARTICLE particles[MAX_PARTICLES];
	int duration;
};

void SetupParticles(PARTICLE particles[MAX_PARTICLES],float x,float y,float z)
{
	int i=0;
	float angle, mag;
	for (i=0;i<MAX_PARTICLES;i++){
		particles[i].x=x;
		particles[i].y=y;
		particles[i].z=z;		
		particles[i].red=(((float)(rand()%90))/100) +0.1f;
		particles[i].green=(((float)(rand()%90))/100) +.1;
		particles[i].blue=(((float)(rand()%90))/100) +.1;		
		angle=(float)(rand()%6283)/1000;
		mag=0;
		while(mag<0.001)
			mag=(float)(rand()%1000)/1000;		
		particles[i].xok=(float)cos(angle)*mag;	
		particles[i].yok=(float)sin(angle)*mag;
		mag=(float)((rand()%1000)-500)/1000;
		particles[i].zok=mag;;
	}
}
float roto=0,roto2=0;
void MoveParticles(PARTICLE particles[MAX_PARTICLES],float angle,float xrot,float yrot,float zrot,float zpos,float light)
{
	int i=0;
	glTranslatef(0,0,zpos);
	glRotatef(angle,xrot,yrot,zrot);

for(i=0;i<MAX_PARTICLES;i++){		
	particles[i].x+= particles[i].xok;
	particles[i].y+= particles[i].yok;
	particles[i].z+= particles[i].zok;	
	
	glTranslatef(particles[i].x,particles[i].y,particles[i].z);
	glColor4f(particles[i].red,particles[i].green,particles[i].blue,light);	
glRotatef(-angle,xrot,yrot,zrot);
	glBegin(GL_QUADS);	
		glTexCoord2f(0.0f, 0.0f); glVertex3f(-SIZEOFPARTICLE, -SIZEOFPARTICLE,  particles[i].z);
		glTexCoord2f(1.0f, 0.0f); glVertex3f(+SIZEOFPARTICLE ,-SIZEOFPARTICLE,  particles[i].z);
		glTexCoord2f(1.0f, 1.0f); glVertex3f(+SIZEOFPARTICLE ,+SIZEOFPARTICLE,  particles[i].z);
		glTexCoord2f(0.0f, 1.0f); glVertex3f(-SIZEOFPARTICLE ,+SIZEOFPARTICLE,  particles[i].z);
	glEnd();
glRotatef(angle,xrot,yrot,zrot);	
	glTranslatef(-particles[i].x,-particles[i].y,-particles[i].z);
}


}
void draw_letter(CUBELETTER *inputas){
	glLoadIdentity();
	//glTranslatef(0,0,-10);
	glTranslatef(inputas->x,inputas->y,inputas->z);	
	if (inputas->letter==0){
		if (inputas->rotox>0)inputas->rotox-=2;
		if (inputas->rotoy>0)inputas->rotoy-=2;
		if (inputas->rotoz>0)inputas->rotoz-=2;
		if (inputas->rotox<0)inputas->rotox+=2;
		if (inputas->rotoy<0)inputas->rotoy+=2;
		if (inputas->rotoz<0)inputas->rotoz+=2;	
	}
	if (inputas->letter==1){
		if (inputas->rotox>180)inputas->rotox-=2;
		if (inputas->rotoy>0)inputas->rotoy-=2;
		if (inputas->rotoz>180)inputas->rotoz-=2;
		if (inputas->rotox<180)inputas->rotox+=2;
		if (inputas->rotoy<0)inputas->rotoy+=2;
		if (inputas->rotoz<180)inputas->rotoz+=2;
	}

	if (inputas->letter==2){
		if (inputas->rotox>270)inputas->rotox-=2;
		if (inputas->rotoy>0)inputas->rotoy-=2;
		if (inputas->rotoz>180)inputas->rotoz-=2;
		if (inputas->rotox<270)inputas->rotox+=2;
		if (inputas->rotoy<0)inputas->rotoy+=2;
		if (inputas->rotoz<180)inputas->rotoz+=2;
	}
	if (inputas->letter==3){
		if (inputas->rotox>90)inputas->rotox-=2;
		if (inputas->rotoy>0)inputas->rotoy-=2;
		if (inputas->rotoz>180)inputas->rotoz-=2;
		if (inputas->rotox<90)inputas->rotox+=2;
		if (inputas->rotoy<0)inputas->rotoy+=2;
		if (inputas->rotoz<180)inputas->rotoz+=2;
	}
	if (inputas->letter==4){
		if (inputas->rotox>0)inputas->rotox-=2;
		if (inputas->rotoy>90)inputas->rotoy-=2;
		if (inputas->rotoz>0)inputas->rotoz-=2;
		if (inputas->rotox<0)inputas->rotox+=2;
		if (inputas->rotoy<90)inputas->rotoy+=2;
		if (inputas->rotoz<0)inputas->rotoz+=2;
	}
	if (inputas->letter==5){
		if (inputas->rotox>0)inputas->rotox-=2;
		if (inputas->rotoy>270)inputas->rotoy-=2;
		if (inputas->rotoz>0)inputas->rotoz-=2;
		if (inputas->rotox<0)inputas->rotox+=2;
		if (inputas->rotoy<270)inputas->rotoy+=2;
		if (inputas->rotoz<0)inputas->rotoz+=2;
	}
	if (inputas->letter==6){
		if (inputas->rotox>90)inputas->rotox-=2;
		if (inputas->rotoy>90)inputas->rotoy-=2;
		if (inputas->rotoz>90)inputas->rotoz-=2;
		if (inputas->rotox<90)inputas->rotox+=2;
		if (inputas->rotoy<90)inputas->rotoy+=2;
		if (inputas->rotoz<90)inputas->rotoz+=2;
	}

	glRotatef(inputas->rotox,1,0,0);
	glRotatef(inputas->rotoy,0,1,0);
	glRotatef(inputas->rotoz,0,0,1);
	
	//glRotatef(-12,1,0,0);
	//TextureHandler.UseTexture(Texture[1],TRUE,false);
	//glColor4f(.5,.5,1,.4);	
	//glColor4f(1,1,1,1);	
//ok nu ska det in en kub.
	TextureHandler.UseTexture(TextCube[0],FALSE,FALSE);	
	//glEnable(GL_DEPTH_TEST);	
	glColor4f(1,1,1,1);	
	glBegin(GL_QUADS);
	// Front Face	
		glTexCoord2f(0.0f, 0.0f); glVertex3f(-1.0f, -1.0f,  1.0f);	// Bottom Left Of The Texture and Quad
		glTexCoord2f(1.0f, 0.0f); glVertex3f( 1.0f, -1.0f,  1.0f);	// Bottom Right Of The Texture and Quad
		glTexCoord2f(1.0f, 1.0f); glVertex3f( 1.0f,  1.0f,  1.0f);	// Top Right Of The Texture and Quad
		glTexCoord2f(0.0f, 1.0f); glVertex3f(-1.0f,  1.0f,  1.0f);	// Top Left Of The Texture and Quad
	glEnd();
	TextureHandler.UseTexture(TextCube[1],FALSE,FALSE);	
	//glEnable(GL_DEPTH_TEST);	
	glColor4f(1,1,1,1);	
	glBegin(GL_QUADS);	
	// Back Face
		glTexCoord2f(1.0f, 0.0f); glVertex3f(-1.0f, -1.0f, -1.0f);	// Bottom Right Of The Texture and Quad
		glTexCoord2f(1.0f, 1.0f); glVertex3f(-1.0f,  1.0f, -1.0f);	// Top Right Of The Texture and Quad
		glTexCoord2f(0.0f, 1.0f); glVertex3f( 1.0f,  1.0f, -1.0f);	// Top Left Of The Texture and Quad
		glTexCoord2f(0.0f, 0.0f); glVertex3f( 1.0f, -1.0f, -1.0f);	// Bottom Left Of The Texture and Quad
	glEnd();
	TextureHandler.UseTexture(TextCube[2],FALSE,FALSE);	
	glColor4f(1,1,1,1);	
	glBegin(GL_QUADS);	
		// Top Face
		glTexCoord2f(0.0f, 1.0f); glVertex3f(-1.0f,  1.0f, -1.0f);	// Top Left Of The Texture and Quad
		glTexCoord2f(0.0f, 0.0f); glVertex3f(-1.0f,  1.0f,  1.0f);	// Bottom Left Of The Texture and Quad
		glTexCoord2f(1.0f, 0.0f); glVertex3f( 1.0f,  1.0f,  1.0f);	// Bottom Right Of The Texture and Quad
		glTexCoord2f(1.0f, 1.0f); glVertex3f( 1.0f,  1.0f, -1.0f);	// Top Right Of The Texture and Quad
	glEnd();
	TextureHandler.UseTexture(TextCube[3],FALSE,FALSE);	
	glColor4f(1,1,1,1);	
	glBegin(GL_QUADS);	
		// Bottom Face
		glTexCoord2f(1.0f, 1.0f); glVertex3f(-1.0f, -1.0f, -1.0f);	// Top Right Of The Texture and Quad
		glTexCoord2f(0.0f, 1.0f); glVertex3f( 1.0f, -1.0f, -1.0f);	// Top Left Of The Texture and Quad
		glTexCoord2f(0.0f, 0.0f); glVertex3f( 1.0f, -1.0f,  1.0f);	// Bottom Left Of The Texture and Quad
		glTexCoord2f(1.0f, 0.0f); glVertex3f(-1.0f, -1.0f,  1.0f);	// Bottom Right Of The Texture and Quad
	glEnd();
	TextureHandler.UseTexture(TextCube[4],FALSE,FALSE);	
	glColor4f(1,1,1,1);	
	glBegin(GL_QUADS);	
		// Right face
		glTexCoord2f(1.0f, 0.0f); glVertex3f( 1.0f, -1.0f, -1.0f);	// Bottom Right Of The Texture and Quad
		glTexCoord2f(1.0f, 1.0f); glVertex3f( 1.0f,  1.0f, -1.0f);	// Top Right Of The Texture and Quad
		glTexCoord2f(0.0f, 1.0f); glVertex3f( 1.0f,  1.0f,  1.0f);	// Top Left Of The Texture and Quad
		glTexCoord2f(0.0f, 0.0f); glVertex3f( 1.0f, -1.0f,  1.0f);	// Bottom Left Of The Texture and Quad
	glEnd();
	TextureHandler.UseTexture(TextCube[5],FALSE,FALSE);	
	glColor4f(1,1,1,1);	
	glBegin(GL_QUADS);	
		// Left Face
		glTexCoord2f(0.0f, 0.0f); glVertex3f(-1.0f, -1.0f, -1.0f);	// Bottom Left Of The Texture and Quad
		glTexCoord2f(1.0f, 0.0f); glVertex3f(-1.0f, -1.0f,  1.0f);	// Bottom Right Of The Texture and Quad
		glTexCoord2f(1.0f, 1.0f); glVertex3f(-1.0f,  1.0f,  1.0f);	// Top Right Of The Texture and Quad
		glTexCoord2f(0.0f, 1.0f); glVertex3f(-1.0f,  1.0f, -1.0f);	// Top Left Of The Texture and Quad
	glEnd();
}
