glMatrixMode(GL_MODELVIEW); glLoadIdentity(); glTranslatef(0.0f, 0.0f, -5.0f); glPushMatrix(); glRotatef(45.0f, 0.0f, 1.0f, 0.0f); glTranslatef(2.0f, 0.0f, 0.0f); drawCube(); glPopMatrix();
void draw() { translate(30, 50); pushMatrix(); rotate(radians(45)); rect(0, 0, 100, 80); popMatrix(); rect(0, 0, 80, 100); }This example is written in Processing, a Java-based library that simplifies graphics programming. Here, we first translate the origin 30 units to the right and 50 units down. We then save this transformed state with pushMatrix(). We rotate the coordinate system by 45 degrees, draw a rectangle, and return to the previous transformation state with popMatrix(). Finally, we draw another rectangle at the origin. Package library: Processing libraries