title: Translate a triangle using animation(one by one after some interval) with opengl and c++
body: <p>I want to make a space invader game in opengl. So I thought of creating the enemies using triangles. Before making the game, I want to try out my hand in animation. I have triangle. i want to translate it left upto some point with animation(i.e, triangle is translated after some interval of time. It should look as if it is moving).After reaching some point in the left, I want to translate it back to the same position or some distances right. The process should go on till the screen is open. I used sleep function. But it is not working. No animation is shown. Only the translated triangle is drawn at different translated position. Help me.</p>
  
  <p>Here is my code-</p>
  
  <pre><code>#include "windows.h"
  #include &lt;gl/glut.h&gt;
  #include&lt;stdio.h&gt;
  
  void init( void )
  {
      printf( "OpenGL version: %s\n", (char*)glGetString(GL_VERSION));
      printf( "OpenGL renderer: %s\n", (char*)glGetString(GL_RENDERER));
  
      //Configure basic OpenGL settings
  
      glClearColor(1.0, 1.0, 0.0, 0.0);
      glMatrixMode(GL_PROJECTION); 
      gluOrtho2D(0.0,640.0,0.0,480.0);
      glColor3f(1.0,0.0,0.0);
  glPointSize(3);
  }
  
  void house(int x, int y,int z)
  {
    glPushMatrix();
    glTranslatef(x, y,z);
    glBegin (GL_LINES);    
       glVertex2i (0,30);
       glVertex2i (15,60);
        glVertex2i (15,60);
         glVertex2i (30,30);
          glVertex2i (30,30);
          glVertex2i (0,30);
          glEnd();
          //Sleep(200);
    glPopMatrix();
      //glutSwapBuffers();
  }
  
  
  // Main drawing routine. Called repeatedly by GLUT's main loop
  void display( void )
  {
      //Clear the screen and set our initial view matrix
  
      glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
  
  
      int i;
      for(i = 10; i &lt; 350; i = i + 50)
    {
      house(i,20,0);
      Sleep(200);
    }
  
      glMatrixMode(GL_MODELVIEW);
      glLoadIdentity();
   glFlush();
  
  }
  
  // Entry point - GLUT setup and initialization
  int main( int argc, char** argv )
  {
  
     glutInit( &amp;argc, argv );
     glutInitDisplayMode (GLUT_DEPTH | GLUT_SINGLE| GLUT_RGB);
     glutInitWindowSize (800, 600);
     glutInitWindowPosition (100, 100);
     glutCreateWindow( "OpenGL Test" );
  
     glutDisplayFunc( display );
  
  
     init();
  
     glutMainLoop();
  
     return 0;
  }
  </code></pre>