I'm learning OpenGL and there is something I don't understand regarding model loading.

Lets say I found a free .blend model of a tree. The problem is - currently in my program all models have only one texture. But this model use two textures, one for trunk and another for branches and leaves. Actually trunk and leaves are two separated models on one scene.

What to do in this situation? Editing model manually could take a long time (I'm not an expert in Blender). I could join two textures in one and correct UV's automatically. But most likely a lot of space will be wasted on such an automatically created texture. I could also modify my model format (it's more like memory dump + header actually) so I could store N models with N textures as one object. But using N times more VBOs and textures when you actually need only one is inefficient.

I'm wondering maybe there is a well known tool for automatically joining multiple objects in one? Or maybe some good practice for this case? Or something like this.


1 Answer 1


Actually trunk and leaves are two separated models on one scene.

Normally, when one model needs to be divided up like this into sub-parts or child models like that, the separate sub - objects become child nodes of the parent object in the transform hierarchy (or Scene graph), so that changes made to the parents world transformation are automatically applied to the child meshes. Such a hierarchy allows you to change the parent's position and orientation and stuff without worrying about the child meshes. Blender already stores its models in such an hierarchy.

To solve your trouble, you do not need to change how you store your models at all. All you need to change is how you render the objects in your scene.

You can load the trunk and branches as separate meshes with their own textures (preferably storing them in the same VBO as well, each starting at an offset, and using the offset while calling glDrawArrays ). Then after you load the meshes into memory, you can create a hierarchy of their transforms where the trunk is the parent node and the branches are the children. When you want to render the branches, you just need to multiply the local transform of the branches with their parent trunk's transform to get their final transformation matrix.

This way, you save yourself most of the work implementing a texture combiner or making a new format. You just need to design the transform hierarchy.

A nice resource that would help you implement such an hierarchy efficiently is this. It might help you get an idea.


You must log in to answer this question.

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