Figure 4: A sample function that draws a shaded pyramid

// Rendering function from sample
// application Renders a shaded pyramid
// By G. Bavestrelli, 
// Copyright Techint S.p.A. 1999

void CMyGraph::OnRender()
{
    // Rotate the model
    glRotatef((GLfloat)RotationY,
       0.0f,1.0f,0.0f);
    glRotatef((GLfloat)RotationX,
       1.0f,0.0f,0.0f);

    // Specify my four points with 
    // template classes
    GLpoint4<GLfloat> P0(0.0F,1.0F,0.0F);
    GLpoint4<GLfloat> P1(0.0F,0.0F,-1.0F);
    GLpoint4<GLfloat> P2(1.0F,0.0F,0.0F);
    GLpoint4<GLfloat> P3(0.0F,0.0F,1.0F);
    GLpoint4<GLfloat> P4(-1.0F,0.0F,0.0F);
    
    // Draw the pyramid, with its normals
    glBegin(GL_TRIANGLES);
    
       glNormal3fv((P0-P1)*(P1-P2)); 
       glVertex3fv(P0);
       glVertex3fv(P1);
       glVertex3fv(P2);

       glNormal3fv((P0-P2)*(P2-P3)); 
       glVertex3fv(P0);
       glVertex3fv(P2);
       glVertex3fv(P3);

       glNormal3fv((P0-P3)*(P3-P4)); 
       glVertex3fv(P0);
       glVertex3fv(P3);
       glVertex3fv(P4);

       glNormal3fv((P0-P4)*(P4-P1)); 
       glVertex3fv(P0);
       glVertex3fv(P4);
       glVertex3fv(P1);

    glEnd();
}