OSG Programming's Hello World 4.0

Source: Internet
Author: User
Tags apm

The code is as follows://need to add two libraries: OsgUtild.lib, OsgTextd.lib

#include <osgDB/ReadFile>#include<osgUtil/Optimizer>#include<osg/CoordinateSystemNode>#include<osg/Switch>#include<osgText/Text>#include<osgViewer/Viewer>#include<osgViewer/ViewerEventHandlers>#include<osgGA/TrackballManipulator>#include<osgGA/FlightManipulator>#include<osgGA/DriveManipulator>#include<osgGA/KeySwitchMatrixManipulator>#include<osgGA/StateSetManipulator>#include<osgGA/AnimationPathManipulator>#include<osgGA/TerrainManipulator>#include<iostream>intMainintargcChar**argv) {Osg::argumentparser arguments (&argc, argv); Arguments.getapplicationusage ()-Setapplicationname (Arguments.getapplicationname ()); Arguments.getapplicationusage ()->setdescription (Arguments.getapplicationname () +"Is the openscenegraph example which loads and visualises 3d models."); Arguments.getapplicationusage ()->setcommandlineusage (Arguments.getapplicationname () +"[options] filename ..."); Arguments.getapplicationusage ()->addcommandlineoption ("--image <filename>","Load an image and render it on quad"); Arguments.getapplicationusage ()->addcommandlineoption ("--dem <filename>","Load an Image/dem and render it on a Heightfield"); Arguments.getapplicationusage ()->addcommandlineoption ("- H or-help","Display command Line Parameters"); Arguments.getapplicationusage ()->addcommandlineoption ("--help-env","Display Environmental variables available"); Arguments.getapplicationusage ()->addcommandlineoption ("--help-keys","Display keyboard & mouse bindings available"); Arguments.getapplicationusage ()->addcommandlineoption ("--help-all","Display command line, env VARs and keyboard & mouse bindings."); Arguments.getapplicationusage ()->addcommandlineoption ("--singlethreaded","Select singlethreaded threading Model for viewer."); Arguments.getapplicationusage ()->addcommandlineoption ("-culldrawthreadpercontext",         "Select culldrawthreadpercontext threading Model for viewer."); Arguments.getapplicationusage ()->addcommandlineoption ("--drawthreadpercontext",         "Select drawthreadpercontext threading Model for viewer."); Arguments.getapplicationusage ()->addcommandlineoption ("--cullthreadpercameradrawthreadpercontext",        "Select cullthreadpercameradrawthreadpercontext threading Model for viewer."); BOOLHelpall = Arguments.read ("--help-all"); unsignedintHelptype = ((Helpall | | | arguments.read ("- H") || Arguments.read ("--help")) ?osg::applicationusage::command_line_option:0) |((Helpall|| Arguments.read ("--help-env")) ?osg::applicationusage::environmental_variable:0) |((Helpall|| Arguments.read ("--help-keys")) ?osg::applicationusage::keyboard_mouse_binding:0); if(Helptype) {arguments.getapplicationusage ()-Write (std::cout, helptype); return 1;    } osgviewer::viewer Viewer (arguments); if(Arguments.errors ()) {arguments.writeerrormessages (std::cout); return 1; }    if(ARGUMENTS.ARGC () <=1) {arguments.getapplicationusage ()-Write (std::cout, osg::applicationusage::command_line_option); return 1; }        //Add some operatorsOsg::ref_ptr<osgga::keyswitchmatrixmanipulator> Keyswitchmanipulator =NewOsgga::keyswitchmatrixmanipulator; Keyswitchmanipulator->addmatrixmanipulator ('1',"trackball",Newosgga::trackballmanipulator ()); Keyswitchmanipulator->addmatrixmanipulator ('2',"Flight",Newosgga::flightmanipulator ()); Keyswitchmanipulator->addmatrixmanipulator ('3'," Drive",NewOsgga::D rivemanipulator ()); Keyswitchmanipulator->addmatrixmanipulator ('4',"Terrain",Newosgga::terrainmanipulator ()); STD::stringPathfile; CharKeyforanimationpath ='5';  while(Arguments.read ("- P", Pathfile)) {Osgga::animationpathmanipulator*APM =NewOsgga::animationpathmanipulator (Pathfile); if(APM | |!apm->valid ()) {unsignedintnum = keyswitchmanipulator->getnummatrixmanipulators (); Keyswitchmanipulator->addmatrixmanipulator (Keyforanimationpath,"Path", APM); Keyswitchmanipulator-selectmatrixmanipulator (num); ++Keyforanimationpath; }} viewer.setcameramanipulator (Keyswitchmanipulator.Get()); //Adding status EventsViewer.addeventhandler (NewOsgga::statesetmanipulator (Viewer.getcamera ()Getorcreatestateset ())); Viewer.addeventhandler (NewOsgviewer::threadinghandler); //Window Size Change EventViewer.addeventhandler (NewOsgviewer::windowsizehandler); //add some common state settingsViewer.addeventhandler (NewOsgviewer::statshandler); Viewer.addeventhandler (NewOsgviewer::helphandler (Arguments.getapplicationusage ())); Viewer.addeventhandler (NewOsgviewer::recordcamerapathhandler); Osg::ref_ptr<osg::Node> Loadedmodel =osgdb::readnodefiles (arguments); if(!Loadedmodel) {Std::cout<<arguments.getapplicationname () <<": No Data loaded"<<Std::endl; return 1;    } arguments.reportremainingoptionsasunrecognized (); if(Arguments.errors ()) {arguments.writeerrormessages (std::cout); return 1;    } Osgutil::optimizer Optimizer; Optimizer.optimize (Loadedmodel.Get()); Viewer.setscenedata (Loadedmodel.Get());    Viewer.realize (); Viewer.run ();}

Spit it out. The author, as a beginner's tutorial, what's the use of doing this mess?

This example compares to the 3.0 version, the only new thing is to have a model optimization.

OSG Programming's Hello World 4.0

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.