]>
git.saurik.com Git - wxWidgets.git/blob - utils/glcanvas/samples/cube/cube.cpp
97ec64dbf5b87f32df03e3ead82bac3fff1eca90
   1 ///////////////////////////////////////////////////////////////////////////// 
   3 // Purpose:     wxGLCanvas demo program 
   4 // Author:      Julian Smart 
   8 // Copyright:   (c) Julian Smart 
   9 // Licence:     wxWindows licence 
  10 ///////////////////////////////////////////////////////////////////////////// 
  13 #pragma implementation 
  17 // For compilers that support precompilation, includes "wx.h". 
  18 #include "wx/wxprec.h" 
  32 // This statement initializes the whole application and calls OnInit 
  37 // `Main program' equivalent, creating windows and returning main app frame 
  38 bool MyApp::OnInit(void) 
  40   wxLog::SetTraceMask(wxTraceMessages
); 
  42   // Create the main frame window 
  43   MyFrame 
*frame 
= new MyFrame(NULL
, "Cube OpenGL Demo", wxPoint(50, 50), wxSize(400, 300)); 
  47   frame
->SetIcon(wxIcon("mondrian")); 
  51   wxMenu 
*fileMenu 
= new wxMenu
; 
  53   fileMenu
->Append(wxID_EXIT
, "E&xit"); 
  54   wxMenuBar 
*menuBar 
= new wxMenuBar
; 
  55   menuBar
->Append(fileMenu
, "&File"); 
  56   frame
->SetMenuBar(menuBar
); 
  58   frame
->m_canvas 
= new TestGLCanvas(frame
, -1, wxPoint(0, 0), wxSize(200, 200)); 
  68 void MyApp::InitGL(void) 
  70     /* set viewing projection */ 
  71     glMatrixMode(GL_PROJECTION
); 
  72     glFrustum(-0.5F
, 0.5F
, -0.5F
, 0.5F
, 1.0F
, 3.0F
); 
  75     glMatrixMode(GL_MODELVIEW
); 
  76     glTranslatef(0.0F
, 0.0F
, -2.0F
); 
  79     glRotatef(30.0F
, 1.0F
, 0.0F
, 0.0F
); 
  80     glRotatef(30.0F
, 0.0F
, 1.0F
, 0.0F
); 
  82     glEnable(GL_DEPTH_TEST
); 
  83     glEnable(GL_LIGHTING
); 
  87 BEGIN_EVENT_TABLE(MyFrame
, wxFrame
) 
  88     EVT_MENU(wxID_EXIT
, MyFrame::OnExit
) 
  91 // My frame constructor 
  92 MyFrame::MyFrame(wxFrame 
*frame
, const wxString
& title
, const wxPoint
& pos
, 
  93     const wxSize
& size
, long style
): 
  94   wxFrame(frame
, -1, title
, pos
, size
, style
) 
  99 // Intercept menu commands 
 100 void MyFrame::OnExit(wxCommandEvent
& event
) 
 105 bool MyFrame::OnClose(void) 
 110 BEGIN_EVENT_TABLE(TestGLCanvas
, wxGLCanvas
) 
 111     EVT_SIZE(TestGLCanvas::OnSize
) 
 112     EVT_PAINT(TestGLCanvas::OnPaint
) 
 113     EVT_ERASE_BACKGROUND(TestGLCanvas::OnEraseBackground
) 
 116 TestGLCanvas::TestGLCanvas(wxWindow 
*parent
, wxWindowID id
, 
 117     const wxPoint
& pos
, const wxSize
& size
, long style
, const wxString
& name
): 
 118   wxGLCanvas(parent
, id
, pos
, size
, style
, name
) 
 122 TestGLCanvas::~TestGLCanvas(void) 
 126 void TestGLCanvas::OnPaint( wxPaintEvent
& event 
) 
 133     /* clear color and depth buffers */ 
 134     glClear(GL_COLOR_BUFFER_BIT 
| GL_DEPTH_BUFFER_BIT
); 
 136     /* draw six faces of a cube */ 
 138     glNormal3f( 0.0F
, 0.0F
, 1.0F
); 
 139     glVertex3f( 0.5F
, 0.5F
, 0.5F
); glVertex3f(-0.5F
, 0.5F
, 0.5F
); 
 140     glVertex3f(-0.5F
,-0.5F
, 0.5F
); glVertex3f( 0.5F
,-0.5F
, 0.5F
); 
 142     glNormal3f( 0.0F
, 0.0F
,-1.0F
); 
 143     glVertex3f(-0.5F
,-0.5F
,-0.5F
); glVertex3f(-0.5F
, 0.5F
,-0.5F
); 
 144     glVertex3f( 0.5F
, 0.5F
,-0.5F
); glVertex3f( 0.5F
,-0.5F
,-0.5F
); 
 146     glNormal3f( 0.0F
, 1.0F
, 0.0F
); 
 147     glVertex3f( 0.5F
, 0.5F
, 0.5F
); glVertex3f( 0.5F
, 0.5F
,-0.5F
); 
 148     glVertex3f(-0.5F
, 0.5F
,-0.5F
); glVertex3f(-0.5F
, 0.5F
, 0.5F
); 
 150     glNormal3f( 0.0F
,-1.0F
, 0.0F
); 
 151     glVertex3f(-0.5F
,-0.5F
,-0.5F
); glVertex3f( 0.5F
,-0.5F
,-0.5F
); 
 152     glVertex3f( 0.5F
,-0.5F
, 0.5F
); glVertex3f(-0.5F
,-0.5F
, 0.5F
); 
 154     glNormal3f( 1.0F
, 0.0F
, 0.0F
); 
 155     glVertex3f( 0.5F
, 0.5F
, 0.5F
); glVertex3f( 0.5F
,-0.5F
, 0.5F
); 
 156     glVertex3f( 0.5F
,-0.5F
,-0.5F
); glVertex3f( 0.5F
, 0.5F
,-0.5F
); 
 158     glNormal3f(-1.0F
, 0.0F
, 0.0F
); 
 159     glVertex3f(-0.5F
,-0.5F
,-0.5F
); glVertex3f(-0.5F
,-0.5F
, 0.5F
); 
 160     glVertex3f(-0.5F
, 0.5F
, 0.5F
); glVertex3f(-0.5F
, 0.5F
,-0.5F
); 
 166 void TestGLCanvas::OnSize(wxSizeEvent
& event
) 
 169     GetClientSize(& width
, & height
); 
 172         glViewport(0, 0, width
, height
); 
 175 void TestGLCanvas::OnEraseBackground(wxEraseEvent
& event
) 
 177     // Do nothing, to avoid flashing.