title: how do i calculate glFrustum parameters?
body: <p>I have this code:</p>
  <pre><code>/*
   * This is a simple program that computes FPS
   * by means of a circular buffer
   */
  #include &lt;GL/glut.h&gt;
  //#include &lt;numeric&gt;
  #include &lt;unistd.h&gt;
  #include &lt;time.h&gt;
  #include &lt;stdio.h&gt;
  
  // Number of elements in the circular buffer
  #define NELS    10
  
  // Number of lines
  #define NLINES  10000
  
  // circular buffer used to compute frame rate
  float circularBuffer[NELS];
  int firstInd = 0, nEls = 0;
  
  // function to get the number of elapsed ticks
  uint32_t getTick()
  {
      struct timespec ts;
      unsigned theTick = 0U;
      clock_gettime( CLOCK_REALTIME, &amp;ts );
      theTick  = ts.tv_nsec / 1000000;
      theTick += ts.tv_sec * 1000;
      return theTick;
  }
  
  // Function to compute real modulus and NOT remained as % does
  inline int modulo(int a, int b) {
      const int result = a % b;
      return result &gt;= 0 ? result : result + b;
  }
  
  // Compute sum of the elements in the circular buffer
  float sumCircularBuffer()
  {
      int ind;
      float sum = 0;
  
      if (nEls &gt; 0) {
          for (ind=1; ind&lt;=nEls; ind++) {
              sum = sum + circularBuffer[modulo(firstInd-ind, NELS)];
          }
      }
  
      return sum;
  }
  
  // accumulate buffer and update window title
  void computeAndShowFrameRate(void)
  {
      static float lastTime = 0.0f;
      static unsigned int frameCount = 0;
      char windowTitle[100];
      float sumFPS;
  
      float currentTime = (float)getTick() * 0.001f;
      // Initialize lastTime to the current time
      if (lastTime == 0) {
          lastTime = currentTime;
      }
  
      // increase frame count
      frameCount++;
      if (currentTime - lastTime &gt; 1.0f) {
          // insert the current fps in the circular buffer
          circularBuffer[firstInd] = ((float)frameCount) / (currentTime - lastTime);
  
          // update variable lastTime
          lastTime = currentTime;
  
          //circularBuffer[firstInd] = (float)frameCount;
          firstInd = ((firstInd+1)%NELS);
          if (nEls &lt; NELS) {
              nEls++;
          }
          frameCount = 0;
  
          // sum elements in circular buffer
          sumFPS = sumCircularBuffer();
          snprintf(windowTitle, 100, &quot;FPS = %6.2f&quot;, sumFPS/nEls);
          // update window title
          glutSetWindowTitle(windowTitle);
      }
  }
  
  // display function
  void display(void)
  {
      int currLineInd;
  
      // get current frame rate
      computeAndShowFrameRate();
  
      // clear buffer
      glClear (GL_COLOR_BUFFER_BIT);
  
      for (currLineInd = 0; currLineInd&lt;NLINES; currLineInd++) {
          // draw line
          glBegin(GL_LINES);
          // random color
          glColor3f((float)rand()/RAND_MAX, (float)rand()/RAND_MAX, (float)rand()/RAND_MAX);
          // random first point
          glVertex2f((float)rand()/RAND_MAX, (float)rand()/RAND_MAX);
          // random color
          glColor3f((float)rand()/RAND_MAX, (float)rand()/RAND_MAX, (float)rand()/RAND_MAX);
          // random second point
          glVertex2f((float)rand()/RAND_MAX, (float)rand()/RAND_MAX);
          glEnd();
      }
  
      glFinish();
      glutPostRedisplay();
  }
  
  // initialization function
  void init (void)
  {
      // Use current time as seed for random generator
      srand(time(0));
  
      // select clearing color
      glClearColor (0.0, 0.0, 0.0, 0.0);
  
      // Orthographic projection
      glOrtho(0.0, 1.0, 0.0, 1.0, -1.0, 1.0);
  }
  
  // Window size and mode
  int main(int argc, char** argv)
  {
      // pass potential input arguments to glutInit
      glutInit(&amp;argc, argv);
  
      // set display mode
      // GLUT_SINGLE = single buffer window
      glutInitDisplayMode (GLUT_SINGLE | GLUT_RGB);
  
      glutInitWindowSize (400, 400);
      glutInitWindowPosition (100, 100);
      glutCreateWindow (&quot;OpenGL Window&quot;);
  
      // Call initialization routinesx
      init();
      glutDisplayFunc(display);
      glutMainLoop();
      return 0;
  }
  </code></pre>
  <p>I have to replace the glOrtho function with glFrustum and get the same result.</p>
  <p>I read the opengl guide on khronos and understood the differences between glOrtho and glFrustum but i can't figure out how to calculate the parameters.</p>
  <p>How do I calculate the parameters to pass to the glFrustum function?</p>