
glBegin(GL_TRIANGLES);
glVertex3f(-3.0, –3.0, 2.0);
glVertex3f(3.0, –3.0, –1.0);
glVertex3f(0.0, 3.0, 4.0);
glEnd();
See? Nothing to it!
Now, lets take what we've learned so far and draw some 3D using OpenGL. As you can see, the following program bears more than a passing resemblence to the previous one (GLUT is so nice that way), with some changes to the display() function. One thing you will notice is that I change the current color with glColor before specifiying some of the vertices. When OpenGL sees a polygon with vertices that have different colors, it draws the figure by smoothly shading from one color to the next. In this example I've created an abstract shape made out of one square surrounded by four triangles. One point of the triangles is red, while the other two are blue. This creates a smoothing purple effect across the face of the triangle.
I'm also using this example to demonstrate some of the UI routines that GLUT uses. In this case we are going to be using the function glutKeyboardFunc(). This function defines a callback handler that will be called whenever a key is pressed while our window has focus.
/**********************************************************************/
/******************************************/
/* Example 2: Drawing in 3D */
/******************************************/
