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.