going from immediete mode to vertex array

Hi! I’ve been using immediate mode for some time, and reading my vertex and faces from my 3ds loader, though now im going on to vertex arrays, what i wonder about is how the array is built,

for what it seems, its adding x,y,z,x,y,z,x,y,z in a one dimensional array, though the result i had with it was not good.

(pseudo)
so doing a for loop, f.exm for (vertxcounter=0;vertexcounter<numvertxes;vertxvounter++)
VertexArray[vertexcounter] = vertx;
VertexArray[vertexcounter+1] = verty;
VertexArray[vertexcounter+2] = vertz;

(vertexarray[numvertx * 3]
would be a mistake i guess? :slight_smile:

You are increasing your counter in the for loop with 1, while you enter three values. So, what happens is the following:

VertexArray[0] = vertx0;
VertexArray[1] = verty0;
VertexArray[2] = vertz0;
VertexArray[1] = vertx1; // notice the index of the VertexArray
VertexArray[2] = vertx1;
VertexArray[3] = vertx1;

Instead make the following loop:


for (size_t vertexcounter = 0; vertexcounter < numvertices; ++vertexcounter)
{
  VertexArray[3 * vertexcounter] = vertx;     // indices 0, 3, 6, ...
  VertexArray[3 * vertexcounter + 1] = verty; // indices 1, 4, 7, ...
  VertexArray[3 * vertexcounter + 2] = vertz; // indices 2, 5, 8, ...
}