Open GL Matrix Stack
← OpenGL Legacy API | ● | Scene Graph To OpenGL →
Supposed we have a procedure drawObject() that renders a particular object.
To render multiple objects of the same type with different transformations we use the matrix stack via glPushMatrix() and glPopMatrix():
glTranslatef(-10,0,0);
glRotatef(90,0,1,0);
drawObject();
glPopMatrix();
glPushMatrix();
glTranslatef(10,0,0);
glRotatef(-90,0,1,0);
drawObject();
glPopMatrix();
The glPushMatrix command saves the actual transformation state. Later on the state can be restored with glPopMatrix().
With the matrix stack we can construct objects hierarchically from parts which in turn can be made up from sub-parts and so on.
{
glPushMatrix();
glTranslatef(-1,0,0);
drawPart();
glPopMatrix();
glPushMatrix();
glTranslatef(1,0,0);
drawPart();
glPopMatrix();
}
void drawPart()
{
glBegin();
...
glEnd();
}
This is called hierarchical modeling. Here, the scene corresponds to a graph with parent-child relationships between the objects and their respective parts. This graph is called the scene graph.
← OpenGL Legacy API | ● | Scene Graph To OpenGL →