# glDrawArrays(GL_TRIANGLES, ......)

This topic is 486 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

I'm creating some vertex data using a vector<GLfloat>:

	    static vector<GLfloat> vertices = {

// 3D position, 2D texture coordinate

// card front
-0.1, -0.1,  0.0,   1*0.125, 4*0.125, // vertex 0
0.1, -0.1,  0.0,   2*0.125, 4*0.125, // vertex 1
0.1,  0.1,  0.0,   2*0.125, 5*0.125, // vertex 2
-0.1, -0.1,  0.0,   1*0.125, 4*0.125, // vertex 0
0.1,  0.1,  0.0,   2*0.125, 5*0.125, // vertex 2
-0.1,  0.1,  0.0,   1*0.125, 5*0.125, // vertex 3
// card back
0.1,  0.1,  0.0,   4*0.125, 2*0.125, // vertex 2
0.1, -0.1,  0.0,   4*0.125, 1*0.125, // vertex 1
-0.1, -0.1,  0.0,   5*0.125, 1*0.125, // vertex 0
0.1,  0.1,  0.0,   4*0.125, 2*0.125, // vertex 2
-0.1, -0.1,  0.0,   5*0.125, 1*0.125, // vertex 0
-0.1,  0.1,  0.0,   5*0.125, 2*0.125  // vertex 3
};


Then I draw it:

	    glDrawArrays(GL_TRIANGLES, 0, vertices.size());


What is the correct value for the final parameter of glDrawArrays()? vertices.size() or vertices.size()/5? Both appear to work.

Edited by sjhalayka

##### Share on other sites

You have here 12 vertices, so your number should be 12.
Your vertices vector contains 60 elements (3x float for position, 2x float for uv), so doing

vector.size() / 5         // => 60/5 = 12

is the correct way.

If you prefer to keep vertex data in one array you might want to consider adding some struct

struct MyVector
{
float x, y, z;
float u, v;
}

and:

static vector<MyVector> vertices

then you can simply do:

vertices.size() // gives 12 now

There are also others methods how you can organize your vertex data, for example keeping vertex and uv data as separate arrays (you can look it up if you want) but I hope this answers your question.

##### Share on other sites

Thank you so much for the reply, and for the ideas!

1. 1
2. 2
Rutin
17
3. 3
4. 4
5. 5

• 13
• 26
• 10
• 11
• 9
• ### Forum Statistics

• Total Topics
633735
• Total Posts
3013596
×