]> git.saurik.com Git - wxWidgets.git/commitdiff
fix the sample to work under X11 (where a context can't be made current before the...
authorVadim Zeitlin <vadim@wxwidgets.org>
Mon, 9 Apr 2007 23:03:54 +0000 (23:03 +0000)
committerVadim Zeitlin <vadim@wxwidgets.org>
Mon, 9 Apr 2007 23:03:54 +0000 (23:03 +0000)
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@45370 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775

samples/opengl/cube/cube.cpp
samples/opengl/cube/cube.h

index 8bf22a199a0d7f063ddb5b8bc0bb54771af30c5c..b5f5ba419e1dfc45a62c0b6dc9f71df53bbfa80e 100644 (file)
@@ -92,7 +92,10 @@ static /* const */ int attribs[] = { WX_GL_RGBA, WX_GL_DOUBLEBUFFER, 0 };
 TestGLCanvas::TestGLCanvas(wxWindow *parent)
             : wxGLCanvas(parent, wxID_ANY, attribs)
 {
-    InitGL();
+    m_gllist = 0;
+
+    // notice that we can't call InitGL() from here: we must wait until the
+    // window is shown on screen to be able to perform OpenGL calls
 }
 
 // this function is called on each repaint so it should be fast
@@ -109,13 +112,22 @@ void TestGLCanvas::Render()
 
 void TestGLCanvas::OnPaint(wxPaintEvent& WXUNUSED(event))
 {
+    // initialize if not done yet
+    InitGL();
+
     wxPaintDC dc(this);
 
     Render();
 }
 
-void TestGLCanvas::OnSize(wxSizeEvent& WXUNUSED(event))
+void TestGLCanvas::OnSize(wxSizeEvent& event)
 {
+    // don't prevent default processing from taking place
+    event.Skip();
+
+    if ( !IsInitialized() )
+        return;
+
     // set GL viewport (not called by wxGLCanvas::OnSize on all platforms...)
     int w, h;
     GetClientSize(&w, &h);
@@ -126,6 +138,9 @@ void TestGLCanvas::OnSize(wxSizeEvent& WXUNUSED(event))
 
 void TestGLCanvas::InitGL()
 {
+    if ( IsInitialized() )
+        return;
+
     wxGetApp().SetCurrent(this);
 
     /* set viewing projection */
index 9b2c7ac63d2248250d4124715fe4ce6f187e15bd..56e6899fc7056861bf161562abdef3a2d77781ad 100644 (file)
@@ -61,7 +61,10 @@ public:
     void OnKeyDown(wxKeyEvent& event);
 
 private:
-    // one-time OpenGL initialization
+    // OpenGL calls can't be done until we're initialized
+    bool IsInitialized() const { return m_gllist != 0; }
+
+    // one-time OpenGL initialization, only does something if !IsInitialized()
     void InitGL();
 
     // render to window