Programming and Graphics

(Kiana) #1

8.1 Glut 261


glRotatef(30, 0.0, 0.0, 1.0); // rotate by 30 deg about the z axis

//--- Paint three faces:

glColor3f(1.0, 0.0, 1.0);
glBegin(GLQUADSTRIP);
glVertex3d(3, 3, -3);
glVertex3d(3, -3, -3);
glVertex3d(-3, 3, -3);
glVertex3d(-3, -3, -3);
glVertex3d(-3, 3, 3);
glVertex3d(-3, -3, 3);
glVertex3d(3, 3, 3);
glVertex3d(3, -3, 3);
glEnd();

glColor3f(1.0, 1.0, 0.0); // Paint the individual faces
glBegin(GLQUADS);
glVertex3d(-3, 3, 3);
glVertex3d(-3, -3, 3);
glVertex3d(3, -3, 3);
glVertex3d(3, 3, 3);
glEnd();
glColor3f(0.0, 0.0, 1.0);
glBegin(GLQUADS);
glVertex3d(-3, -3, -3);
glVertex3d(3, -3, -3);
glVertex3d(3, -3, 3);
glVertex3d(-3, -3, 3);
glEnd();
glColor3f(0.0, 1.0, 1.0);
glBegin(GLQUADS);
glVertex3d(-3, 3, -3);
glVertex3d(3, 3, -3);
glVertex3d(3, 3, 3);
glVertex3d(-3, 3, 3);
glEnd();
glColor3f(0.2, 1.0, 0.0);
glBegin(GLQUADS);
glVertex3d(3, 3, -3);
glVertex3d(3, -3, -3);
glVertex3d(-3,-3, -3);
glVertex3d(-3, 3, -3);
glEnd();
glFlush();
}

The faces of the cube were painted with different colors using theglColor3f
function.

Free download pdf