Hi,

I´m using an osg::camera to take a screenshot in high-res.

To have it as easy as possible, I just copy the original scene-View-camera. See code below.

Just one problem and one question:
- after taking the picture, my viewport is set to the 2500 pixels. Why is the original camera modified? Shouldn´t i use the copy-constructor here? - is there a way to figure out the maximum-resolution I can use for a screenshot?

Apart from this this works well, and the render-to-image of osg::Camera is very convenient!

Regards,

Andreas

//save the old viewport:
osg::ref_ptr<osg::Viewport> AlterViewport = sceneView->getViewport();
osg::ref_ptr<osg::Image> shot = new osg::Image();
//shot->setPixelFormat(GL_RGB);

int w = 0; int h = 0;
GetClientSize(&w, &h);
float ratio = (float)w/(float)h;
w = 2500;
h = (int)((float)w/ratio);
//shot->scaleImage(w, h, 24);
shot->allocateImage(w, h, 24, GL_RGB, GL_UNSIGNED_BYTE);
osg::Node* subgraph = TheDocument->RootGroup.get();

osg::ref_ptr<osg::Camera> camera = new osg::Camera(*(sceneView->getCamera()) );

// set view
camera->setReferenceFrame(osg::Transform::ABSOLUTE_RF);

// set viewport
camera->setViewport(0,0,w,h);

// set the camera to render before the main camera.
camera->setRenderOrder(osg::Camera::PRE_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);
//Need to mage it part of the scene :
sceneView->setSceneData(camera);

//Make it frame:
Update();
Refresh();

wxImage img;
img.Create(w, h);
img.SetData(shot->data());
shot.release();

wxImage i2 = img.Mirror(false);
i2.SaveFile(filename);
sceneView->setSceneData(subgraph);
sceneView->setViewport(AlterViewport.get() );

return true;



_______________________________________________
osg-users mailing list
[email protected]
http://openscenegraph.net/mailman/listinfo/osg-users
http://www.openscenegraph.org/

Reply via email to