title: c++ opengl draw cylinder using GL_LINE_LOOP
body: <p>So i am trying to replicate a cylinder using a nest for-loop by drawing a series of squares in a circle fashion (check image). This is my code which I need to implement. I know I'm supposed to achieve the four coordinates of each line loop repeatedly until its a circle. I don't know how to calculate the:</p>
  
  <p>-deltaZ</p>
  
  <p>-xLeft</p>
  
  <p>-yLeft</p>
  
  <p>-xRight</p>
  
  <p>-yRight</p>
  
  <p>-thetaRight </p>
  
  <p>Could I get some help? Thanks! (P.S. numSides is at least 3 and numStacks starts out at about 10</p>
  
  <pre><code>//Move everything to the z axis
  glTranslatef(0.0, 0.0, 2.0);
  //change its size so that way its so big
  glScalef(0.5, 0.5, 0.0);
  
  float radius = 1.0;
  float zTop = 1.0;
  float zBottom;
  float xLeft;
  float yLeft;
  float xRight;
  float yRight;
  float thetaRight;
  
  for (int m = 0; m &lt;= numStacks; m++)
  {
  
    zBottom = zTop-deltaZ;
    xLeft = 0;
    yLeft = 0;
    thetaRight = m*pi/numStacks;
    for (int i=0; i&lt;numSides; i++)
    {
      xRight = 0;
      yRight = 0;
      glBegin(GL_LINE_LOOP);
      //top left
      glVertex3f(xLeft, yLeft, zTop);
      //bottom left
      glVertex3f(xLeft, yLeft, zBottom);
      //bottom right
      glVertex3f(xRight, yRight, zBottom);
      //top right
      glVertex3f(xRight, yRight, zBottom);
      glEnd();
  
      //exchanging these values moves the
      //line_loop to the right
      xLeft = xRight;
      yLeft = yRight;
      thetaRight = thetaRight + i*pi/numSides;
   }
    zTop = zBottom;
  }
  </code></pre>
  
  <p><img src="https://i.stack.imgur.com/CWZeV.png" alt="enter image description here"> </p>