X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/c2265822fec3d0fa383dc6e043cad1a12a0e8418..56b9c74101566aa241d1846a148d3a01980b7431:/utils/glcanvas/samples/cube/cube.cpp diff --git a/utils/glcanvas/samples/cube/cube.cpp b/utils/glcanvas/samples/cube/cube.cpp index 6a756b2893..6b4fc01e6e 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) @@ -114,6 +93,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 +106,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 +157,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 +171,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); +} +