#include<GL/glut.h>
#include<math.h>
static float Xvalue = 0.0, Yvalue = 0.0; 
static float Angle = 0.0; 
static int isAnimate = 0; 
static int animationPeriod=50;
void display(void)
{
   glClear(GL_COLOR_BUFFER_BIT);

   glLoadIdentity();

glTranslatef(Xvalue, Yvalue, -15.0);

 glRotatef(Angle, 0.0, 1.0, 1.0);

 glColor3f(0.0, 0.0, 0.0);

glutWireCube(5.0);

   glutSwapBuffers();
}
void init(void) 
{
   glClearColor(1.0, 1.0, 1.0, 0.0);
}
void increaseAngle(void)
{
   Angle += 0.5;
   if (Angle > 360.0) Angle -= 360.0;
   glutPostRedisplay();
}
void animate(int value)
{
   if (isAnimate) 
   {
      increaseAngle();

      glutPostRedisplay();     
      glutTimerFunc(animationPeriod, animate, 1);
   }
}

void keyInput(unsigned char key, int x, int y)
{
   switch(key) 
   {
      case 27:
         exit(0);
         break;
	  case ' ': 
         if (isAnimate) isAnimate = 0;
		 else 
		 {
	        isAnimate = 1; 
			animate(1);
		 }
		 break;
      default:
         break;
   }
}

   void resize(int w, int h)
{
   glViewport(0, 0, w, h); 
   glMatrixMode(GL_PROJECTION);
   glLoadIdentity();
   glFrustum(-5.0, 5.0, -5.0, 5.0, 5.0, 100.0);

   glMatrixMode(GL_MODELVIEW);
}
int main(int argc, char **argv) 
{
   glutInit(&argc, argv);

  

   glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGBA); 
   glutInitWindowSize(500, 500);
   glutInitWindowPosition(100, 100); 
   glutCreateWindow("cube2.cpp");
   glutDisplayFunc(display); 
   glutReshapeFunc(resize);  
   glutKeyboardFunc(keyInput);

  // glutSpecialFunc(specialKeyInput);
   
  init(); 

   glutMainLoop(); 
}
