I want to render an object imported from wavefront obj file. The object has multiple groups and materials:
# group one
g one
v ...
vt ...
vn ...
# material A
usemtl ...
f ...
# material B
usemtl ...
f ..
# second group
g two
v ...
vt ...
vn ...
# material C
usemtl ...
f ...
# material D
usemtl ...
f ...
The different parts of the model need to be rendered separately, as they have different materials.
I will build a container with an information about the model and I would like to know what is the best/common way to organize the "queue" of the objects to render.
My idea, which I don't know if it's good is the following (with pseudocode): for each group g
store all vertex information in object VertexInformation g1, g2
and for each usemtl
store information about faces (and the used material) in FaceInformation f1, f2, f3, f4
.
Then the rendering would look as follows:
load vertices g1
render f1 f2
load vertices g2
render f3 f4
Or maybe better to load all the vertices from g1
and g2
at once?
Is that the way? Or it has some giant drawbacks?
I would to suggest you to declare the interface IModel and implement it in a different models like WavefrontModel so:
class IModel{
public:
virtual bool drawModel() =0;
};
class WavefrontModel : public IModel{
public:
bool drawModel();
};
I have an example for you here: http://code.google.com/p/gstmultimedialib/source/browse/#svn%2Ftrunk%2Fgstmultimedialib%2FGLEngine%2FGLEngine%2FModel
If you want you can get the glEngine module from this project.
After that implement your scene or device which will contain a list of your models.
class Device{
private:
std::list< IModel* > m_models;
public:
bool drawScene(); //iterate all of your models and call the draw method here.
};