After searching and reading about Modern OpenGL in order to upgrade my existing project, I\'m a bit confused, since my 3D framework based on OpenGL 2.1.
so, as far a
If your rendering already happens hierarchically using, for example, function recursion then you already have matrix stack!
void renderMesh(Matrix transform, Mesh mesh)
{
// here call glDrawElements/glDrawArrays and send transform matrix to MVP uniform
mesh->draw(transform);
// now render all the sub-meshes, then will be transformed relative to current mesh
for (int i=0; isubMeshCount(); i++)
{
Matrix subMeshTransform = mesh->getSubMeshTransform(i);
Mesh subMesh = mesh->getSubMesh();
renderMesh(subMeshTransform * transform, subMesh);
}
}
// somwhere in main function
...
Matrix projection = Matrix::perspective(...);
Matrix view = camera->getViewMatrix();
Matrix transform = view * projectIon;
renderMesh(transform, rootMesh);