Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>The problem with your syntax is by saying targetVertices[iii] you re referring to the iiith index of the array, not the entire column. 2D arrays are stored as 1D arrays, but provide [][] for simple access. You can refer to them as single or dual dimensional.</p> <p>Here is a more reusable way to approach this.</p> <pre><code>void addVertex(std::vector&lt;GLfloat&gt; &amp;data, GLfloat x, GLfloat y, GLfloat z) { data.push_back(x); data.push_back(y); data.push_back(z); } </code></pre> <hr> <pre><code>void addCube(std::vector&lt;GLfloat&gt; &amp;data, GLfloat x, GLfloat y, GLfloat z) { addVertex(data, x-1, y-1, z-1); addVertex(data, x-1, y-1, z+1); addVertex(data, x-1, y+1, z+1); addVertex(data, x-1, y+1, z-1); addVertex(data, x+1, y-1, z-1); addVertex(data, x+1, y-1, z+1); addVertex(data, x+1, y+1, z+1); addVertex(data, x+1, y+1, z-1); addVertex(data, x-1, y-1, z-1); addVertex(data, x-1, y-1, z+1); addVertex(data, x+1, y-1, z+1); addVertex(data, x+1, y-1, z-1); addVertex(data, x-1, y+1, z-1); addVertex(data, x-1, y+1, z+1); addVertex(data, x+1, y+1, z+1); addVertex(data, x+1, y+1, z-1); addVertex(data, x-1, y-1, z-1); addVertex(data, x-1, y+1, z-1); addVertex(data, x+1, y+1, z-1); addVertex(data, x+1, y-1, z-1); addVertex(data, x-1, y-1, z+1); addVertex(data, x-1, y+1, z+1); addVertex(data, x+1, y+1, z+1); addVertex(data, x+1, y-1, z+1); } </code></pre> <hr> <pre><code>void makeCubes(std::vector&lt;GLfloat&gt; &amp;data) { float targetX[10], targetY[10], targetZ[10]; data.clear(); data.reserve(720); //...initialize the above arrays... for (int i=0; i&lt;10; i++) { std::vector&lt;GLfloat&gt; newData; addCube(newData, targetX[i], targetY[i], targetZ[i]); data.insert(data.begin(), newData.begin(), newData.end()); } } </code></pre> <hr> <p>You can easily convert this to a C-array by taking a reference to the first element:</p> <pre><code>std::vector&lt;GLfloat&gt; data; makeCubes(data); GLfloat *cArray = &amp;data[0]; </code></pre> <p>A call to glBufferData could be made like this:</p> <pre><code>glBufferData(GL_ARRAY_BUFFER, data.size()*sizeof(GLfloat), &amp;data[0], GL_STREAM_DRAW); </code></pre>
 

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