VBO and transformation matrix


Ive been playing around with VBO for few days, and so far, I can use it to draw objects. There is one question that I havent found answer for. What if I want to display, lets say, two boxes (A and B), but each one has different transformation matrix.
Should I do following steps, or is there any other, better method?

2.Create transformation matrix for A
3.compute new coordiates for each point that A consists of.
4.load newly computed cordinates into VBO buffer
6.Do the same for box B
7.Draw scene

Boxes are defined like this:
class Point{
GLfloat x, y, z;

class Box{
Point points[8];
Glfloat dx, dy, dz; //displacements
Glfloat angle_x, angle_y, angle_z; //rotation

There is another question, should I declare one global VBO that keeps coordinates of each point of A and B, or should I make local VBO for each box?

You don’t need to recompute the coordinates when using an object->world transformation matrix (also called model matrix).

You’re right in using the matrix stack and defining a different model matrix for each object. What you don’t need to do is to recompute the coordinates and then upload it to the vertex buffer - unless of course you want to transform the object from object space to world space in a pre-process.

The usual way to achieve what you desire is:

I) Create VBOs A and B and upload object space data
II) Enter render loop
a) Set View Matrix
b) PushMatrix for Object A
c) Set Model Matrix for Object A
d) Render Object A (glDrawArrays/glDrawElements)
e) PopMatrix
f) PushMatrix for Object B
g/h) similar
i) PopMatrix
j) Swap Buffers

As for your second question, in this case it really doesn’t matter. If you up the object count to hundreds or thousands, using one vertex buffer for each object, no matter how small, will result in equally numerous buffer binding and draw calls which can be quite detrimental to performance.

Also, allocating bigger vertex buffers may lead to faster rendering speed due to better coherence. You can check the wiki for more: http://www.opengl.org/wiki/Main_Page

Thanks for your answer, it helped a lot.