[osg-users] Rendering a scene to texture

Robert Osfield robert.osfield at gmail.com
Sun Mar 18 13:19:49 PDT 2018


HI Jochen,

On 18 March 2018 at 18:08, Jochen Maier <franke.jochen at gmx.de> wrote:
> I know that the way is to realize this is using different cameras and render to texture. But I don't know how to initiate the rendering-process; I only know this by calling Viewer::frame(). I thought there is another way.

Viewer::frame() kicks update, event and renderingTraverls(), the later
does the cull traversal (works out what data needs to be drawn in this
frame) and draw dispatch traversal (send data to OpenGL)


> btw:
> I was thinking a little bit of this and my idea was:
> There are different scene-roots (osg::group). Add all my scene childs to each osg::group.
> Now I set for the RTT the sceneData which I want to render to texture (osgViewer::setSceneData(sceneToRenderToTexture)) and the camera which renders to texture and call osgViewer::frame().
> Done!! I have a texture wich shows my scene (sceneToRenderToTexture).
>
> Is this an option to solve my problem?

It's difficult to work exactly what you mean from this description.
As I don't understand what you mean I can't say whether it's a
sensible approach or not.

As a general note, the design of the OSG RTT system using osg::Camera
and osgViewer provides all the power and flexibility you need to do
what you need to do, there shouldn't be any need to add an extra
complexity into the main loop, just configure the scene graph or
viewer to do the rendering you need to do and just call viewer.run()
or frame() within a frame loop and everything should just work.

If you only want to update a subset of the RTT Camera's per frame you
can toggle them on/off by setting their NodeMask to 0x0 (for off) and
0xffffffff (for on).  If you are using RTT Camera's in the scene graph
you can also using osg::Switch nodes to toggle thins on/off or use
your own custom cull callback above the RTT Camera's to decide whether
they should be traversed or not.

There is so much power and flexibility in this system you are best to
spend the time understanding the examples to see all the different
ways osg::Camera can be used.  Just do a search for osg::Camera in the
whole OSG code base and you'll see it popping up in lots of places for
various different purposes.

Robert.


More information about the osg-users mailing list