Hi all,
I have an application where I use an osg::viewer for a single viewport of a
model. The camera for the viewer is created like this:
------------------------------
// Init a new Camera (Master for this View)
camera = mViewer->getCamera();
// Assign Graphics Context to the Camera
camera->setGraphicsContext(gc);
// Set the viewport for the Camera
camera->setViewport(new osg::Viewport(traits->x, traits->y, traits->width,
traits->height));
// Add the Camera to the Viewer
mViewer->setCamera(camera.get());
-------------------------------
I have created a function which will be used to both take high-res screenshots
of the main viewport and to make renderings from other cameras defined in the
model (not osg::camera's, just a camera class defining a camera view). I wanted
to do this by creating a new osg::camera on the fly and disabling to main
viewer camera in order to not have the viewport redrawn while making a
rendering/screenshot. If I do not disable the viewer-camera by using
setnodemask, the following code works but the contents of the main viewport
disappear until the next normal frame() is called, which causes some naste
blinking of the viewport, when recording video from it. When I use setnodemask
to try to disable the viewer camera, I just get a uniform grey osg::Image. I'm
somewhat new to OSG, so it is probably some simple error. The source code for
my screenshot/rendering function can be found below.
System data: Viste 64, OSG 2.6.1, Visual Studio 2005 sp1.
bool CModelView::CreateOSGImageSnap(int p_width, int p_height, double p_left,
double p_right,
double p_bottom, double p_top, double p_near, double p_far,
double p_eye_pivot_0, double p_eye_pivot_1, double p_eye_pivot_2,
double p_eye_eulerpar_0, double p_eye_eulerpar_1, double p_eye_eulerpar_2,
double p_eye_eulerpar_3, double p_eye_dist, bool p_ortho, osg::Image* p_image)
{
osg::ref_ptr<osg::Camera> t_camera = new osg::Camera;
osg::ref_ptr<osg::Group> t_parent = new osg::Group;
unsigned int t_samples = 0;
unsigned int t_colorSamples = 0;
t_camera->setViewport(0,0,p_width,p_height);
if(p_ortho){
t_camera->setProjectionMatrixAsOrtho(p_left,p_right,p_bottom,p_top,p_near,p_far);
}else{
t_camera->setProjectionMatrixAsFrustum(p_left,p_right,p_bottom,p_top,p_near,p_far);
}
osg::Matrixd t_matrix =
osg::Matrixd::translate(-(osg::Vec3d(p_eye_pivot_0,p_eye_pivot_1,p_eye_pivot_2)))*
osg::Matrixd::rotate((osg::Quat(p_eye_eulerpar_1,p_eye_eulerpar_2,p_eye_eulerpar_3,p_eye_eulerpar_0)).inverse())*
osg::Matrixd::translate(0.0,0.0,-p_eye_dist);
t_camera->setViewMatrix(t_matrix);
t_camera->setRenderOrder(osg::Camera::PRE_RENDER);
t_camera->setRenderTargetImplementation(osg::Camera::FRAME_BUFFER_OBJECT);
t_camera->setReferenceFrame(osg::Transform::ABSOLUTE_RF);
t_camera->setClearColor(
osg::Vec4(GetBackgroundColor()[0],GetBackgroundColor()[1],GetBackgroundColor()[2],1.0)
);
p_image->allocateImage(p_width, p_height, 1, GL_RGBA, GL_UNSIGNED_BYTE);
t_camera->attach(osg::Camera::COLOR_BUFFER, p_image, t_samples, t_colorSamples);
t_camera->setPostDrawCallback(new MyCameraPostDrawCallback(p_image));
osg::Node* t_oldroot = mOSG->getASG()->getOSGRoot();
t_camera->addChild(mOSG->getASG()->getOSGRoot());
t_parent->addChild(t_camera.get());
mOSG->getViewer()->setSceneData(t_parent.get());
mOSG->getViewer()->getCamera()->setNodeMask(0x0);
mOSG->getViewer()->frame();
//bool s_test = osgDB::writeImageFile(*p_image, "screenshot.bmp");
mOSG->getViewer()->setSceneData(t_oldroot);
mOSG->getViewer()->getCamera()->setNodeMask(0xffffffff);
return true; //Fixme: This should be changed to a bool describing whether the
snapshot was successful.
};
Regards, and thanks in advance.
Jesper D. Thomsen
_______________________________________________
osg-users mailing list
[email protected]
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org