[osg-users] Question about idle event handling in the wxWidgets example

YH Zhang asmwarrior at gmail.com
Thu Oct 3 02:41:43 PDT 2019


Hi, in the \examples\osgviewerWX\osgviewerWX.cpp

I see such code snippet


Code:

void MainFrame::OnIdle(wxIdleEvent &event)
{
    if (!_viewer->isRealized())
        return;

    _viewer->frame();

    event.RequestMore();
}




This makes the frame() function call runs continuously.

I just change the code by those steps:

1, first, I comment out all the codes in the "void MainFrame::OnIdle(wxIdleEvent &event)", and this means the OnIdle just do nothing.

2, second, I add some code snippet to some event handling function like:


Code:


void OSGCanvas::OnMouseWheel(wxMouseEvent &event)
{
    int delta = event.GetWheelRotation() / event.GetWheelDelta() * event.GetLinesPerAction();

    if (_graphics_window.valid()) {
        _graphics_window->getEventQueue()->mouseScroll(
            delta>0 ?
            osgGA::GUIEventAdapter::SCROLL_UP :
            osgGA::GUIEventAdapter::SCROLL_DOWN);
    }

    // those code were added by me, which force a refresh of the view
    MainFrame * f = (MainFrame *)GetParent();

    if (!f->_viewer->isRealized())
        return;

    f->_viewer->frame();

}





My question is: My thought was remove the idle event handling, because it waste some CPU resource to refresh the opengl window again and again. My change is try to only update the view when some true event happens. Any ideas?

Thank you!

------------------
Read this topic online here:
http://forum.openscenegraph.org/viewtopic.php?p=76774#76774







More information about the osg-users mailing list