wxGLCanvas cleared when the window is resized Topic is solved

Are you writing your own components and need help with how to set them up or have questions about the components you are deriving from ? Ask them here.
Post Reply
TriKri
Earned a small fee
Earned a small fee
Posts: 11
Joined: Thu Feb 24, 2011 1:46 am

wxGLCanvas cleared when the window is resized

Post 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.
Last edited by TriKri on Thu Feb 24, 2011 11:03 am, edited 2 times in total.
User avatar
evstevemd
Part Of The Furniture
Part Of The Furniture
Posts: 2409
Joined: Wed Jan 28, 2009 11:57 am
Location: United Republic of Tanzania

Post by evstevemd »

Working fine here with Ubuntu/wx29 GCC 4.4.3
Chief Justice: We have trouble dear citizens!
Citizens: What it is his honor?
Chief Justice:Our president is an atheist, who will he swear to?
TriKri
Earned a small fee
Earned a small fee
Posts: 11
Joined: Thu Feb 24, 2011 1:46 am

Post 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?
TriKri
Earned a small fee
Earned a small fee
Posts: 11
Joined: Thu Feb 24, 2011 1:46 am

Post 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?
User avatar
doublemax
Moderator
Moderator
Posts: 19158
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Post 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.
Use the source, Luke!
TriKri
Earned a small fee
Earned a small fee
Posts: 11
Joined: Thu Feb 24, 2011 1:46 am

Post 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?
User avatar
doublemax
Moderator
Moderator
Posts: 19158
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Post 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.
Use the source, Luke!
Post Reply