2
\$\begingroup\$

Say, I send 10 polygon pairs (one polygon pair == one 2d sprite == one rectangle == two triangles) into OpenGL ES 2.0 VBO. The 10 polygon pairs represent one animated 2D object consisting of 10 frames.

The 10 frames, of course, can not be rendered all at the same time, but will be rendered in particular order to make up smooth animation.

Would you have an advice, how to pick up proper polygon pair for rendering (4 vertices) inside Vertex Shader from the VBO? Creating separate VBO for each frame would end up with thousands of VBOs, which is not the right way of doing it.

I use OpenGL ES 2.0, and VBOs for both Vertices and Indices.

\$\endgroup\$

2 Answers 2

4
\$\begingroup\$

If you use glDrawElements, you should be able to define offset. If you have bound indeces with glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, indices), last parameter in glDrawElements is just offset. So you can start from anywhere and stop after few indeces (second parameter - count).

\$\endgroup\$
3
  • \$\begingroup\$ @zaharmarz: hi and +1. That is great advice. I will take closer look at the last parameter of glDrawElements(). I am curious, do you think, there is a way on how to contoll VBO polygons directly from the Vertex Shader? \$\endgroup\$ Feb 17, 2011 at 20:00
  • \$\begingroup\$ I am marking this one as the Accepted Answer. I have tested it, and it works well for me. Thank you. \$\endgroup\$ Feb 17, 2011 at 22:59
  • \$\begingroup\$ I haven't try to control polygons directly from vertex shader. But I think it's not possible. Vertex program is executed on one processor, which has it's own registers (I think). It can't access global memory like CUDA. \$\endgroup\$
    – zacharmarz
    Feb 17, 2011 at 23:29
3
\$\begingroup\$

One approach is to use a shader to interpolate frames, so you get smooth animation and possibly less data.

Look at this question and its answers: interpolating frames in a vertex shader

\$\endgroup\$
1
  • \$\begingroup\$ +1 for valuable answer. Yeah, that would be a solution as well, if I do nto use one of the values like normal, uv, color... Meanwhile I already implemented Zacharmarz's solution, and it worked very well. Thank you :-) \$\endgroup\$ Feb 17, 2011 at 22:59

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .