root/OpenSceneGraph/trunk/examples/osgshaders/osgshaders.cpp @ 2027

Revision 2027, 3.9 kB (checked in by robert, 11 years ago)

From Mike Weiblen's osgGL2 node kit which support the latest OpenGL 2.0 extensions.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
Line 
1/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2003 Robert Osfield
2 * Copyright (C) 2003 3Dlabs Inc. Ltd.
3 *
4 * This application is open source and may be redistributed and/or modified   
5 * freely and without restriction, both in commericial and non commericial applications,
6 * as long as this copyright notice is maintained.
7 *
8 * This application is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
11*/
12
13/* file:        examples/osgshaders/osgshaders.cpp
14 * author:      Mike Weiblen 2003-07-14
15 *
16 * A simple app skeleton for viewing OpenGL Shading Language shaders;
17 * derived from osgviewer.cpp from OSG 0.9.4-2
18 *
19 * See http://www.3dlabs.com/opengl2/ for more information regarding
20 * the OpenGL Shading Language.
21*/
22
23#include <osgDB/ReadFile>
24#include <osgUtil/Optimizer>
25#include <osgProducer/Viewer>
26
27#define GL2SCENE
28osg::Node* GL2Scene();
29void GL2Update();
30
31int main( int argc, char **argv )
32{
33
34    // use an ArgumentParser object to manage the program arguments.
35    osg::ArgumentParser arguments(&argc,argv);
36   
37    // set up the usage document, in case we need to print out how to use this program.
38    arguments.getApplicationUsage()->setApplicationName(arguments.getApplicationName());
39    arguments.getApplicationUsage()->setDescription(arguments.getApplicationName()+" is the standard OpenSceneGraph example which loads and visualises 3d models.");
40    arguments.getApplicationUsage()->setCommandLineUsage(arguments.getApplicationName()+" [options] filename ...");
41    arguments.getApplicationUsage()->addCommandLineOption("-h or --help","Display this information");
42   
43
44    // construct the viewer.
45    osgProducer::Viewer viewer(arguments);
46
47    // set up the value with sensible default event handlers.
48    viewer.setUpViewer(osgProducer::Viewer::STANDARD_SETTINGS);
49
50    // get details on keyboard and mouse bindings used by the viewer.
51    viewer.getUsage(*arguments.getApplicationUsage());
52
53    // if user request help write it out to cout.
54    if (arguments.read("-h") || arguments.read("--help"))
55    {
56        arguments.getApplicationUsage()->write(std::cout);
57        return 1;
58    }
59
60    // any option left unread are converted into errors to write out later.
61    arguments.reportRemainingOptionsAsUnrecognized();
62
63    // report any errors if they have occured when parsing the program aguments.
64    if (arguments.errors())
65    {
66        arguments.writeErrorMessages(std::cout);
67        return 1;
68    }
69   
70#ifdef GL2SCENE //(
71    osg::ref_ptr<osg::Node> loadedModel = GL2Scene();
72#else //)(
73    if (arguments.argc()<=1)
74    {
75        arguments.getApplicationUsage()->write(std::cout,osg::ApplicationUsage::COMMAND_LINE_OPTION);
76        return 1;
77    }
78
79    // read the scene from the list of file specified commandline args.
80    osg::ref_ptr<osg::Node> loadedModel = osgDB::readNodeFiles(arguments);
81
82    // if no model has been successfully loaded report failure.
83    if (!loadedModel)
84    {
85        std::cout << arguments.getApplicationName() <<": No data loaded" << std::endl;
86        return 1;
87    }
88
89
90    // optimize the scene graph, remove rendundent nodes and state etc.
91    osgUtil::Optimizer optimizer;
92    optimizer.optimize(loadedModel.get());
93#endif //)
94
95    // set the scene to render
96    viewer.setSceneData(loadedModel.get());
97
98    // create the windows and run the threads.
99    viewer.realize();
100
101    while( !viewer.done() )
102    {
103        // wait for all cull and draw threads to complete.
104        viewer.sync();
105
106        // update the scene by traversing it with the the update visitor which will
107        // call all node update callbacks and animations.
108        viewer.update();
109#ifdef GL2SCENE //(
110        GL2Update();
111#endif //)
112         
113        // fire off the cull and draw traversals of the scene.
114        viewer.frame();
115       
116    }
117   
118    // wait for all cull and draw threads to complete before exit.
119    viewer.sync();
120
121    return 0;
122}
Note: See TracBrowser for help on using the browser.