Andreas Goebel schrieb:
Hi Robert,
just one more Question: I have a HUD-Node in my scenegraph. This
HUD-Node simply gets left out when rendering to the image with the
screenshot-camera.
Is there a switch to enable nested cameras?
Thanks for your help,
Andreas
Hi,
I have solved this by setting the HUD-Camera to "NESTED_RENDER" and
putting all geometries of the HUD-Node into the transparent bin.
So this is how it works:
I have a sceneView with scene-Data.
I remove the scene-Data from the sceneView, add it to a cameraNode and
then add this cameraNode to the sceneView.
Then I update the sceneView, the cameraNOde renders to the image, and
then I remove the camera Node again and put the sceneData into the
sceneView back again.
The trouble was: I wanted to save work by constructing the cameraNode
with the copy-Constructor starting with the original sceneView´s camera.
This was not a good idea, probably because the renderToImage could not
be set to Image after being constructed with the copyConstructor.
So anyone who would like to have a simple, high-res screenshot, here is
the complete source:
shot = new osg::Image();
//This is wxWidgets-Stuff to get the image ratio:
int w = 0; int h = 0;
GetClientSize(&w, &h);
int newSize = (int) wxGetNumberFromUser(_("Geben Sie die Breite des
Bildes in Pixeln an: "), _("Aufloesung:"), _("Aufloesung"), w, 300, 5000 );
if (newSize == -1)
return false;
float ratio = (float)w/(float)h;
w = newSize;
h = (int)((float)w/ratio);
shot->allocateImage(w, h, 24, GL_RGB, GL_UNSIGNED_BYTE);
osg::ref_ptr<osg::Node> subgraph = TheDocument->RootGroup.get();
osg::ref_ptr<osg::Camera> camera = new osg::Camera;
osg::ref_ptr<osg::Camera> oldcamera = sceneView->getCamera();
//Copy the settings from sceneView-camera to get exactly the view
the user sees at the moment:
camera->setClearColor(oldcamera->getClearColor() );
camera->setClearMask(oldcamera->getClearMask() );
camera->setColorMask(oldcamera->getColorMask() );
camera->setTransformOrder(oldcamera->getTransformOrder() );
camera->setProjectionMatrix(oldcamera->getProjectionMatrix() );
camera->setViewMatrix(oldcamera->getViewMatrix() );
// set view
camera->setReferenceFrame(osg::Transform::ABSOLUTE_RF);
// set viewport
camera->setViewport(0,0,w,h);
// set the camera to render before after the main camera.
camera->setRenderOrder(osg::Camera::POST_RENDER);
// tell the camera to use OpenGL frame buffer object where supported.
camera->setRenderTargetImplementation(osg::Camera::FRAME_BUFFER_OBJECT);
camera->attach(osg::Camera::COLOR_BUFFER, shot.get());
// add subgraph to render
camera->addChild(subgraph.get());
//camera->addChild(TheDocument->GetHUD().get() );
//Need to mage it part of the scene :
sceneView->setSceneData(camera.get());
//Make it frame:
sceneView->update();
sceneView->cull();
sceneView->draw();
//Write the image the wxWidgets-Way, which works better for me:
wxImage img;
img.Create(w, h);
img.SetData(shot->data());
//Damit der Destruktor des Image nicht meckert:
shot.release();
wxImage i2 = img.Mirror(false);
i2.SaveFile(filename);
//Reset the old data to the sceneView, so it doesn´t always render
to image:
sceneView->setSceneData(subgraph.get() );
//This would work, too:
//return osgDB::writeImageFile(*shot, filename.c_str() );
return true;
_______________________________________________
osg-users mailing list
[email protected]
http://openscenegraph.net/mailman/listinfo/osg-users
http://www.openscenegraph.org/