Search code examples
c++openglopenscenegraph

Why does the camera not remain child of the other camera after adding it in osg?


I am writing an OpenSceneGraph based program that uses two cameras, one to render the preview for the user and one that uses a callback to make screenshots with MRT. The exporter camera is using an orthographic projection and always from the same position with the same view and up vector, whereas the preview camera can be moved by the usere.

Upon starting the program, I create the preview camera, add the shaders to it, then set up the viewer and add the preview camera to it.

Afterwards I create the export camera, add its shaders, textures and callback and then I add the export camera as a child to the preview camera. Up to this point, nothing has been rendered (i.e. no frame call has been made).

The addChild call is issued (i.e. the break point is reached in VS, and stepping further I can see that the exporter camera is now a child of the preview camera). However, once I issue a command to actually make a screenshot, the exporter camera is not the child of the preview camera anymore (by now, a few render calls have been made).

Why is this, and how can I fix it apart from adding the exporter camera again?


On a sidenote: I started using computergraphics.stackexchange.com, would this question be suited for that side or is it meant for the algorithms rather than the implementations?


Solution

  • If you're using osg::View, it has its own implementation for master and slave cameras - see the osg::View headers for information or this old tutorial for an example: http://thermalpixel.github.io/osg/2014/02/15/rtt-with-slave-cameras.html