Pause the glutMainLoop

I would like to know how can I render my animation step by step, like calling a function (for example takeStepAnimation()), unlike from in a infite loop (glutMainLoop) that I can not control the progress of the animation, if there is a way to pause the loop (glutMainLoop) and play, someone know how to to this?

I don’t think pausing glutMainLoop is how you want to implement this. You want your application to continue to repaint (in case of window coverage changes) regardless of whether your animation state is running or stopped.

Simplest way is to have an animation counter in your program that increments when your animation state is running and doesn’t increment when your animation state is paused. Then in your display() function, just redraw based on the current animation counter, and then if your animation state is “running”, bump the counter. For best results, bump the counter based on actual elapsed time, not just a constant amount each time the display function is called.

My application is composed by to programs conected by socket the first program send the message 1 to the second program to change a position of one object, after that the first program send the message 2 to the second to simulate the physical, after that I would like to the first program to send the message 3 to the second program do render the scene and objects. The glutMainLoop is there in the second program, but the renderCallBack is in the glutMainLoop that is in infinite loop, not the way i would like to do, advance render step by step.

I need a asynchronous callback for the glutDisplayFunc, unlike the way called by the glutMainLoop, that I do not have control of the sequence of events. I need a pause and play function.

No, what you need to do is decouple animation update from being told to render. If you’re told to render, you check to see if you should update animation. If you should, then update it then render. If not, then don’t update it and just render everything in its current position.

I do something similar to what you are trying to do. How about this? In your graphics program you have a routine that’s reading the data coming in through the socket. This routine should be set as the Idlefunction (glutidlefunc). Your graphics program must stay in this routine until all 3 blocks of data are passed through the socket. GL graphics are updated only when you exit the idlefunction.

I have the exact problem like Diego, a socket, sending receiving and update the glut window continuously
I have written these but it dosent work! :sorrow:

int main(int argc, char **argv)
{
	initSocket();
	
  printf("
  Defining Step Time Parameters and Initial Conditions for solving Dynamic equations
");
	 
  xi=0;
  xf=0.1;
  printf("
    end value x         : %f ",xf); 
  i=0;  yi[i]=0; 
  i++;yi[i]=-1.570796;
  i++;yi[i]=-1.570796;
  i++;yi[i]=0;
  i++;yi[i]=0;
  i++;yi[i]=0;
  ndata=2; fi=1;
		
  double counter=0.1;


  Eqdifp(v1,v2,v3,v4,v5,v6,xi,xf,yi,ndata,p,fi);

  void OnIdle(void){  
  for(int i=0;i<50;i++)
	//while(1)
  {

	  getData();

	  printf("
");
	  for(int i=0;i<6; i++)
	  {
		  		 
		  printf("%d = %.3f
", i,drecvbuf[i]);
	  }
	  printf("
");
	
   yi[0]=v1[ndata];
   yi[1]=v2[ndata];
   yi[2]=v3[ndata];
   yi[3]=v4[ndata];
   yi[4]=v5[ndata];
   yi[5]=v6[ndata];
	printf("my nadata %f
",v1[ndata]);
	counter=counter+0.1;
 
	Eqdifp(v1,v2,v3,v4,v5,v6,xi,xf,yi,ndata,p,fi);
    glutPostRedisplay();
 }
  }
/////////////////////////////////////////////////////
 	glutInit(&argc, argv);
	glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGBA | GLUT_DEPTH);
	glutInitWindowSize(900,500);
	int u=glutCreateWindow("3DOF robot");
	myinit();
	createMenu();
	glutDisplayFunc(Display);
	glutReshapeFunc(reshape);
	glutKeyboardFunc(KeyDown);
	glutIdleFunc (OnIdle);
    glutMainLoop(); 
	
	System::Timers::Timer^ aTimer = gcnew System::Timers::Timer( 100 );

      // Hook up the Elapsed event for the timer.
    aTimer->Elapsed += gcnew System::Timers::ElapsedEventHandler( OnTimedEvent );

      // Set the Interval to 2 seconds (2000 milliseconds).
    aTimer->Enabled = true;
	return 0;
	
}

heeeeeeeeeeeeeeelp!