title: How to calculate the shift parameters of glTranslatef function in opengl
body: <p>I am a newbie to opengl and confused about how to caculate the parameters of glTranslatef.
  Here is my display code </p>
  
  <pre><code>void display()
  {
  
  
      glPushMatrix();
      glClearColor(1.0f, 1.0f, 1.0f, 1.0f);   // background
  
      glClear(GL_DEPTH_BUFFER_BIT | GL_COLOR_BUFFER_BIT);
  
      glScalef(1.f,1.f,1.f);
      glTranslatef(2.f,0.f,0);
  
  
      glBegin(GL_QUADS);
      glVertex2f(-1.0f,-1.0f);
      glTexCoord2f(0.0f,1.0f); 
  
      glVertex2f(1.0f,-1.0f);
      glTexCoord2f(0.0f,0.0f); 
  
      glVertex2f(1.0f,1.0f);
      glTexCoord2f(1.0f,0.0f); 
  
      glVertex2f(-1.0f,1.0f);
      glTexCoord2f(1.0f,1.0f); 
  
      glEnd();  
      //here is my drawing code,ignore it
      runCuda();
      glBindBuffer(GL_PIXEL_UNPACK_BUFFER, pbo);
  
      glBindTexture(GL_TEXTURE_2D, textureID);
  
      glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 1024, 768,/*window_width, window_height,*/ 
          GL_RGB, GL_UNSIGNED_BYTE, NULL);
  
      glPopMatrix();
      glFlush();
  }
  </code></pre>
  
  <p>here is my initiate gl code</p>
  
  <pre><code> bool initGL(int argc, char **argv)
      {
      glutInit(&amp;argc, argv);
      glutInitDisplayMode(GLUT_RGBA | GLUT_SINGLE);
      glutInitWindowSize(window_width, window_height);
      glutCreateWindow("Cuda GL Interop Demo (adapted from NVDIA's simpleGL)");
  
      glutDisplayFunc(fpsDisplay);
  
      glewInit();
      if(!glewIsSupported("GL_VERSION_2_0"))
      {
          fprintf(stderr, "ERROR: Support for necessary OpengGL extensions missing.");
          return false;
      }
  
      glViewport(0, 0, window_width, window_height);  
  
      glClearColor(0.0, 0.0, 0.0, 1.0);  
      glDisable(GL_DEPTH_TEST);  
  
      glMatrixMode(GL_MODELVIEW);  
      glLoadIdentity();  
  
      glMatrixMode(GL_PROJECTION); // Add this line
      glLoadIdentity(); 
  
      gluOrtho2D(-1.0f, 1.0f, -1.0f, 1.0f);//, -1.0f, 1.0f);  
  
  
      return true;
      }
  </code></pre>
  
  <p>The problem is that,When nScale = 1.f,we apply gltranslatef(1.f,0,0) to move leftside at the middle of the window, and gltranslatef(2.f,0,0) to move the picture out of window(2.f is the munimum shift value to move picture out of window).But if I change the nScale to 2.f ,we need change to x_shift to 1.5f(gltranslatef(1.5f,0,0))to move the picture of the window ,or change the nScale to 4.f ,we need change to x_shift to 1.25f to move the picture of the window.I am confused about x_shift(or y_shift) in gltranslate function. It looks that we need change the shift value to (1 + 1/nScale^2),is that correct?How to get that equation?I hope someone can help me.
  here is the original pic:
  <img src="https://i.stack.imgur.com/FgJDB.jpg" alt="enter image description here"></p>
  
  <p>here is the pic applied to (glScalef(1.f,1.f,1.f),glTranslatef(1.f,0.f,0))
  <img src="https://i.stack.imgur.com/KchQl.jpg" alt="enter image description here"></p>
  
  <p>here is the pic applied to (glScalef(1.f,1.f,1.f),glTranslatef(2.f,0.f,0))，which is moved out of window just right</p>
  
  <p><img src="https://i.stack.imgur.com/YjQFH.jpg" alt="enter image description here"></p>