meditec
02-25-2010, 03:44 AM
Hi,
i have several objects that need to be displayed. Lets say i have a racing car and a track drawn with pure opengl commands, some houses on the track loaded from STL files and maybe some more stuff. Now i'm looking for a viable and efficient way to display all these objects. If each object is an instance of a class (not necessarily the same class), i thought of using such a function called from my main loop:
void RenderWidget::paintGL()
{
car->render();
track->render();
house1->render();
house2->render();
}
where each object has a function called render() that draws it on its current location (the objects know their position in 3D space and transform themselves accordingly).
Is this approach viable? also, this solution works only if all objects are known at compile-time. What should i do if the number of objects may vary during runtime (more cars and houses for example)? Should i use function pointers in a loop?
thanks in advance.
i have several objects that need to be displayed. Lets say i have a racing car and a track drawn with pure opengl commands, some houses on the track loaded from STL files and maybe some more stuff. Now i'm looking for a viable and efficient way to display all these objects. If each object is an instance of a class (not necessarily the same class), i thought of using such a function called from my main loop:
void RenderWidget::paintGL()
{
car->render();
track->render();
house1->render();
house2->render();
}
where each object has a function called render() that draws it on its current location (the objects know their position in 3D space and transform themselves accordingly).
Is this approach viable? also, this solution works only if all objects are known at compile-time. What should i do if the number of objects may vary during runtime (more cars and houses for example)? Should i use function pointers in a loop?
thanks in advance.