Setting OpenGL context in the dtor of a wxGLCanvas derived class
Luca Cappa
luca.cappa at sequoia.it
Fri Sep 28 07:02:43 PDT 2007
Hello all,
I developed a wxGLCanvas derived class, which needs to execute some OpenGL
cleanup when it is destroyed. For this purpose I put this code in the
destructor of my class. The problem is that I cannot set the OpenGL
context as the current one if the wxGLCanvas's parent window is not shown:
in fact, a call to SetCurrent() will trigger an assert at line 549 of the
file glcanvas.cpp, whose code is shown here below:
void wxGLCanvas::SetCurrent(const wxGLContext& RC) const
{
// although on MSW it works even if the window is still hidden, it
doesn't
// under wxGTK and documentation mentions that SetCurrent() can only be
// called for a shown window, so check it
wxASSERT_MSG( GetParent()->IsShown(), _T("can't make hidden GL canvas
current") );
....
As the comment says, this problem arises only on a wxGTK platform. To
circumvent the assertion, since I am working on a MSW application, I set
the GL context using this code instead:
GLCanvasDerivedClass::~GLCanvasDerivedClass ()
{
getGLContext ()->SetCurrent (*this);
....
}
where getGLContext()'s return type is wxGLContext* .
Since this is more an hack and since it will not work (perhaps, i have not
tryed it yet) on wxGTK, I am asking if someone could tell me a more
sensible way to set the OGL context in the window's destructor. Or maybe
someone could tell me how to organize my clean up differently.
TIA,
Luca
More information about the wx-users
mailing list