title: OpenGL vertex arrays, drawing from user input
body: <p>I am trying to take user input in the form of left and right clicks to draw a polygon to the screen.  Every left click is captured as an (x,y) coordinate and saved into an array.  After the user pressed the right click, the mouse function should finish the polygon (connect the last point to the original) and display it to the screen.  I have verified using my code in the display function with hardcoded values using the vertex array, so I think the issue is to do with how I handle the termination condition (i.e. "GLUT_RIGHT_CLICK")<br>
  Can you see an error here?  When I test the function it crashes on right click.</p>
  
  <pre><code>void mouseMove(int click, int state, int x, int y)
  {
      clearFramebuffer();
      static int i = 0;
      drawit();
      glEnableClientState(GL_VERTEX_ARRAY);
      while(click!=GLUT_RIGHT_BUTTON){
          if(click==GLUT_LEFT_BUTTON &amp;&amp; state == GLUT_DOWN){
  
              vertices[i]=x;
              vertices[i+1]=y;
              //{10, 10, 10, 50, 50, 50, 50, 10};
              //printf("Coords:  (%d,%d)\n",vertices[i],vertices[i+1]);
              i++;i++;
          }
      }
      //drawit();
      glVertexPointer(2, GL_INT, 0, vertices);
      glDrawArrays(GL_POLYGON, 0, 10);
      glDisableClientState(GL_VERTEX_ARRAY);  
      glutPostRedisplay();
  }
  </code></pre>
  
  <p>mouseMove is called in the main like so:</p>
  
  <pre><code>glutMouseFunc( mouseMove );
  </code></pre>
  
  <p>This is part of my homework so any other solution not involving vertex arrays is not allowed.</p>