# Thread: How do I draw separate triangles (not attached) in one draw call?

1. ## How do I draw separate triangles (not attached) in one draw call?

If I instantiate and position two separate quadrangles

Code :
```	Quadrangle q0;
q0.setPosition(glm::vec3(0, 0, 0));

q1.setPosition(glm::vec3(1, 1, 1));```

I can draw them separately in separate draw calls with no problems.

I encounter problems if I try and draw them in the same draw call

Code :
`	glDrawElements(GL_TRIANGLES, m_numQuadrangles * 6, GL_UNSIGNED_SHORT, BUFFER_OFFSET(0));`

A connecting triangle between the first and second quadrangle is drawn and the second quadrangle triangles are ignored completely.

My indices for each quadrangle are correct

Code :
```	int numIndices = 0;

for (int i = 0; i < maxQuadrangles; i++)
{
// CW Winding [0, 1, 2] [1, 3, 2]
m_indices[numIndices++] = 0 + i;
m_indices[numIndices++] = 1 + i;
m_indices[numIndices++] = 2 + i;

m_indices[numIndices++] = 1 + i;
m_indices[numIndices++] = 3 + i;
m_indices[numIndices++] = 2 + i;
}```

m_numQuadrangles * 6 is the correct index count depending on the number of quadrangles.

The vertices are set correctly

Code :
```	std::array<VertexPositionTexture, 4> v = quadrangle.getVertices();
std::copy(v.begin(), v.end(), m_vertices.begin() + (m_numQuadrangles * 4));

...

glBindBuffer(GL_ARRAY_BUFFER, vbuffer);
glBufferData(GL_ARRAY_BUFFER, maxVertices * sizeof(VertexPositionTexture), &m_vertices[0], GL_DYNAMIC_DRAW);```

How can I make sure the triangles making up each quadrangle are completely separate but only using one draw call?

2. You probably want something like:
Code :
```m_indices[numIndices++] = 0 + i * 6;
m_indices[numIndices++] = 1 + i * 6;
m_indices[numIndices++] = 2 + i * 6;

m_indices[numIndices++] = 1 + i * 6;
m_indices[numIndices++] = 3 + i * 6;
m_indices[numIndices++] = 2 + i * 6;```

3. Thanks Dan. I've solved it. You highlighted the problem area but the solution is:

Code :
```	for (int i = 0; i < maxQuadrangles; i += 4)
{
// CW Winding [0, 1, 2] [1, 3, 2]
m_indices[numIndices++] = 0 + i;
m_indices[numIndices++] = 1 + i;
m_indices[numIndices++] = 2 + i;

m_indices[numIndices++] = 1 + i;
m_indices[numIndices++] = 3 + i;
m_indices[numIndices++] = 2 + i;
}```

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•