X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/b94d29a7a10638783fc7092d33af6315bb7c3e59..26ee65c723cf55822c540506f064ec11d9b26858:/samples/opengl/cube/cube.cpp diff --git a/samples/opengl/cube/cube.cpp b/samples/opengl/cube/cube.cpp index b5f5ba419e..4b549dc05c 100644 --- a/samples/opengl/cube/cube.cpp +++ b/samples/opengl/cube/cube.cpp @@ -87,10 +87,10 @@ BEGIN_EVENT_TABLE(TestGLCanvas, wxGLCanvas) EVT_KEY_DOWN(TestGLCanvas::OnKeyDown) END_EVENT_TABLE() -static /* const */ int attribs[] = { WX_GL_RGBA, WX_GL_DOUBLEBUFFER, 0 }; +static const int attribs[] = { WX_GL_RGBA, WX_GL_DOUBLEBUFFER, 0 }; TestGLCanvas::TestGLCanvas(wxWindow *parent) - : wxGLCanvas(parent, wxID_ANY, attribs) + : wxGLCanvas(parent, wxID_ANY, NULL /* attribs */) { m_gllist = 0; @@ -101,8 +101,6 @@ TestGLCanvas::TestGLCanvas(wxWindow *parent) // this function is called on each repaint so it should be fast void TestGLCanvas::Render() { - wxGetApp().SetCurrent(this); - glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glCallList(m_gllist); @@ -112,6 +110,8 @@ void TestGLCanvas::Render() void TestGLCanvas::OnPaint(wxPaintEvent& WXUNUSED(event)) { + wxGetApp().SetCurrent(this); + // initialize if not done yet InitGL(); @@ -141,8 +141,6 @@ void TestGLCanvas::InitGL() if ( IsInitialized() ) return; - wxGetApp().SetCurrent(this); - /* set viewing projection */ glMatrixMode(GL_PROJECTION); glLoadIdentity(); @@ -243,7 +241,8 @@ void TestGLCanvas::OnKeyDown( wxKeyEvent& event ) i != wxTopLevelWindows.end(); ++i ) { - (*i)->Refresh(false); + MyFrame *frame = (MyFrame *)*i; + frame->RefreshCanvas(); } } @@ -252,8 +251,8 @@ void TestGLCanvas::OnKeyDown( wxKeyEvent& event ) // ---------------------------------------------------------------------------- BEGIN_EVENT_TABLE(MyFrame, wxFrame) - EVT_MENU(wxID_EXIT, MyFrame::OnExit) EVT_MENU(wxID_NEW, MyFrame::OnNewWindow) + EVT_MENU(wxID_CLOSE, MyFrame::OnClose) END_EVENT_TABLE() MyFrame::MyFrame() @@ -265,18 +264,21 @@ MyFrame::MyFrame() SetIcon(wxICON(sample)); // Make a menubar - wxMenu *winMenu = new wxMenu; - winMenu->Append(wxID_EXIT, _T("&Close")); - winMenu->Append(wxID_NEW, _T("&New") ); + wxMenu *menu = new wxMenu; + menu->Append(wxID_NEW); + menu->AppendSeparator(); + menu->Append(wxID_CLOSE); wxMenuBar *menuBar = new wxMenuBar; - menuBar->Append(winMenu, _T("&Window")); + menuBar->Append(menu, _T("&Cube")); SetMenuBar(menuBar); + CreateStatusBar(); + Show(); } -void MyFrame::OnExit( wxCommandEvent& WXUNUSED(event) ) +void MyFrame::OnClose(wxCommandEvent& WXUNUSED(event)) { // true is to force the frame to close Close(true); @@ -287,3 +289,7 @@ void MyFrame::OnNewWindow( wxCommandEvent& WXUNUSED(event) ) (void) new MyFrame(); } +void MyFrame::RefreshCanvas() +{ + m_canvas->Refresh(false); +}