int main(int argc, char** argv) { QApplication app(argc, argv); // prepare scene. osg::Vec3 center(0.0f,0.0f,0.0f); float radius = 1.0f; // create the hud. osg::ref_ptr<osg::Camera> camera = new osg::Camera; camera->setReferenceFrame(osg::Transform::ABSOLUTE_RF); camera->setProjectionMatrixAsOrtho2D(0,1280,0,1024); camera->setViewMatrix(osg::Matrix::identity()); camera->setClearMask(GL_DEPTH_BUFFER_BIT); camera->addChild(createHUDText()); camera->getOrCreateStateSet()->setMode(GL_LIGHTING,osg::StateAttribute::OFF); // make sure the root node is group so we can add extra nodes to it. osg::ref_ptr<osg::Group> group = new osg::Group; group->addChild(camera.get()); group->addChild(create3DText(center, radius)); // The qt window MainWindow widget; // set the scene to render widget.setSceneData(group.get()); widget.setCameraManipulator(new osgGA::TrackballManipulator); widget.setGeometry(100, 100, 800, 600); widget.show(); return app.exec(); }
int main(int argc, char** argv) { osg::ArgumentParser arguments(&argc, argv); // construct the viewer. osgViewer::Viewer viewer(arguments); typedef std::list< osg::ref_ptr<osg::OperationThread> > Threads; Threads operationThreads; osg::ref_ptr<UpdateTextOperation> updateOperation; unsigned int numThreads = 0; if (arguments.read("--mt", numThreads) || arguments.read("--mt")) { // construct a multi-threaded text updating test. if (numThreads==0) numThreads = 1; // create a group to add everything into. osg::Group* mainGroup = new osg::Group; osg::Vec3 center(0.5f,0.5f,0.5f); float diameter = 1.0f; osg::ref_ptr<osg::Node> loadedModel = osgDB::readNodeFiles(arguments); if (loadedModel.valid()) { mainGroup->addChild(loadedModel.get()); center = loadedModel->getBound().center(); diameter = loadedModel->getBound().radius() * 2.0f; } for(unsigned int i=0; i<numThreads; ++i) { osg::Group* textGroup = new osg::Group; mainGroup->addChild(textGroup); // create the background thread osg::OperationThread* operationThread = new osg::OperationThread; operationThreads.push_back(operationThread); // create the operation that will run in the background and // sync once per frame with the main viewer loop. updateOperation = new UpdateTextOperation(center, diameter, textGroup); // add the operation to the operation thread and start it. operationThread->add(updateOperation.get()); operationThread->startThread(); // add the operation to the viewer to sync once per frame. viewer.addUpdateOperation(updateOperation.get()); // add a unit cube for the text to appear within. osg::Geode* geode = new osg::Geode; geode->getOrCreateStateSet()->setAttribute(new osg::PolygonMode(osg::PolygonMode::FRONT_AND_BACK,osg::PolygonMode::LINE)); geode->addDrawable(new osg::ShapeDrawable(new osg::Box(center,diameter))); mainGroup->addChild(geode); } viewer.setSceneData(mainGroup); } else { // prepare scene. osg::Vec3 center(0.0f,0.0f,0.0f); float radius = 1.0f; // make sure the root node is group so we can add extra nodes to it. osg::Group* group = new osg::Group; if (true) { // create the hud. osg::Camera* camera = new osg::Camera; camera->setReferenceFrame(osg::Transform::ABSOLUTE_RF); camera->setProjectionMatrixAsOrtho2D(0,1280,0,1024); camera->setViewMatrix(osg::Matrix::identity()); camera->setClearMask(GL_DEPTH_BUFFER_BIT); camera->addChild(createHUDText()); camera->getOrCreateStateSet()->setMode(GL_LIGHTING,osg::StateAttribute::OFF); group->addChild(camera); } if (true) { group->addChild(create3DText(center,radius)); } // set the scene to render viewer.setSceneData(group); } std::string filename; if (arguments.read("-o",filename)) { osgDB::writeNodeFile(*viewer.getSceneData(),filename); return 0; } viewer.addEventHandler( new osgGA::StateSetManipulator(viewer.getCamera()->getOrCreateStateSet()) ); viewer.addEventHandler(new osgViewer::StatsHandler()); viewer.run(); if (!operationThreads.empty()) { for(Threads::iterator itr = operationThreads.begin(); itr != operationThreads.end(); ++itr) { (*itr)->cancel(); } } return 0; }