X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/6a1120ad4cc05520f989449ffc953a217782af72..56b9c74101566aa241d1846a148d3a01980b7431:/utils/glcanvas/samples/cube/cube.cpp diff --git a/utils/glcanvas/samples/cube/cube.cpp b/utils/glcanvas/samples/cube/cube.cpp index 97ec64dbf5..6b4fc01e6e 100644 --- a/utils/glcanvas/samples/cube/cube.cpp +++ b/utils/glcanvas/samples/cube/cube.cpp @@ -29,11 +29,6 @@ #include "cube.h" -// This statement initializes the whole application and calls OnInit -MyApp myApp; - -IMPLEMENT_APP(MyApp) - // `Main program' equivalent, creating windows and returning main app frame bool MyApp::OnInit(void) { @@ -57,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) @@ -117,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) @@ -125,11 +102,23 @@ TestGLCanvas::~TestGLCanvas(void) void TestGLCanvas::OnPaint( wxPaintEvent& event ) { - if ( !GetContext() ) - return; + // This is a dummy, to avoid an endless succession of paint messages. + // OnPaint handlers must always create a wxPaintDC. + wxPaintDC dc(this); + +#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); @@ -168,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) @@ -177,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); +} +