[PD-dev] Fwd: Synchronizing OpenGL with libpd (with RtAudio or Port Audio)

0222445 Luis.Valdivia at stud.sbg.ac.at
Fri Feb 19 02:03:54 CET 2016


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);
        }

    }
}
and the synchronisation works now.
Regards.
Luis

2016-02-18 3:15 GMT+01:00 Dan Wilcox <danomatika at gmail.com>:

> That shouldn’t make a difference, but you could try it. People haven’t had
> problems with OpenGL + libpd using ofxPd in open frameworks, so it may be
> due to how the wx widget mainloop & gl context interact.
>
> --------
> Dan Wilcox
> @danomatika <https://twitter.com/danomatika>
> danomatika.com
> robotcowboy.com
>
> On Feb 17, 2016, at 7:12 PM, 0222445 <Luis.Valdivia at stud.sbg.ac.at> wrote:
>
> There is no context error in the OpenGL draw now (solved with the call
> wxGLCanvas::SetCurrent(*m_context) but the draw still doesn't works (the
> object is moved after the manager->stop() and not during the execution) . I
> still think RtAudio is owning the CPU and blocking the execution of other
> threads or process. It will be better to do it with PortAudio?
>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.puredata.info/pipermail/pd-dev/attachments/20160219/ea8e574c/attachment.html>


More information about the Pd-dev mailing list