Page 1 of 1

wxGLCanvas cleared when the window is resized

Posted: Thu Feb 24, 2011 2:04 am
by TriKri
Hi, I followed this minimal wxGLCanvas sample, and just replaced the code in the 'minimal' sample project that comes with wxWidgets, and got it to compile directly. However, when I'm resizing the window, the image that is rendered in the window is totally cleared until I have stopped resizing it (the image is replaced by the light gray color that is the base color of many windows applications). Why does this happen and how can I modify the code in the example I linked to in order to not get the artifact?

Edit: I'm running Windows 7, using wxWidgets 2.8.11 and compiling with Visual Studio 2008.

Posted: Thu Feb 24, 2011 5:52 am
by evstevemd
Working fine here with Ubuntu/wx29 GCC 4.4.3

Posted: Thu Feb 24, 2011 11:13 am
by TriKri
On the other hand, the penguin OpenGL example project that comes with wxWidgets, does not expose this artifact. I have tried to figure out what they differs in that example, but I'm not really sure. One thing I noticed is that it has the wxGLCanvas inside of a wxFrame that in turn is inside a wxApp, while in the example I linked to the wxGLCanvas is directly inside the wxApp. Another thing is that in the latter, a wxGLContext is explicitly declared, while in the penguin example it's not, but a request is made for the associated context everytime it's needed. Can anything of this be the cause of the artifact?

Posted: Thu Feb 24, 2011 12:24 pm
by TriKri
evstevemd wrote:Working fine here with Ubuntu/wx29 GCC 4.4.3
Could you try to switch place on "wxFrame *frame;" and "BasicGLPane * glPane;" in the definition of MyApp? Maybe the canvas is drawn on the frame when refreshing the window for you, while the frame is drawn on the canvas for me by some reason?

Posted: Thu Feb 24, 2011 1:58 pm
by doublemax
The important difference is catching the EVT_ERASE_BACKGROUND event and using an empty event handler to avoid drawing the background color.

Code: Select all

void TestGLCanvas::OnEraseBackground(wxEraseEvent& WXUNUSED(event))
{
    // Do nothing, to avoid flashing on MSW
}
Alternatively, calling SetBackgroundStyle(wxBG_STYLE_CUSTOM) in the glcanvas ctor should do the same.

Posted: Thu Feb 24, 2011 3:05 pm
by TriKri
doublemax wrote:The important difference is catching the EVT_ERASE_BACKGROUND event and using an empty event handler to avoid drawing the background color.

Code: Select all

void TestGLCanvas::OnEraseBackground(wxEraseEvent& WXUNUSED(event))
{
    // Do nothing, to avoid flashing on MSW
}
Alternatively, calling SetBackgroundStyle(wxBG_STYLE_CUSTOM) in the glcanvas ctor should do the same.
Thanks, both methods worked perfect!

By the way, which is to prefer; to have the wxGLCanvas if the wxFrame which in turn is in the wxApp, or having both the canvas and the frame in the app? Or isn't there any difference?

Posted: Thu Feb 24, 2011 3:24 pm
by doublemax
By the way, which is to prefer; to have the wxGLCanvas if the wxFrame which in turn is in the wxApp, or having both the canvas and the frame in the app? Or isn't there any difference?
When you look at it closely, you'll notice that in both cases the glcanvas is a child of the frame, which is all that matters here. Just the location where the glcanvas is created is different.