rishi
rishi

Reputation: 749

speed mismatch in linux and windows

void myDisplay(void)  //glutDIsplayFunc(mydisplay)
{
  while(1)
  {
    glClear(GL_COLOR_BUFFER_BIT);
    x=rand()%680;
    y=rand()%680;
    sx=(x-p)/100;
    sy=(y-q)/100;
    glColor3f(0.7+sx,0.1-sy,0.6);

    for(g=0;g<120;g++)
    {
      p+=sx;
      q+=sy;
      glBegin(GL_POINTS);
      glVertex2i(p,q); 
      glEnd();
      glutSwapBuffers();
    }
  }
}

This code just chooses one arbitrary point on screen and do smooth translation. I compiled this same code in visual C++ and on linux and I noticed that the translation (from one point to another) happens fast on windows while on linux it drags slow.

why this is so?

Upvotes: 0

Views: 90

Answers (1)

derhass
derhass

Reputation: 45332

Your are using a movement vector which is totally independent of the fps. This means that it will run with a different speed on a different machine.From your description I guess that on your Linux machine, sync to vblank is enabled, limiting your framerate to the refresh rate of the display (typically 60Hz), while on the windows machine, it is disabled, running with a much higher frequency.

You should use a timer to control animations, and define your animation speeds in sapce-units per time-unit.

Furthermore, you should follow Andon M. Coleman's advice: The GLUT display callback is mean to draw a single frame. If you want an animation over many frames, use some variables to store your current state (for example, the current position and direction vector) and update them for each step. The way you currently implemented it, GLUT's event handling will by blocked for the whole duration of the animation. On windows, this might even trigger "the application is not responding" warning, when your animation takes too long.

Upvotes: 2

Related Questions