# Rectangular Prism Vertices

I am trying to create a rectangular prism from vertices, however when I do glDrawArrays with GL_LINES, it seems that two of the three vertices are counted for the triangle drawn and it gives the odd shape below. I have my vertices building code below, any idea why this is happening? Thanks

``````glGenVertexArrays(1, &vao);
glBindVertexArray(vao);

//Back Face
addVert(x + width, y, z);
addVert(x + width, y + height, z);

addVert(x + width, y + height, z);
addVert(x, y + height, z);

//Front face
addVert(x, y, z + length);
addVert(x + width, y, z + length);
addVert(x + width, y + height, z + length);

addVert(x, y, z + length);
addVert(x + width, y + height, z + length);
addVert(x, y + height, z + length);

//Right Face
addVert(x + width, y, z);
addVert(x + width, y, z + length);
addVert(x + width, y + height, z + length);

addVert(x + width, y, z);
addVert(x + width, y + height, z + length);
addVert(x + width, y + height, z);

//Left Face
addVert(x, y, z + length);
addVert(x, y + height, z);

addVert(x, y, z + length);
addVert(x, y + height, z);
addVert(x, y + height, z + length);

//Top Face
addVert(x, y + height, z);
addVert(x + width, y + height, z);
addVert(x + width, y + height, z + length);

addVert(x, y + height, z);
addVert(x + width, y + height, z + length);
addVert(x, y + height, z + length);

//bottom face
addVert(x + width, y, z);
addVert(x + width, y, z + length);

addVert(x + width, y, z + length);
addVert(x, y, z + length);

glGenBuffers(1, &vbo);
glBindBuffer(GL_ARRAY_BUFFER, vbo);
glBufferData(GL_ARRAY_BUFFER, sizeof(float) * vert.size(), &vert[0], GL_STATIC_DRAW);
//glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 0, (void *) 0);
glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 3 * sizeof(float), (void*)0);
``````

It’s happening because you’re supplying vertices for triangles, not lines. Triangles consume vertices in groups of 3, lines use groups of 2.

If you need to switch between triangles and lines, either use `GL_TRIANGLES` for the draw call and use `glPolygonMode` with `GL_FILL` or `GL_LINE`, or use `glDrawElements` and use different index arrays for triangles and lines. The latter option is preferable as you can omit the diagonals.