# What stride parameter in Vertex Arrays exactly does??

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

## Recommended Posts

I am studying about vertex array. And I dont understand the stride parameters at all.

##### Share on other sites
Stride is the size of the structure that you are storing in the array. Since the array is prolly a contiguous block of memory, you have to tell it how big each chunk is.

That's how it is in DirectX, no doubt similar in OGL.

Hope that helps,

Dave

##### Share on other sites
It's not exactly how Dave suggested. Yes, it is the size of one vertex (texcoord, normals, tangent, binormal, position added together). However, since these are normally stored sequentially, OpenGL allows you to pass in a size of 0 in that case, which is read as 'continuous'. If you had for example texture coordinates in your data structure, but don't require them in this draw call, you would have to use the stride parameter do jump to the correct start of the next vertex.

##### Share on other sites
So if my array got only floating point. I pass 0 right? but If I got another type what should I pass to??

##### Share on other sites
No no no, this is how it works:

Say you have a structure that holds all your verts:
struct myVert{    float   position[3];    float   texcoord[2];};

And for each vertex of your model, you have one of these. Basically, you have an array of myVert structures, all filled out with all your data:
myVert *verts = new myVert[numVerts];setupVerts(verts);

Now, when you want to go through and draw using this data, this is where the stride comes into play:
glVertexPointer (3, GL_FLOAT, sizeof(myVert), (void *)((float *)verts + 0));glEnableClientState (GL_VERTEX_ARRAY);glClientActiveTextureARB (GL_TEXTURE0_ARB);glTexCoordPointer (2, GL_FLOAT, sizeof(myVert), (void *)((float *)verts + 3));glEnableClientState (GL_TEXTURE_COORD_ARRAY);

Notice, the stride parameter is basically "How many bytes do I need to go to get to the beginning of the next set of this data?" Since all our vertices are packed neatly together in an array, it's simply the size of an element of the array (myVert).

The last parameter is where the FIRST element is, so for the position, it's just the beginning of the array (since the position is first), and for the texcoord, it's 3 floats into the array (since the texcoords are directly after the position).

Hope that helps!

Oh, one more thing: If the stride parameter is zero, then it is implied that the data is tightly packed in the array, with nothing in between. If, for example, you only had position in your struct, like:
struct myVert{    float  pos[3];}

Then you could pass in zero, instead of passing in sizeof(myVert), because there is nothing inbetween successive elements. This is generally worthless, though, because you'll rarely (if ever!) have just one big array full of the same type of data, and if you pass in zero the API will just calculate the value for you anyway (using the first two parameters - 2 and GL_FLOAT = 2 * sizeof(float) ).

1. 1
Rutin
37
2. 2
3. 3
4. 4
5. 5

• 11
• 10
• 13
• 103
• 11
• ### Forum Statistics

• Total Topics
632977
• Total Posts
3009674
• ### Who's Online (See full list)

There are no registered users currently online

×