From: Vadim Zeitlin Date: Mon, 9 Apr 2007 23:03:54 +0000 (+0000) Subject: fix the sample to work under X11 (where a context can't be made current before the... X-Git-Url: https://git.saurik.com/wxWidgets.git/commitdiff_plain/b94d29a7a10638783fc7092d33af6315bb7c3e59 fix the sample to work under X11 (where a context can't be made current before the window is realized) git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@45370 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- diff --git a/samples/opengl/cube/cube.cpp b/samples/opengl/cube/cube.cpp index 8bf22a199a..b5f5ba419e 100644 --- a/samples/opengl/cube/cube.cpp +++ b/samples/opengl/cube/cube.cpp @@ -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 */ diff --git a/samples/opengl/cube/cube.h b/samples/opengl/cube/cube.h index 9b2c7ac63d..56e6899fc7 100644 --- a/samples/opengl/cube/cube.h +++ b/samples/opengl/cube/cube.h @@ -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