glDrawArrays, seems to ignore stride parameter?

  • Follow


The following works, to draw a square:
		float a[] = {
				   	  -1, 1, 0,
			          1, 1, 0,
					  -1,-1, 0,
					  1,1,0,
					  -1,-1,0,
					  1,-1,0,
		};
		glVertexPointer( 3, GL_FLOAT, 0, a );
		glDrawArrays( GL_TRIANGLES, 0, 6 );

The following code has the same logic, but I have inserted an extra 
float between each vertex.  I tell opengl by setting the stride to be 
sizeof(float).  But the following make square scrambled.
		float a[] = {
				   	  -1, 1, 0,
			99,
			          1, 1, 0,
			99,
					  -1,-1, 0,
			99,
					  1,1,0,
			99,
					  -1,-1,0,
			99,
					  1,-1,0,
			99,
		};
		glVertexPointer( 3, GL_FLOAT, sizeof(float), a );
		glDrawArrays( GL_TRIANGLES, 0, 6 );

Thanks,
~S
0
Reply sheam 5/18/2008 10:52:14 PM

sheam wrote:
> The following works, to draw a square:
>         float a[] = {
>                          -1, 1, 0,
>                       1, 1, 0,
>                       -1,-1, 0,
>                       1,1,0,
>                       -1,-1,0,
>                       1,-1,0,
>         };
>         glVertexPointer( 3, GL_FLOAT, 0, a );
>         glDrawArrays( GL_TRIANGLES, 0, 6 );
> 
> The following code has the same logic, but I have inserted an extra 
> float between each vertex.  I tell opengl by setting the stride to be 
> sizeof(float).  But the following make square scrambled.
>         float a[] = {
>                          -1, 1, 0,
>             99,
>                       1, 1, 0,
>             99,
>                       -1,-1, 0,
>             99,
>                       1,1,0,
>             99,
>                       -1,-1,0,
>             99,
>                       1,-1,0,
>             99,
>         };
>         glVertexPointer( 3, GL_FLOAT, sizeof(float), a );
>         glDrawArrays( GL_TRIANGLES, 0, 6 );
> 
> Thanks,
> ~S

Ok, I figure it out.  stride is described in man page as bytes between. 
  But it is actually the number of bytes from start to start of next. 
i.e., sizeof(float)*4 worked.

~S
0
Reply sheam 5/18/2008 10:54:40 PM


On May 18, 5:54=A0pm, sheam <she...@eastlink.ca> wrote:

> > The following code has the same logic, but I have inserted an extra
> > float between each vertex. =A0I tell opengl by setting the stride to be
> > sizeof(float). =A0But the following make square scrambled.

[...]

> Ok, I figure it out. =A0stride is described in man page as bytes between.
> =A0 But it is actually the number of bytes from start to start of next.
> i.e., sizeof(float)*4 worked.

It can also be 0 for tightly packed arrays:

    stride   Specifies the byte offset  between  consecutive
vertexes.  If
                stride  is 0, the vertexes are understood to be
tightly packed
                in the array. The initial value
                is 0.

Since your second example isn't tightly packed, you needed to specify
the offset.

- Chris
0
Reply crjjrc 5/19/2008 12:26:06 PM

2 Replies
174 Views

(page loaded in 0.039 seconds)

Similiar Articles:













7/18/2012 1:03:47 PM


Reply: