stride and Interleaved arrays
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.
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)
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:
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.
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.
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.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement