From e601bb9cc36d011d6a50892b6d74954a178be5cb Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Mon, 14 Jun 2010 15:25:05 +0000 Subject: [PATCH] From Wang Rui, "For a long time, the osgviewerMFC example uses addSlave() to setup the graphics context and link it with a slave camera. I don't know the reason we perform like that, which will cause a problem that the GUIEventHandler may not obtain correct window coordinates because the main camera will use a default input range to receive events from the slave camera's graphics context. It is also weird to see the addSlave() used in non-cluster applications, which beginners will be confused with. I've make a slightly modification to the osgviewerMFC example to make it work without setting slave cameras. I've tested with the MDI framework and everything seems fine." --- examples/osgviewerMFC/MFC_OSG.cpp | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/examples/osgviewerMFC/MFC_OSG.cpp b/examples/osgviewerMFC/MFC_OSG.cpp index aef0f8ac1..29fa7c561 100644 --- a/examples/osgviewerMFC/MFC_OSG.cpp +++ b/examples/osgviewerMFC/MFC_OSG.cpp @@ -105,8 +105,15 @@ void cOSG::InitCameraConfig(void) // Set the viewport for the Camera camera->setViewport(new osg::Viewport(traits->x, traits->y, traits->width, traits->height)); + // Set projection matrix and camera attribtues + camera->setClearMask(GL_DEPTH_BUFFER_BIT | GL_COLOR_BUFFER_BIT); + camera->setClearColor(osg::Vec4f(0.2f, 0.2f, 0.4f, 1.0f)); + camera->setProjectionMatrixAsPerspective( + 30.0f, static_cast(traits->width)/static_cast(traits->height), 1.0, 1000.0); + // Add the Camera to the Viewer - mViewer->addSlave(camera.get()); + //mViewer->addSlave(camera.get()); + mViewer->setCamera(camera.get()); // Add the Camera Manipulator to the Viewer mViewer->setCameraManipulator(keyswitchManipulator.get()); @@ -118,10 +125,10 @@ void cOSG::InitCameraConfig(void) mViewer->realize(); // Correct aspect ratio - double fovy,aspectRatio,z1,z2; + /*double fovy,aspectRatio,z1,z2; mViewer->getCamera()->getProjectionMatrixAsPerspective(fovy,aspectRatio,z1,z2); aspectRatio=double(traits->width)/double(traits->height); - mViewer->getCamera()->setProjectionMatrixAsPerspective(fovy,aspectRatio,z1,z2); + mViewer->getCamera()->setProjectionMatrixAsPerspective(fovy,aspectRatio,z1,z2);*/ } void cOSG::PreFrameUpdate()