title: Drawing a linestrip with opengl1 by looping through a linked list of vectors
body: <p>i have previously asked a <a href="https://stackoverflow.com/questions/61527670/adding-coordinates-of-clicks-with-glut-to-a-linked-list-in-c">question</a> about appending coordinates of clicks to a singly linked list, in order to loop through the linked list ,put vertices at the positions of the clicks and connect them <a href="https://i.stack.imgur.com/l1aKL.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/l1aKL.png" alt="a linestrip with 6 vertices"></a></p>
  
  <p>The answer given solved my issues with overflow of the linked list but afterwards i had problems with the display function, such that when i loop through the linked list and add those coordinates to <code>glVertex2i();</code>, it doesn't draw a linestrip when i click multiple times on the graphical window.</p>
  
  <p>I tried to see what would happen when i removed the <code>while</code> loop, but that would cause segmentation fault.</p>
  
  <p>These are the structs.</p>
  
  <pre><code>typedef struct vector{int x;int y;}Vector;
  typedef struct VectorList{Vector X; struct VectorList*next; }node_v;
  </code></pre>
  
  <p>And i had declared these</p>
  
  <pre><code>Vector P;
  node_v * prev;
  </code></pre>
  
  <p>And with the help of the answer to <a href="https://stackoverflow.com/questions/61527670/adding-coordinates-of-clicks-with-glut-to-a-linked-list-in-c">my previous question</a>, initialized <code>Vector P</code> with the coordinates of the clicks and appended to the linked list of vectors <code>node_v * prev;</code></p>
  
  <pre><code>static void _display_CB()
  {
      glMatrixMode(GL_PROJECTION);
      glLoadIdentity();
      glMatrixMode(GL_MODELVIEW);
      glLoadIdentity();
      glOrtho(0,window_width,window_height,0,-1,1);
  
      glClear(GL_COLOR_BUFFER_BIT);
  
      glColor3ub(0,0,0);
      glBegin(GL_LINE_STRIP);
      while(prev){
          glVertex2i( prev-&gt;X.x, prev-&gt;X.y);
          prev=prev-&gt;next;
      }
  
      glEnd();
      glFlush();
    glutSwapBuffers();
  glutPostRedisplay();
  }
  </code></pre>
  
  <p>What changes should be done in <code>_display_CB()</code> for the program to be able to draw linestrips like in the picture?</p>