I'm playing with OSG activeX example and trying to make screenshot of current scene, but I get black screenshot.
the Viewer initiation is the following:
Code:
_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 );
The part of the code which grabs screenshot is the following:
Code:
osgViewer::ScreenCaptureHandler* scrn = new osgViewer::ScreenCaptureHandler();
osgViewer::ScreenCaptureHandler::WriteToFile* captureOper = new osgViewer::ScreenCaptureHandler::WriteToFile(tmpStr.m_szBuffer, "png");
scrn->setCaptureOperation(captureOper);
scrn->captureNextFrame(*_viewer);
_viewer->frame();
I think I need to take screenshot from GraphicContext instead of viewer, but I have no idea how to do it.
Can you please help?
Thank you!
Cheers,
Danny
------------------
Read this topic online here:
http://forum.openscenegraph.org/viewtopic.php?p=22850#22850
_______________________________________________
osg-users mailing list
osg-...@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
Does anybody have any clue? how to solve this problem?
Thank you!
Cheers,
Danny
------------------
Read this topic online here:
http://forum.openscenegraph.org/viewtopic.php?p=22922#22922
jp
--
This message is subject to the CSIR's copyright terms and conditions, e-mail legal notice, and implemented Open Document Format (ODF) standard.
The full disclaimer details can be found at http://www.csir.co.za/disclaimer.html.
This message has been scanned for viruses and dangerous content by MailScanner,
and is believed to be clean. MailScanner thanks Transtec Computers for their support.
I tried the following code
Code:
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" );
but still black image. How can I solve the issue.
Thank you!
Cheers,
Danny
------------------
Read this topic online here:
http://forum.openscenegraph.org/viewtopic.php?p=23033#23033
try attach before frame. I'm not sure why you want to call frame
yourself, is this part of a larger app?
jp
--
This message is subject to the CSIR's copyright terms and conditions, e-mail legal notice, and implemented Open Document Format (ODF) standard.
The full disclaimer details can be found at http://www.csir.co.za/disclaimer.html.
This message has been scanned for viruses and dangerous content by MailScanner,
and is believed to be clean. MailScanner thanks Transtec Computers for their support.
_______________________________________________
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
// 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
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
camera->attach(osg::Camera::COLOR_BUFFER, NULL);
Gives me
Error C2668: 'osg::Camera::attach' : ambiguous call to overloaded function
If I replace it with:
camera->attach(osg::Camera::COLOR_BUFFER, shot.get());
I still get black image.
What might be the problem?
Thank you!
Cheers,
Danny
------------------
Read this topic online here:
http://forum.openscenegraph.org/viewtopic.php?p=23064#23064