Moving a circle across

hi all.
I want to draw a circle on the push of a particular key and make it move across the screen. Heres the snippet:
This is the function to catch the key press:


void keyPressed(unsigned char key, int x, int y) 
{
    /* avoid thrashing this procedure */
    usleep(100);

    /* If escape is pressed, kill everything. */
    if (key == ESCAPE) 
    { 
	/* shut down our window */
	glutDestroyWindow(window); 
	
	/* exit the program...normal termination. */
	exit(0);                   
    }

    if(key == 102 || key == 70)
       foo();
}

And this is the function to draw the circle which is not registered as a display function:


void foo(){
				glTranslatef(3.0f,0.0f,0.0f);		        // Move Right 3 Units
	
	  			glBegin(GL_LINES);
					glColor3f(1.0f,0.0f,0.0f);
					int j;
					float x = 0.05f * cos(359 * PI/180.0f);
					float y = 0.05f * sin(359 * PI/180.0f);
					for(j = 0; j < 360; j++)
					{
						glVertex2f(x,y);
						x = 0.05f * cos(j * PI/180.0f);
						y = 0.05f * sin(j * PI/180.0f);
						glVertex2f(x,y);
					}
				glEnd();
				glutSwapBuffers();
				glutPostRedisplay();
			
}

Now since the above function is not registered as a display function, it is not redrawn and i want it to be redrawn. The circle is displayed and disappears. Recursion is bit messy(in processing terms) and i am not looking at it now.

Any suggestions?
Thank you.

I cant understand what you exactly want to do.

How do you expect the scene to be redrawn if it is not registered as a display callback?

If you want to see the circle drawn in steps I suggest the following:

  • declare a static counter variable ( say i)
  • iterate over i after every callback to foo();
  • use a timer function glutTimerfunc(*timer_func,value,1); value = 30ms or whatever.
  • and register your display func. That is necessary!
  • Check if you have enabled Double buffering, otherwise when you swap buffers the result will be a blank screen as you mentioned.

hope this helped.