Hi Bob

I have used such a design in wxWidgets. I guess you could adopt the
same strategy for MFC.

I have an instance of osgViewer::CompositeViewer in a global
singleton. When I need a 3D view:
- I create a canvas (in your case, an MFC window that derives from or
has a osg::GraphicsContext).
- I also create a specialized osgViewer::View and I bind this view to
the viewer (through CompositeViewer::addView() and
View::getCamera()->setGraphicsContext()).
- Then I add the scene to the view.

Now each time the application requests a redraw of the window (i.e. in
the WM_PAINT handler), I call CompositeViewer::frame(). This renders a
single, static frame and displays it in the window. When I want to
refresh the content, I call wxWindow::Refresh() which in turns calls
back the CompositeViewer::frame() method. In MFC, you'll do something
like
win->InvalidateRect(NULL,FALSE); // invalidate the entire window
win->UpdateWindow(); // redraw now

To handle continuous updates and redraw requests from within the scene
graph, you should override the osgViewer::View's methods:
                void requestRedraw();
                void requestContinuousUpdate(bool needed=true);
                void requestWarpPointer(float x,float y);

requestRedraw() will typically call the refresh code above
requestContinuousUpdate() can set up a timer which fires at regular
intervals (or an idle time handler) and call the refresh code
continuously
I do not use requestWarpPointer().

This way, when the user throws the model with the
osgGA::TrackballManipulator, your scene will be rendered continuously
- the user will still be able to manipulate the GUI. When the user
stops the model, rendering stops as well.

About threading: I could not manage to get my app to work properly in
non SingleThreaded models, so I never have to call
{start/stop}Threading(). I don't know if it makes sense to use other
threading models with a static application anyway.

Hope this helps

Thibault


On Mon, Apr 6, 2009 at 9:51 PM, Bob Youmans <[email protected]> wrote:
> Thanks for the very helpful guidance you provide…
>
>
>
> In the MFC example, I think the .run() method is already replaced by this:
>
>
>
>     //viewer->run();
>
>     while(!viewer->done())
>
>     {
>
>         osg->PreFrameUpdate();
>
>         viewer->frame();
>
>         osg->PostFrameUpdate();
>
> }
>
> I understand your suggestion about the details in the frame() call.  Here’s
> more detail about my intended use:
>
>
>
> For example, I want the user to be able to spin the model and look at it,
> but then click a start button and then (ignoring the user inputs)
> systematically traverse an axis between some values, and/or viewing angles,
> and then when finished, let the user look at it again (with the rendering
> details changed (color transparency, other textures, etc.).
>
>
>
> I was thinking I could stop the normal viewer threading that responds to
> user input and then drive it myself from another function.When finished I
> would restart the viewer to respond to user input.  There’s probably a
> better way…
>
>
>
> Would I be better off using update traversals, animation stuff, or some
> other osg design I haven’t learned yet?
>
>
>
> How about osgPPU? What do you think of it?
>
>
>
> Thanks,
>
> bob
>
>
>
> From: [email protected]
> [mailto:[email protected]] On Behalf Of Robert
> Osfield
> Sent: Monday, April 06, 2009 2:37 PM
> To: OpenSceneGraph Users
> Subject: Re: [osg-users] start/stop viewer
>
>
>
> Hi Bob,
>
> The viewer only renders a frame when you call viewer.frame().  If you are
> calling the convenience function viewer.run() then just replace this run
> call with the constuent parts of Viewer::run() i.e.
>
> while(!viewer.done())
> {
>    viewer.advance();
>    viewer.eventTraversal();
>    viewer.updateTraversal();
>    viewer.renderingTraversals();
> }
>
> Robert.
>
> On Mon, Apr 6, 2009 at 6:56 PM, Bob Youmans <[email protected]> wrote:
>
> Hello osg-list,
>
>
>
> I’d like to find the best way to adapt osg::viewer to control its
> rendering:  in one case I want the usual case where viewer->run is doing its
> thing at 60 fps.  But, then, I have other GUI windows (MFC-based) and I want
> to stop the viewer, and then render a single frame, all using the same
> geometry.  What’s the best approach for such a design?  Can I (using the
> examples for MFC) call viewer->stopThreads and then “manually” render a
> single frame, and then call  run, startThreads, etc. subsequently, and
> repeat this as often as I like?
>
>
>
> Thanks,
>
> Bob
>
> _______________________________________________
> osg-users mailing list
> [email protected]
> http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
>
>
>
> _______________________________________________
> osg-users mailing list
> [email protected]
> http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
>
>
_______________________________________________
osg-users mailing list
[email protected]
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org

Reply via email to