   about main
  In opengl, am I right to say below code enters loop so main calls   glutReshapeFunc(reshape);  glutDisplayFunc(display);  glutIdleFunc(animate);  glutSpecialFunc(special_keys);and call these again as it is in loop?.and what is role of srand48((long int) time(NULL));?Lastly How often animate is called and what does get_time return? For example 1,2.. or 0.1,0.2...int main(int argc, char **argv){  glutInit(&argc, argv);  glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH);  glutInitWindowSize(500, 500);  glutCreateWindow("Waterfall");  glutReshapeFunc(reshape);  glutDisplayFunc(display);  glutIdleFunc(animate);  glutSpecialFunc(special_keys);  srand48((long int) time(NULL));    glutMainLoop();  return 0;}float gettime(){  static clock_t t_old = 0;  clock_t t_new, elapsed;  t_new = clock();  elapsed = t_new - t_old;  t_old = t_new;    return (float) elapsed / CLOCKS_PER_SEC;}void animate(){  int i;  float time_step = gettime();  if(current_particles<=(WATERFALL_MAX-WATERFALL)){    for(i=0; i<WATERFALL; i++) new_particle(i+current_particles);    current_particles += WATERFALL;  } glutPostRedisplay();  return;}   
  The following calls:glutReshapeFunc(reshape);glutDisplayFunc(display);glutIdleFunc(animate);glutSpecialFunc(special_keys);Register callback functions with opengl, those are functions that OpenGL will call on every tick.glutMainLoop(); is the real loop, the source code for it should be something like:while(keepRunning){   dealwithinput();   animate();   display();}The role of srand48((long int) time(NULL)); is the following:srand48 is a function call to seed the pseudo-random number generator, it takes a long.  You can seed the random number generator with whatever you want, the numbers generated are based on a seed so if you always provide the same seed the random numbers are going to be the same.To avoid that in this case the program is using the current time (time(NULL)) to feed the random number generator.Hope this makes sense;  BTW get_time will return the time that has elapsed since the last time get_time was called.i.e.Time 0 I call get_time, I get 0Time 2 I call get_time, I get 2Time 5 I call get_time, I get 3 (What has elapsed since last time I called get_time at time 2)   ;  what is callback function?what does this line mean in my example? glutDisplayFunc sets the display callback for the  current window   ;  To explain a callback function, let me use an example from windows programming(possibly where you are getting it from).Windows deals with 'events' for pretty much all of its programming.  Say the user wants to change windows, then it sends out an event to the running program that it is no longer in the foreground.  It also sends a message to the program you switch to saying that it is in the front being used.  A callback function in this case is so your program can deal with events in a specific way.  Instead of YOU calling this function, windows calls it for you and sends a message filled with information, including the event.  So this function has a list of all events it cares about(it can ignore them, but you usually send them to a default callback function that handles them).  Say the user switches from  your game to a spreadsheet so the boss thinks they are working.  Your program can deal with the sent message saying your program is out of focus by pausing it, so you don't die.There are other uses, and I'm not sure about in your example, especially without knowing what display is.  Hope that helps a little.   ;Quote:Original post by ldeejThe following calls:glutReshapeFunc(reshape);glutDisplayFunc(display);glutIdleFunc(animate);glutSpecialFunc(special_keys);Register callback functions with opengl, those are functions that OpenGL will call on every tick.GLUT, not OpenGL.   