| 264 | | int main( int argc, char **argv ) |
| 265 | | { |
| 266 | | |
| 267 | | // use an ArgumentParser object to manage the program arguments. |
| 268 | | osg::ArgumentParser arguments(&argc,argv); |
| 269 | | |
| 270 | | // set up the usage document, in case we need to print out how to use this program. |
| 271 | | arguments.getApplicationUsage()->setDescription(arguments.getApplicationName()+" is the example which demonstrates use of pre rendering to texture to create a shadow effect.."); |
| 272 | | arguments.getApplicationUsage()->setCommandLineUsage(arguments.getApplicationName()+" [options] filename ..."); |
| 273 | | arguments.getApplicationUsage()->addCommandLineOption("-h or --help","Display this information"); |
| 274 | | |
| | 264 | int main(int, char **) |
| | 265 | { |
| 276 | | osgProducer::Viewer viewer(arguments); |
| 277 | | |
| 278 | | // set up the value with sensible default event handlers. |
| 279 | | viewer.setUpViewer(osgProducer::Viewer::STANDARD_SETTINGS); |
| 280 | | |
| 281 | | // get details on keyboard and mouse bindings used by the viewer. |
| 282 | | viewer.getUsage(*arguments.getApplicationUsage()); |
| 283 | | |
| 284 | | // if user request help write it out to cout. |
| 285 | | if (arguments.read("-h") || arguments.read("--help")) |
| 286 | | { |
| 287 | | arguments.getApplicationUsage()->write(std::cout); |
| 288 | | return 1; |
| 289 | | } |
| 290 | | |
| 291 | | // any option left unread are converted into errors to write out later. |
| 292 | | arguments.reportRemainingOptionsAsUnrecognized(); |
| 293 | | |
| 294 | | // report any errors if they have occured when parsing the program aguments. |
| 295 | | if (arguments.errors()) |
| 296 | | { |
| 297 | | arguments.writeErrorMessages(std::cout); |
| 298 | | return 1; |
| 299 | | } |
| 300 | | |
| 301 | | // load the nodes from the commandline arguments. |
| 302 | | osg::Node* model = createModel(); |
| 303 | | if (!model) |
| 304 | | { |
| 305 | | return 1; |
| 306 | | } |
| 307 | | |
| 308 | | // comment out optimization over the scene graph right now as it optimizers away the shadow... will look into this.. |
| 309 | | //osgUtil::Optimizer optimzer; |
| 310 | | //optimzer.optimize(rootnode); |
| 311 | | |
| 312 | | // add a viewport to the viewer and attach the scene graph. |
| 313 | | viewer.setSceneData( model ); |
| 314 | | |
| 315 | | // create the windows and run the threads. |
| 316 | | viewer.realize(); |
| 317 | | |
| 318 | | while( !viewer.done() ) |
| 319 | | { |
| 320 | | // wait for all cull and draw threads to complete. |
| 321 | | viewer.sync(); |
| 322 | | |
| 323 | | // update the scene by traversing it with the the update visitor which will |
| 324 | | // call all node update callbacks and animations. |
| 325 | | viewer.update(); |
| 326 | | |
| 327 | | // fire off the cull and draw traversals of the scene. |
| 328 | | viewer.frame(); |
| 329 | | |
| 330 | | } |
| 331 | | |
| 332 | | // wait for all cull and draw threads to complete. |
| 333 | | viewer.sync(); |
| 334 | | |
| 335 | | // run a clean up frame to delete all OpenGL objects. |
| 336 | | viewer.cleanup_frame(); |
| 337 | | |
| 338 | | // wait for all the clean up frame to complete. |
| 339 | | viewer.sync(); |
| 340 | | |
| 341 | | return 0; |
| 342 | | } |
| | 267 | osgViewer::Viewer viewer; |
| | 268 | |
| | 269 | // add the spoit light model to the viewer |
| | 270 | viewer.setSceneData( createModel() ); |
| | 271 | |
| | 272 | // run the viewer main frame loop. |
| | 273 | return viewer.run(); |
| | 274 | } |