Thansk for your help. Yes, you are rigth, the problem was in the interaction between the wxwidgets main loop and the gl context.
For the Pd-dev list:
The solution is to write an Idle function, I made the following changes:
//on WxApp class
void MyApp::activateRenderLoop(bool on) {
if(on && !render_loop_on) {
Connect(wxID_ANY, wxEVT_IDLE, wxIdleEventHandler(MyApp::onIdle));
render_loop_on = true;
}
else if (!on && render_loop_on) {
Disconnect(wxEVT_IDLE, wxIdleEventHandler(MyApp::onIdle));
render_loop_on = false;
}
}
void MyApp::onIdle(wxIdleEvent &evt) {
activateRenderLoop(glPane->render_on);
if(render_loop_on) {
std::cout<<"MyApp on Idle, render_loop_on"<<std::endl;
glPane->paint_now();
evt.RequestMore();
}
}
//on event table:
EVT_PAINT(BasicGLPane::paint_rt)
//on WxGLCanvas class
void BasicGLPane::rightClick(wxMouseEvent& event) {
render_on = true;
manager->init();
SLEEP(2000);
manager->play();
wxGetApp().activateRenderLoop(true);
}
void BasicGLPane::paint_rt(wxPaintEvent &evt) {
wxPaintDC dc(this);
render_rt(dc);
}
void BasicGLPane::paint_now(){
wxClientDC dc(this);
std::cout<<"paint now() "<<std::endl;
render_rt(dc);
}
void BasicGLPane::render_rt(wxDC &dc) {
wxGLCanvas::SetCurrent(*m_context);
if(_object->getCounter()>=10) {
wxGetApp().activateRenderLoop(false);
manager->stop();
render_on = false;
}
else {
ctx = CGLGetCurrentContext();
err = CGLEnable( ctx, kCGLCEMPEngine);
std::cout<<"render_rt CGLError: "<<err<<std::endl;
if (err==0) {
glTranslatef(p3->x, p3->y, 0);
Refresh(false);
}
}
}