X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/c2265822fec3d0fa383dc6e043cad1a12a0e8418..fed485e0946d9cff74fce6afdb169796d90a99f2:/utils/glcanvas/samples/cube/cube.cpp diff --git a/utils/glcanvas/samples/cube/cube.cpp b/utils/glcanvas/samples/cube/cube.cpp index 6a756b2893..7a9735c98b 100644 --- a/utils/glcanvas/samples/cube/cube.cpp +++ b/utils/glcanvas/samples/cube/cube.cpp @@ -29,8 +29,6 @@ #include "cube.h" -IMPLEMENT_APP(MyApp) - // `Main program' equivalent, creating windows and returning main app frame bool MyApp::OnInit(void) { @@ -54,32 +52,13 @@ bool MyApp::OnInit(void) frame->m_canvas = new TestGLCanvas(frame, -1, wxPoint(0, 0), wxSize(200, 200)); - InitGL(); - // Show the frame frame->Show(TRUE); return TRUE; } -void MyApp::InitGL(void) -{ - /* set viewing projection */ - glMatrixMode(GL_PROJECTION); - glFrustum(-0.5F, 0.5F, -0.5F, 0.5F, 1.0F, 3.0F); - - /* position viewer */ - glMatrixMode(GL_MODELVIEW); - glTranslatef(0.0F, 0.0F, -2.0F); - - /* position object */ - glRotatef(30.0F, 1.0F, 0.0F, 0.0F); - glRotatef(30.0F, 0.0F, 1.0F, 0.0F); - - glEnable(GL_DEPTH_TEST); - glEnable(GL_LIGHTING); - glEnable(GL_LIGHT0); -} +IMPLEMENT_APP(MyApp) BEGIN_EVENT_TABLE(MyFrame, wxFrame) EVT_MENU(wxID_EXIT, MyFrame::OnExit) @@ -99,11 +78,6 @@ void MyFrame::OnExit(wxCommandEvent& event) Destroy(); } -bool MyFrame::OnClose(void) -{ - return TRUE; -} - BEGIN_EVENT_TABLE(TestGLCanvas, wxGLCanvas) EVT_SIZE(TestGLCanvas::OnSize) EVT_PAINT(TestGLCanvas::OnPaint) @@ -114,6 +88,7 @@ TestGLCanvas::TestGLCanvas(wxWindow *parent, wxWindowID id, const wxPoint& pos, const wxSize& size, long style, const wxString& name): wxGLCanvas(parent, id, pos, size, style, name) { + m_init = FALSE; } TestGLCanvas::~TestGLCanvas(void) @@ -126,11 +101,19 @@ void TestGLCanvas::OnPaint( wxPaintEvent& event ) // OnPaint handlers must always create a wxPaintDC. wxPaintDC dc(this); - if ( !GetContext() ) - return; +#ifndef __WXMOTIF__ + if (!GetContext()) return; +#endif SetCurrent(); + /* init OpenGL once, but after SetCurrent */ + if (!m_init) + { + InitGL(); + m_init = TRUE; + } + /* clear color and depth buffers */ glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); @@ -169,8 +152,13 @@ void TestGLCanvas::OnSize(wxSizeEvent& event) int width, height; GetClientSize(& width, & height); - if ( GetContext() ) +#ifndef __WXMOTIF__ + if (GetContext()) +#endif + { + SetCurrent(); glViewport(0, 0, width, height); + } } void TestGLCanvas::OnEraseBackground(wxEraseEvent& event) @@ -178,3 +166,22 @@ void TestGLCanvas::OnEraseBackground(wxEraseEvent& event) // Do nothing, to avoid flashing. } +void TestGLCanvas::InitGL(void) +{ + /* set viewing projection */ + glMatrixMode(GL_PROJECTION); + glFrustum(-0.5F, 0.5F, -0.5F, 0.5F, 1.0F, 3.0F); + + /* position viewer */ + glMatrixMode(GL_MODELVIEW); + glTranslatef(0.0F, 0.0F, -2.0F); + + /* position object */ + glRotatef(30.0F, 1.0F, 0.0F, 0.0F); + glRotatef(30.0F, 0.0F, 1.0F, 0.0F); + + glEnable(GL_DEPTH_TEST); + glEnable(GL_LIGHTING); + glEnable(GL_LIGHT0); +} +