Sign in to follow this  

stride and Interleaved arrays

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

If you intended to correct an error in the post then please contact us.

Recommended Posts

I am trying to render a terrain mesh. I have 2 questions 1.In glVertexpointer API, there is a parameter called stride. What is its use. When I specify 0, it is ok. But others does not work. Why? 2. How does glInterleaved works. Is it necessary to use. Can I do away with this.

Share this post


Link to post
Share on other sites
The stride usually means what is the size of an single vertex. for example if you have
struct Vertex
{
float x,y,z;
}

Then your stride would be 12 bytes. or you can simply use sizeof(Vertex)

Share this post


Link to post
Share on other sites
actually, stride is the space between vertices.
so if you packed the Vertex like this:

struct Point
{
float x, y, z;
}

struct Normal
{
float x, y, z;
}

struct Vertex
{
Point pos;
Normal norm;
...
}

Vertex vtx;


then the vertex pointer would be 0 and stride would be sizeof(Vertex) - sizeof(Point)
normal pointer would be 12 and stride would be sizeof(Vertex) - sizeof(Normal)

etc., etc., etc.

Share this post


Link to post
Share on other sites
Quote:
Original post by JPulham
actually, stride is the space between vertices.
so if you packed the Vertex like this:
*** Source Snippet Removed ***
then the vertex pointer would be 0 and stride would be sizeof(Vertex) - sizeof(Point)
normal pointer would be 12 and stride would be sizeof(Vertex) - sizeof(Normal)

etc., etc., etc.

It's not. The stride is the distance from the start of one vertex to the start of the next. A stride of zero is a special case to mean a tightly packed attribute array.

Share this post


Link to post
Share on other sites
I believe stride is used if there is empty space between the vertex data that you are trying to use. If you loaded the array with your vertex data one right after the other then just use 0 which means the data is coming with no breaks.

Share this post


Link to post
Share on other sites

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

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this