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
This commit is contained in:
@@ -92,7 +92,10 @@ static /* const */ int attribs[] = { WX_GL_RGBA, WX_GL_DOUBLEBUFFER, 0 };
|
|||||||
TestGLCanvas::TestGLCanvas(wxWindow *parent)
|
TestGLCanvas::TestGLCanvas(wxWindow *parent)
|
||||||
: wxGLCanvas(parent, wxID_ANY, attribs)
|
: 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
|
// 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))
|
void TestGLCanvas::OnPaint(wxPaintEvent& WXUNUSED(event))
|
||||||
{
|
{
|
||||||
|
// initialize if not done yet
|
||||||
|
InitGL();
|
||||||
|
|
||||||
wxPaintDC dc(this);
|
wxPaintDC dc(this);
|
||||||
|
|
||||||
Render();
|
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...)
|
// set GL viewport (not called by wxGLCanvas::OnSize on all platforms...)
|
||||||
int w, h;
|
int w, h;
|
||||||
GetClientSize(&w, &h);
|
GetClientSize(&w, &h);
|
||||||
@@ -126,6 +138,9 @@ void TestGLCanvas::OnSize(wxSizeEvent& WXUNUSED(event))
|
|||||||
|
|
||||||
void TestGLCanvas::InitGL()
|
void TestGLCanvas::InitGL()
|
||||||
{
|
{
|
||||||
|
if ( IsInitialized() )
|
||||||
|
return;
|
||||||
|
|
||||||
wxGetApp().SetCurrent(this);
|
wxGetApp().SetCurrent(this);
|
||||||
|
|
||||||
/* set viewing projection */
|
/* set viewing projection */
|
||||||
|
@@ -61,7 +61,10 @@ public:
|
|||||||
void OnKeyDown(wxKeyEvent& event);
|
void OnKeyDown(wxKeyEvent& event);
|
||||||
|
|
||||||
private:
|
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();
|
void InitGL();
|
||||||
|
|
||||||
// render to window
|
// render to window
|
||||||
|
Reference in New Issue
Block a user