Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>In this code</p> <pre><code>void drawLines() { glBegin(GL_LINES); glColor3f(1.0,0.0,0.0); for(int i=0;i&lt;z;i++) { glVertex2f(arr[i][0],arr[i][1]); } glEnd(); } </code></pre> <p><code>GL_LINES</code> is a drawing mode where two consecutive vertices make a line segment. Then the next two and so so. What you're drawing is a <em>line strip</em>; replacing <code>GL_LINES</code> with <code>GL_LINE_STRIP</code> will give you your expected result.</p> <p>On a side note: You should abandon using immediate mode (glBegin, glVertex, glEnd). It's slow, it's cumbersome to work with and in the long term can become a major PITA. Use at least vertex arrays; they've been the recommended way of supplying geometry data for well over 15 years. Plus it makes your code much simpler. Your code above can be replaced with this:</p> <pre><code>/* vertex data comes from an array */ glEnableClientState(GL_VERTEX_ARRAY); /* we want to use a common color for all vertices */ glDisableClientState(GL_COLOR_ARRAY); glColor3f(1.0, 0.0, 0.0); /* where to get the data from */ glVertexPointer(2, GL_DOUBLE, sizeof(double)*4, arr); /* draw the whole thing */ glDrawArrays(GL_LINE_STRIP, 0, z); /* cleanup */ glDisableClientState(GL_VERTEX_ARRAY); </code></pre> <p>As you can see it's shorter, more concise, easier to read and it avoids doing <code>z+3</code> function calls, each of which taking some time to execute.</p> <p><strong>Important</strong> that OpenGL can digest that multidimensional array <code>arr</code> is due to the fact, that statically allocated storage of multidimensional arrays is always contiguous. It would not work if you'd allocate an array of pointers to arrays (the naive way to allocate multidimensional arrays dynamically).</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload