stride and Interleaved arrays

Started by
3 comments, last by Funkyjive 15 years, 8 months ago
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.
Advertisement
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)
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.
pushpork
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.
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.
"I would rather be in the boat with a drink on the rocks, than in the drink with a boat on the rocks" -Unknown

This topic is closed to new replies.

Advertisement