Hi,
I understand that people can't see the attachments and I put them in the
message body.
I just add some code demonstrating using OSG.
That is "OnCreate" code:
RECT rect;
GetWindowRect(&rect);
// 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;
try
{
_gc = osg::GraphicsContext::createGraphicsContext(
_traits.get() );
}
catch (...)
{
::MessageBox(0, L"... Exception", L"Hint", MB_OK);
}
_gc->setClearColor( osg::Vec4f(1.0f, 1.0f, 1.0f, 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 Screen Capture Handler
osgViewer::ScreenCaptureHandler::CaptureOperation* captureOperation =
new CustomCaptureOperation(_saveScreenshotEvent);
_scnsvr = new osgViewer::ScreenCaptureHandler(captureOperation);
// 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();
// Switch off the end signal of the viewer main loop
_viewer->setKeyEventSetsDone(0);
// Create doolloop logo
_root->addChild(createText(10, 672, 45, osg::Vec4f(0.878f, 0.832f,
0.492f, 1.0f), LogoFont, LogoText1));
_root->addChild(createText(102, 672, 45, osg::Vec4f(0.82f, 0.82f,
0.82f, 1.0f), LogoFont, LogoText2));
// Create the open/download progress text
_root->addChild(createText(10, 15, 26, osg::Vec4f(0.5f, 0.5f, 0.5f,
1.0f), LogoFont, _progressTextUpdateHandler));
// Create a thread for the simulation loop
_beginthread(&RenderThread, 0, _viewer);
That is "OnLoad" code:
// Remove loaded models
if (_root->getNumChildren())
{
_root->removeChildren(NUMBER_SERVICE_NODES,
_root->getNumChildren() - NUMBER_SERVICE_NODES);
}
// Load a new model
osg::ref_ptr<osg::Node> node;
osgDB::ReaderWriter::ReadResult rr =
osgDB::Registry::instance()->readNode( fileName,
osgDB::Registry::instance()->getOptions() );
if ( rr.validNode() )
{
node = rr.takeNode();
}
if (node.valid())
{
node->setDataVariance( osg::Object::DYNAMIC );
_root->addChild( node.get() );
// Back to home position to see the whole scene
_viewer->getCameraManipulator()->computeHomePosition();
_viewer->getCameraManipulator()->home( 0.0 );
}
else
{
::MessageBox(0, A2BSTR("Fail to open file."), L"Error", MB_OK);
}
Oleg
------------------
Read this topic online here:
http://forum.openscenegraph.org/viewtopic.php?p=26687#26687
_______________________________________________
osg-users mailing list
[email protected]
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org