Hello Bart,

I must be missing something obvious I guess, but for me it isn't obvious (yet).

Not quite obvious, I would say, but something you could have found out by using the debugger or looking at the OSG code for the functions you're calling. Both are tools you should learn to use when you develop with third-party libraries, especially open source ones like OSG.

You don't need to create a new camera. In fact, in creating a new camera and replacing the view's camera with yours AFTER the view->setUpViewOnSingleScreen(x) line, you're effectively destroying the graphics context that the setUpView...() function created for you. And your own camera has no graphics context, so you see a black screen.

When you create an osgViewer::View, it creates an osg::Camera for you, with appropriate settings. When you call view->setUpView...(), it creates a graphics context and sets it on the view's camera. Creating your own camera and setting it on the view basically voids all that work that was done for you.

So just remove the lines:

  osg::Camera* camera = new osg::Camera;
  ...
  view->setCamera(camera);

for both your views, and whenever you used the camera variable, use view->getCamera() instead.

I'm not sure why you say that just setting a manipulator on the view did not give a black screen. Running your code with the setCameraManipulator(Tman) line uncommented, I still get a black screen in the second view, as I would expect. The camera manipulator is not related to the graphics context in any way, it only acts on the camera's view matrix. If the camera doesn't have a graphics context, you'll get a black screen whether you have a camera manipulator or not.

What will make a difference is using viewer.run() instead of while !viewer.done()) viewer.frame(); . The former is a shortcut for doing quick demos. It will do a few things for you, including setting a camera manipulator and creating a graphics context that spans all your screens. So this might have led you to believe that the two were related, but they're not. It's just that viewer.run() does these two things for you... But if you don't want to use a camera manipulator, you don't want viewer.run() anyways.

This kind of thing could be seen in a debugger by the way. By setting a breakpoint when you create your views, you could have seen that the view already had a camera as soon as it was created, then that the setUpView...() function had set a graphics context on that camera, and then when you assigned your own camera you could have seen that it had no graphics context.

Finally, for future reference, if you want someone to actually compile and run your code, it's much more helpful to include a complete file, with all necessary headers etc that you know compiles, rather than copy and paste some code (even if it's almost complete). It just provides a lower barrier for people to help you easily... For example, here's a source file ready to be compiled that shows what I'm talking about above. You should see the cow on both screens. (note I've commented out checking the arguments for -2, so I can test without any command line arguments, again make it easy for people to help you...)

Hope this helps,

J-S
--
______________________________________________________
Jean-Sebastien Guay    jean-sebastien.g...@cm-labs.com
                               http://www.cm-labs.com/
                        http://whitestar02.webhop.org/
#include <osgDB/ReadFile>
#include <osg/Group>
#include <osgViewer/CompositeViewer>
#include <osgViewer/View>
#include <osgGA/TrackballManipulator>

int main(int argc, char** argv)
{
    osg::ArgumentParser arguments(&argc, argv);

    osg::Group* scene = new osg::Group();
        osg::Node* groundNode = NULL;
        osg::Node* tankNode = NULL;
        groundNode = osgDB::readNodeFile("cow.osg");

        scene->addChild(groundNode);
        osgGA::TrackballManipulator* Tman = new osgGA::TrackballManipulator;
    
        // construct the viewer.
    osgViewer::CompositeViewer viewer(arguments);

                        
    //if (arguments.read("-2"))
    {

        // view one
        {
        
                        //osg::Camera* camera = new osg::Camera;            // 
don't create a new camera
            osgViewer::View* view = new osgViewer::View;
            osg::Camera* camera = view->getCamera();            // use the 
view's existing camera instead.
            view->setName("View one");
            viewer.addView(view);

            view->setUpViewOnSingleScreen(0);
            view->setSceneData(scene);

            // Get the scene bounding sphere
                        osg::BoundingSphere bsph = scene->getBound();

            // Look at the center of the scene
            osg::Vec3 lookAt = bsph.center();

            // Place eye at an appropriate distance 'south' of the look-at point
            osg::Vec3 eyef = lookAt + osg::Vec3(0,-1,0) * bsph.radius() * 3.5f;

            // Set camera view matrix
            camera->setViewMatrixAsLookAt(eyef, lookAt, osg::Vec3(0,0,1)); 
            //view->setCamera(camera);
        }

        // view two
        {
                        //osg::Camera* camera = new osg::Camera;            // 
don't create a new camera
            osgViewer::View* view = new osgViewer::View;
            osg::Camera* camera = view->getCamera();            // use the 
view's existing camera instead.
            view->setName("View two");
            viewer.addView(view);

            view->setUpViewOnSingleScreen(1);
            view->setSceneData(scene);

            // Get the scene bounding sphere
                        osg::BoundingSphere bsph = scene->getBound();

            // Look at the center of the scene
            osg::Vec3 lookAt = bsph.center();

            // Place eye at an appropriate distance 'south' of the look-at point
            osg::Vec3 eyef = lookAt + osg::Vec3(0,-1,0) * bsph.radius() * 1.5f;

            // Set camera view matrix
            camera->setViewMatrixAsLookAt(eyef, lookAt, osg::Vec3(0,0,1)); 
            //view->setCamera(camera);
            //view->setCameraManipulator(Tman);
        }
    }

        viewer.realize(); 


        while(!viewer.done())
        {
                viewer.frame();
        }
}
_______________________________________________
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org

Reply via email to