I was wondering how basic animation is done in OpenGL. In my code I currently insert all vertices for 2 shapes in a VBO. Then I select certain vertices ( shape’s 1 vertices for example and change their “x” position by +1). Then I re-draw the image. Is this the correct way and idea of manipulating multiple object’s position in Opengl?
Share
The answer is it depends on what your vertices represent. If you need to deform the model they represent, then yes you have to modify their coordinates. However, if the model retains its shape, you can use the modelview matrix to move the object.
If you currently use 1 draw call with the vertices of multiple shapes that move independently, this means you will have to make instead 1 draw call per shape with different modelview matrices.
This approach can slow down your rendering however depending on what you draw. If you have many simple shapes that move independently (e.g. a particle system), you will get poor performance by performing many draw calls and your approach is better. A potentially even better one (and more advanced), if it applies to your case, is to use the vertex shader to move the vertices according to a mathematical formula.
There are many other factors that affect rendering time, but small rendering batch size is high on the list.
I suggest you take a look at the OpenGL red book chapter 3 for more info on matrices. The rest of the book is getting out of date with shaders and VBOs, but that part is good in my opinion.