Hi Danny,

you have to attach the image first and then draw the frame:

>       osg::ref_ptr<osg::Image> shot = new osg::Image();
>       shot->allocateImage(640, 480, 24, GL_RGB, GL_UNSIGNED_BYTE);
> osg::ref_ptr<osg::Camera> camera = _viewer->getCamera();
> camera->attach(osg::Camera::COLOR_BUFFER, shot.get());
> _viewer->frame();
> osgDB::writeImageFile(*shot, "test.png" );
> camera->attach(osg::Camera::COLOR_BUFFER, NULL);

The image is copied from the frame buffer at the end of the frame() call.

regards Ralph

Am 22.01.2010 13:30, schrieb Danny Lesnik:
> Hi,
> 
> This is activeX control and inside the contol I have a method which prints 
> screenshot. 
> 
> This is how I do initiate control AND all OSG instances:
> 
> 
> Code:
> 
>  int ViewerCtrl::OnCreate(LPCREATESTRUCT lpCreateStruct)
> {
>       if (COleControl::OnCreate(lpCreateStruct) == -1)
>               return -1;
> 
>       RECT rect;
>       GetWindowRect(&rect);
> 
>       WCHAR str[255];
>       swprintf(str, L"(%d,%d) - (%d,%d)", 
> rect.left,rect.top,rect.right,rect.bottom);
> 
>       // Set window traits and gc
>       _traits = new osg::GraphicsContext::Traits;
>       osg::ref_ptr<osg::Referenced> windata = new 
> osgViewer::GraphicsWindowWin32::WindowData( GetSafeHwnd() );
>       _traits->x = 0;
>       _traits->y = 0;
>       _traits->width = rect.right - rect.left;
>       _traits->height = rect.bottom - rect.top;
>       _traits->windowDecoration = false;
>       _traits->doubleBuffer = true;
>       _traits->sharedContext = 0;
>       _traits->setInheritedWindowPixelFormat = true;
>       _traits->inheritedWindowData = windata;
>       _gc = osg::GraphicsContext::createGraphicsContext( _traits.get() );
>       _gc->setClearColor( osg::Vec4f(0.2f, 0.2f, 0.6f, 1.0f) );
>       _gc->setClearMask( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
> 
>       // Create camera
>       osg::ref_ptr<osg::Camera> camera = new osg::Camera;
>       camera->setGraphicsContext(_gc);
>       camera->setViewport( new osg::Viewport(_traits->x, _traits->y, 
> _traits->width, _traits->height) );
>       camera->setProjectionMatrixAsPerspective( 30.0f, 
> (double)_traits->width/(double)_traits->height, 1.0f, 10000.0f );
>       camera->setClearMask( GL_DEPTH_BUFFER_BIT );
> 
>       // Create viewer
>       _viewer = new osgViewer::Viewer;
>       _viewer->setThreadingModel( osgViewer::Viewer::SingleThreaded );
>       _viewer->setCamera( camera.get() );
>       _viewer->setCameraManipulator( new osgGA::TrackballManipulator );
> 
>       // Set root node of the scene
>       _root = new osg::Group;
>       _viewer->setSceneData( _root.get() );
>       _viewer->realize();
> 
> WS_CHILD|WS_VISIBLE|BS_PUSHBUTTON, CRect(01, 1, 50, 50), this, 1000);
> 
>       // Create a thread for the simulation loop
>       _beginthread(&RenderThread, 0, _viewer); 
>       return 0;
> }
> 
> 
> 
> 
> and this is how do I take screenshot:
> 
> 
> Code:
> 
> VARIANT_BOOL ViewerCtrl::SaveScreenshot(LPCTSTR name)
> {
>       AFX_MANAGE_STATE(AfxGetStaticModuleState());
> 
>       CW2A tmpStr(name);
>       osg::ref_ptr<osg::Image> shot = new osg::Image();
>       shot->allocateImage(640, 480, 24, GL_RGB, GL_UNSIGNED_BYTE);
> osg::ref_ptr<osg::Camera> camera = _viewer->getCamera();
> _viewer->frame();
> camera->attach(osg::Camera::COLOR_BUFFER, shot.get()); 
> osgDB::writeImageFile(*shot, "test.png" );
> 
>       //osgViewer::ScreenCaptureHandler* scrn = new 
> osgViewer::ScreenCaptureHandler();
>       //osgViewer::ScreenCaptureHandler::WriteToFile* captureOper = new 
> osgViewer::ScreenCaptureHandler::WriteToFile(tmpStr.m_szBuffer, "png");
>       //scrn->setCaptureOperation(capt()ureOper);
>       //scrn->captureNextFrame(*_viewer); 
>       //_viewer->frame();
>       return VARIANT_TRUE;
> }
> 
> 
> 
> 
> so any clue or suggestion is welcomed.
> Thank you!
> 
> Cheers,
> Danny
> 
> ------------------
> Read this topic online here:
> http://forum.openscenegraph.org/viewtopic.php?p=23053#23053
> 
> 
> 
> 
> 


_______________________________________________
osg-users mailing list
[email protected]
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org

Reply via email to