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

Matthias Asselborn matthias.asselborn at gmx.de
Fri Apr 15 15:46:47 PDT 2011


i want to render a loaded scene into an image. 
i dont want to see any viewer windows. 

I have tried to realize it with osg::Viewer, but after the call 
viewer->frame a viewer window poped up. 

Now ive tried it with osgUtils::SceneViewer
but after the draw call - the program crashes

whats wrong? 


osg::ref_ptr<osg::Image> shot = new osg::Image(); 
shot->allocateImage( 800, 600, 1, GL_RGB, GL_UNSIGNED_BYTE ); 
osg::ref_ptr<osg::Node> subgraph = m_pNode.get(); 
osg::ref_ptr<osg::Camera> camera = new osg::Camera; 
osg::ref_ptr<osg::Camera> oldcamera = m_pViewer->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, 800, 600 ); 

//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 : 
m_pViewer->setSceneData( camera.get() ); 

//Make it frame: 


// in draw call the software crashes 

osgDB::writeImageFile( *shot, "C:/tools/test.bmp" ); 

The crash appers in 
RenderStage.cpp Line 1146 - trunk 


    if (_graphicsContext.valid() && _graphicsContext != callingContext)
        // show we release the context so that others can use it?? will do so right
        // now as an experiment.

Thank you!


Read this topic online here:

More information about the osg-users mailing list