# glDrawArrays question

**URL:** <https://discourse.libcinder.org/t/gldrawarrays-question/472>\
**Category:** Using Cinder\
**Created:** [December 31, 2016, 8:27am UTC](https://discourse.libcinder.org/t/gldrawarrays-question/472 "2016-12-31T08:27:45Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![seph](https://avatars.discourse-cdn.com/v4/letter/s/87869e/32.png) [@seph](https://discourse.libcinder.org/u/seph)\
**Post date:** [December 31, 2016, 8:27am UTC](https://discourse.libcinder.org/t/gldrawarrays-question/472/1 "2016-12-31T08:27:45Z")

</div>

Hi,

I have a question regarding using gldrawarrays in transform feedback.  
Here is the code:

```auto
mFeedbackObj[1 - mDrawIdx]->bind();
gl::beginTransformFeedback( GL_POINTS );
gl::drawArrays( GL_POINTS, 2*mNumNodes, mNumNodes * mNumLines - 2 * mNumNodes );
gl::endTransformFeedback();
mFeedbackObj[1 - mDrawIdx]->unbind();

```

which is pretty much the same with the transform feedback sample.

And the problem is, for `gl::drawArrays(GL_POINTS, startIndex, numberOfPoints);`  
If I put 0 as startIndex, everything is working as expected, no matter what number I put for numberOfPoints.  
But if I change startIndex to some other number and reduce the numberOfPoints accordingly, something odd happens.

And here is the update shader code:

```auto
#version 330 core

#define LIMIT 0.9549296586
#define M_PI 3.1415926535

layout (location = 0) in vec3 VertexPosition;
uniform float uTime;
out vec3 tfPosition;

//taken from http://www.neilmendoza.com/glsl-rotation-about-an-arbitrary-axis/
mat4 rotationMatrix(vec3 axis, float angle)
{
    float s = sin(angle);
    float c = cos(angle);
    float oc = 1.0 - c;
    return mat4(oc * axis.x * axis.x + c, oc * axis.x * axis.y - axis.z * s, oc * axis.z * axis.x + axis.y * s, 0.0,
                oc * axis.x * axis.y + axis.z * s, oc * axis.y * axis.y + c, oc * axis.y * axis.z - axis.x * s, 0.0,
                oc * axis.z * axis.x - axis.y * s, oc * axis.y * axis.z + axis.x * s, oc * axis.z * axis.z + c, 0.0,
                0.0, 0.0, 0.0, 1.0);
}

vec3 rotateVector(vec3 vector, float angle, vec3 axis)
{
    mat4 matrix = rotationMatrix(axis, angle);
    vec4 res = matrix * vec4(vector,1.0);
    return res.xyz;
}

void main()
{
    tfPosition = rotateVector(VertexPosition,uTime,vec3(0,1,0));
}

```

Since the update shader only uses the current vertex position passed in to rotate it surrounds a pivot, it shouldn’t be interfered by other vertices I think.  
Any thoughts? Possibilities?

And happy new year!  
-seph

---

<div class="post-metadata">

**Author:** ![paul.houx](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.libcinder.org/paul.houx/32/31_2.png) [@paul.houx](https://discourse.libcinder.org/u/paul.houx)\
**Post date:** [December 31, 2016, 10:05am UTC](https://discourse.libcinder.org/t/gldrawarrays-question/472/2 "2016-12-31T10:05:52Z")

</div>

Can you describe what happens?

---

<div class="post-metadata">

**Author:** ![seph](https://avatars.discourse-cdn.com/v4/letter/s/87869e/32.png) [@seph](https://discourse.libcinder.org/u/seph)\
**Post date:** [January 2, 2017, 9:09pm UTC](https://discourse.libcinder.org/t/gldrawarrays-question/472/3 "2017-01-02T21:09:05Z")

</div>

Yeah,  
So here is the screenshot when things work as expected:

 ![](https://canada1.discourse-cdn.com/flex030/uploads/libcinder/original/1X/5536d23072ac73d4190447038e75ad383f8e0e12.png)  
8 rings should rotate around the center pivot;

 ![](https://canada1.discourse-cdn.com/flex030/uploads/libcinder/original/1X/fa8bbc52daa46da723d0e9c13b2f09a245eab786.png)

And this is what happens after I change the startIndex to 2\*mNumNodes. If it work as expected, then there should be 6 rings rotating while the other 2 hold still. But it looks like the vertices are messed up somehow.

-seph

---

<div class="post-metadata">

**Author:** ![seph](https://avatars.discourse-cdn.com/v4/letter/s/87869e/32.png) [@seph](https://discourse.libcinder.org/u/seph)\
**Post date:** [January 3, 2017, 6:31pm UTC](https://discourse.libcinder.org/t/gldrawarrays-question/472/4 "2017-01-03T18:31:27Z")

</div>

Ah I think I figured out why.  
It looks like glDrawArrays does take the startIndex correctly but when it write into the feedback buffer it begins with 0. So in this case since I started by offsetting 2 rings then eventually all the rings will be shifted to the position of the first 2 rings.

So I guess then my question would be, is there a way to do transform feedback with only a portion of the points in the buffer?
