Figure 9: Class CMyGraph

// File MyGraph.h

class CMyGraph : public COpenGLCtrls
{
    int RotationX,RotationY;   // Rotation around axes

  public: 

    CMyGraph();

    // Overridden COpenGLCtrls virtual functions to draw scene
    virtual void OnCreateRC();
    virtual void OnRender();
    virtual void OnViewing();
    virtual void OnViewport(int cx, int cy);
    virtual void OnProjection(GLdouble AspectRatio);
  
    //... MFC message handlers and message map
};

// File MyGraph.cpp

#include "stdafx.h"
#include "oglctrl.h" 
#include "MyGraph.h"

CMyGraph::CMyGraph()
         :RotationX(0),RotationY(0)
{
}

void CMyGraph::OnCreateRC()
{
    glClearColor(0.0f,0.0f,0.0f,0.0f);
    glClearDepth(1.0f);
    glEnable(GL_DEPTH_TEST);
}

void CMyGraph::OnRender()
{
    // Rotate the model
    glRotatef((GLfloat)RotationY,0.0f,1.0f,0.0f);
    glRotatef((GLfloat)RotationX,1.0f,0.0f,0.0f);
    
    // Draw the color pyramid
    glBegin(GL_TRIANGLE_FAN);
       glColor3f(1.0f,1.0f,1.0f);
       glVertex3f(0.0f,1.0f,0.0f);
       glColor3f(1.0f,0.0f,0.0f);
       glVertex3f(-1.0f,0.0f,0.0f);
       glColor3f(1.0f,1.0f,0.0f);
       glVertex3f(0.0f,0.0f,1.0f);
       glColor3f(0.0f,1.0f,0.0f);
       glVertex3f(1.0f,0.0f,0.0f);
       glColor3f(0.0f,0.0f,1.0f);
       glVertex3f(0.0f,0.0f,-1.0f);
       glColor3f(1.0f,0.0f,0.0f);
       glVertex3f(-1.0f,0.0f,0.0f);
    glEnd();

    // Show a sphere (if it works...)
    auxWireSphere(1);
}

void CMyGraph::OnViewport(int cx, int cy)
{
    glViewport(0,0,cx,cy);
}

void CMyGraph::OnViewing()
{
    gluLookAt(2,2,2,0,0,0,0,1,0);
}

void CMyGraph::OnProjection(GLdouble AspectRatio)
{
    gluPerspective(45,AspectRatio,1,10);
}

//... Mouse handlers rotate the model
//End of File