title: Limit Speed Of Gameplay On Different Computers
body: <p>I'm creating a 2D game using OpenGL and C++.</p>
  
  <p>I want it so that the game runs at the same speed on different computers, At the moment my game runs faster on my desktop than my laptop (i.e. my player moves faster on my desktop)</p>
  
  <p>I was told about QueryPerformanceCounter() but I don't know how to use this.</p>
  
  <p>how do I use that or is there a better/easier way?</p>
  
  <p>My Display function</p>
  
  <pre><code>void display()                                  
  {
  static long timestamp = clock();
  // First frame will have zero delta, but this is just an example.
  float delta = (float)(clock() - timestamp) / CLOCKS_PER_SEC;
  
  glClear(GL_COLOR_BUFFER_BIT);
  
  glLoadIdentity();
  
  createBackground();
  
  int curSpeed = (player.getVelocity()/player.getMaxSpeed())*100;
  
  glColor3f(1.0,0.0,0.0);
  glRasterPos2i(-screenWidth+20,screenHeight-50);
  glPrint("Speed: %i",curSpeed);
  
  glRasterPos2i(screenWidth-200,screenHeight-50);
  glPrint("Lives: %i",lives);
  
  glRasterPos2i(screenWidth-800,screenHeight-50);
  glPrint("Heading: %f",player.getHeading());
  
  for(int i = 0;i&lt;90;i++){
      if (numBullets[i].fireStatus == true){
          numBullets[i].updatePosition(player);
          if (numBullets[i].getXPos() &gt; screenWidth || numBullets[i].getXPos() &lt; -screenWidth || numBullets[i].getYPos() &gt; screenHeight || numBullets[i].getYPos() &lt; -screenHeight ){
              numBullets[i].fireStatus = false;
              numBullets[i].reset(player);
              numBullets[i].~Bullet();
          }
      }
  }
  
  player.updatePosition(playerTex,delta);
  
  glFlush();
  
  timestamp = clock();
  </code></pre>
  
  <p>}</p>
  
  <p>My Update positiom method</p>
  
  <pre><code>void Player::updatePosition(GLuint playerTex, float factor){
  //draw triangle
  glPushMatrix();
  
  glEnable(GL_TEXTURE_2D);    
  glEnable(GL_BLEND);
  glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
  glBindTexture(GL_TEXTURE_2D, playerTex);
  glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
  
  glTranslatef(factor*XPos, factor*YPos, 0.0);
  glRotatef(heading, 0,0,1);
  glColor3f(1.0,0.0,0.0);
      glBegin(GL_POLYGON);
          glTexCoord2f(0.0, 1.0); glVertex2f(-40,40);
          glTexCoord2f(0.0, 0.0); glVertex2f(-40,-40);
          glTexCoord2f(1.0, 0.0); glVertex2f(40,-40);
          glTexCoord2f(1.0, 1.0); glVertex2f(40,40);
      glEnd();
  
  glDisable(GL_BLEND);
  glDisable(GL_TEXTURE_2D);
  glPopMatrix();
  
  XPos += speed*cos((90+heading)*(PI/180.0f));
  YPos += speed*sin((90+heading)*(PI/180.0f));
  }
  </code></pre>