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.
wxGLCanvas cleared when the window is resized Topic is solved
wxGLCanvas cleared when the window is resized
Last edited by TriKri on Thu Feb 24, 2011 11:03 am, edited 2 times in total.
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?
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?evstevemd wrote:Working fine here with Ubuntu/wx29 GCC 4.4.3
The important difference is catching the EVT_ERASE_BACKGROUND event and using an empty event handler to avoid drawing the background color.
Alternatively, calling SetBackgroundStyle(wxBG_STYLE_CUSTOM) in the glcanvas ctor should do the same.
Code: Select all
void TestGLCanvas::OnEraseBackground(wxEraseEvent& WXUNUSED(event))
{
// Do nothing, to avoid flashing on MSW
}
Use the source, Luke!
Thanks, both methods worked perfect!doublemax wrote:The important difference is catching the EVT_ERASE_BACKGROUND event and using an empty event handler to avoid drawing the background color.
Alternatively, calling SetBackgroundStyle(wxBG_STYLE_CUSTOM) in the glcanvas ctor should do the same.Code: Select all
void TestGLCanvas::OnEraseBackground(wxEraseEvent& WXUNUSED(event)) { // Do nothing, to avoid flashing on MSW }
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.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?
Use the source, Luke!