[osg-users] Render To Image Crash in RenderStage.cpp - trunk

Matthias Asselborn matthias.asselborn at gmx.de
Sat Apr 16 16:49:49 PDT 2011


nobody an idea?

i tried another thing, but there is no sceneobject on the image
ive also tried the osgscreencapture example
is there a way to get rid of the callback? 
i need only one screenshot


Code:


void render()
{
	osgUtil::SceneView *SceneView = new osgUtil::SceneView;
	SceneView->setDefaults();

	osg::ref_ptr<osg::Node> pNode = osgDB::readNodeFile( "C:/cessna.osg" );
	SceneView->setSceneData( pNode );

	osg::ref_ptr<osg::Camera> pCameraNode = new osg::Camera;

	const osg::BoundingSphere& bs = pNode->getBound();
	int r = bs.radius();
	pCameraNode->setProjectionMatrixAsOrtho2D( -r, r, -r, r );
	pCameraNode->setViewMatrixAsLookAt( osg::Vec3( r*100,-r*100, r*100 ) , osg::Vec3(bs.center()[0], bs.center()[1], bs.center()[2] ),osg::Vec3(0.0f,0.0f,1.0f));

	osg::ref_ptr<osg::Image> pImage = new osg::Image;
	
	const osg::Viewport* Viewport = SceneView->getViewport();

	int Width = 1024;
	int Height = 768;

	pImage->allocateImage(Width, Height, 1, GL_RGB, GL_UNSIGNED_BYTE);

	pCameraNode->setClearColor(SceneView->getClearColor());
	pCameraNode->setViewport(0, 0, Width, Height);
	//pCameraNode->setRenderOrder(osg::Camera::POST_RENDER);
	pCameraNode->setRenderOrder(osg::Camera::PRE_RENDER);
	pCameraNode->setRenderTargetImplementation(osg::Camera::FRAME_BUFFER_OBJECT, osg::Camera::FRAME_BUFFER);
	//pCameraNode->setRenderTargetImplementation( osg::CameraNode::PIXEL_BUFFER );
	pCameraNode->setComputeNearFarMode(osg::Camera::DO_NOT_COMPUTE_NEAR_FAR);
	pCameraNode->setReferenceFrame(osg::Camera::ABSOLUTE_RF);
	pCameraNode->setProjectionMatrix(SceneView->getProjectionMatrix());
	pCameraNode->setViewMatrix(SceneView->getViewMatrix());
	pCameraNode->attach( osg::Camera::COLOR_BUFFER, pImage.get());

	pCameraNode->addChild(pNode);
	SceneView->setSceneData(pCameraNode.get());

	SceneView->update();
	SceneView->cull();
	SceneView->draw();

	osgDB::writeImageFile(*pImage, "c:/tools/test.png");
}




------------------
Read this topic online here:
http://forum.openscenegraph.org/viewtopic.php?p=38527#38527








More information about the osg-users mailing list