title: glutKeyboardFunc calling function not working
body: <p>I am trying to call a function, only when "spacebar" is pressed. Its key code is 32.</p>
  
  <pre><code>#include &lt;GL/glut.h&gt;
  #include &lt;GL/glu.h&gt;
  #include &lt;GL/gl.h&gt;
  #include &lt;cmath&gt; 
  #include &lt;iostream&gt;
  #include &lt;string.h&gt;
  
  using namespace std;
  
  GLuint window, View1;
  void Display_Mid_Ellipse()
  {
  
      double xc=0.0, yc=0.0,  rx=140.0, ry=200.0;
      double rxSq = rx * rx;
      double rySq = ry * ry;
      double x = 0, y = ry, p;
      double px = 0, py = 2 * rxSq * y;
      glClear(GL_COLOR_BUFFER_BIT);
      glColor3f( 1 ,0, 0);
       glBegin(GL_POINTS);
  
  
       glVertex2d(xc+x,yc-y);
       glVertex2d(xc-x,yc-y);
       glVertex2d(xc-x,yc+y);
      glEnd();
  
      p = rySq - (rxSq * ry) + (0.25 * rxSq);
      while (px &lt; py)
      {
                      x++;
                      px = px + 2 * rySq;
                      if (p &lt; 0)
                      p = p + rySq + px;
                      else
                      {
                      y--;
                      py = py - 2 * rxSq;
                      p = p + rySq + px - py;
                      }
                       glBegin(GL_POINTS);
  
                       glVertex2d(xc+x,yc+y);
                       glVertex2d(xc+x,yc-y);
                       glVertex2d(xc-x,yc-y);
                       glVertex2d(xc-x,yc+y);
                      glEnd();
  
      }
  
      p = rySq*(x+0.5)*(x+0.5) + rxSq*(y-1)*(y-1) - rxSq*rySq;
      while (y &gt; 0)
      {
              y--;
              py = py - 2 * rxSq;
              if (p &gt; 0)
              p = p + rxSq - py;
              else
              {
              x++;
              px = px + 2 * rySq;
              p = p + rxSq - py + px;
              }
             glBegin(GL_POINTS);
  
       glVertex2d(xc+x,yc+y);
       glVertex2d(xc+x,yc-y);
       glVertex2d(xc-x,yc-y);
       glVertex2d(xc-x,yc+y);
      glEnd();
      glFlush();
  
      }
  }    //end_MIDPOINT_ELLIPSE
  
  void init () {
      glClear(GL_COLOR_BUFFER_BIT);
  glClearColor(0.3,0.3,0.3,0.7);
      gluOrtho2D(-500.0,500.0,-500.0,500.0);
  }
  void View1Display()
  {
  glutSetWindow(View1);
  gluOrtho2D(-500.0,500.0,-500.0,500.0);  
  Display_Mid_Ellipse();
  
  
     }
      void Display()
   { 
      glutSetWindow(window);
      glClear(GL_COLOR_BUFFER_BIT);
      //View1Display(); 
   }
  
  void keyFunc(unsigned char ch, int x, int y){
  
  if(ch==32){
  View1Display();
  }
  }
  
  int main (int argc, char *argv[]) {      
  
  glutInit(&amp;argc, argv);
  glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB);
  
  glutInitWindowSize(750, 750);
  glutInitWindowPosition(0, 0);
  
  window=glutCreateWindow("Circle and ellipse");
  init();
  
  View1 = glutCreateSubWindow(window,20,40, 340,340);
  glutDisplayFunc(Display);
  glutKeyboardFunc(keyFunc);
  glutMainLoop();
  
      return 0;
  }
  </code></pre>
  
  <p>When i call the same View1Display from the Display() function, it works well.
  I'm confused. I have tried the alternatives I could but could not find a solution. Please help.
  Thanks</p>