title: Why isn't glTranslate doing anything in a double buffered GLUT window?
body: <p>I'm trying to make it so that when I press W, A, S, or D, it moves a bunch of lines around on the screen. I read in all the lines from a file and display them, and that works fine.</p>
  
  <p>So I have a keyboard function that has a switch statement that increments an X and Y variable which I use in glTranslate inside of my display function, but my lines don't move. Could anyone help me out with this?</p>
  
  <pre><code>#include &lt;GL/glut.h&gt;
  #include &lt;stdlib.h&gt;
  #include &lt;fstream&gt;
  #include &lt;iostream&gt;
  
  int height = 640, width = 640;
  
  int X = 0, Y = 0;
  
  void drawPolyLineFile(char * fileName) {
      std::fstream inStream;
      inStream.open(fileName, std::ios::in);
      if (inStream.fail()) {
          std::cerr&lt;&lt; "Error opening file";
          return;
      }
  
      glClear(GL_COLOR_BUFFER_BIT);
  
      GLint numpolys, numLines, x, y;
      inStream &gt;&gt; numpolys;
      for ( int j =0; j &lt; numpolys; j++) {
          inStream &gt;&gt; numLines;
          glBegin(GL_LINE_STRIP);
          for (int i = 0; i &lt; numLines; i++) {
              inStream &gt;&gt; x &gt;&gt; y;
              glVertex2i(x, y);
          }
          glEnd();
      }
  
      //glutSwapBuffers();
  
      inStream.close();
  }
  
  void display(void)
  {
  /* clear all pixels  */
     glClear (GL_COLOR_BUFFER_BIT);
  
     glTranslatef(X, Y, 0);
     drawPolyLineFile("dino.dat");
  
  /* don't wait!
   * start processing buffered OpenGL routines
   */
     glutSwapBuffers();
  }
  
  void init (void)
  {
  /* select clearing color        */
     glClearColor (0.0, 0.0, 0.0, 0.0);
  
  /* initialize viewing values  */
     glMatrixMode(GL_PROJECTION);
     glLoadIdentity();
     glOrtho(0.0, 640.0, 0.0, 640.0, -1.0, 1.0);
  }
  
  
  void keyboard(unsigned char key, int x, int y) {
      float speed = 5.0f;
      switch ( key ) {
          case 'a':
              X -= speed;
              std::cerr&lt;&lt; X &lt;&lt; std::endl;
              break;
          case 'd':
              X += speed;
              std::cerr&lt;&lt; X &lt;&lt; std::endl;
              break;
          case 's':
              Y -= speed;
              std::cerr&lt;&lt; Y &lt;&lt; std::endl;
              break;
          case 'w':
              Y += speed;
              std::cerr&lt;&lt; Y &lt;&lt; std::endl;
              break;
          default:
              break;
      }
  
  }
  
  
  /*
   * Declare initial window size, position, and display mode
   * (single buffer and RGBA).  Open window with "hello"
   * in its title bar.  Call initialization routines.
   * Register callback function to display graphics.
   * Enter main loop and process events.
   */
  int main(int argc, char** argv)
  {
     glutInit(&amp;argc, argv);
     glutInitDisplayMode (GLUT_DOUBLE | GLUT_RGB);
     glutInitWindowSize (640, 640);
     glutInitWindowPosition (100, 100);
     glutCreateWindow ("hello");
     init ();
     glutKeyboardFunc(keyboard);
     glutDisplayFunc(display);
     glutMainLoop();
     return 0;   /* ANSI C requires main to return int. */
  }
  </code></pre>