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

Revision 2369, 3.4 kB (checked in by robert, 11 years ago)

Fixed missing osg::

  • 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-09-18
15 *
16 * A demo of the OpenGL Shading Language shaders using osgGL2.
17 *
18 * See http://www.3dlabs.com/opengl2/ for more information regarding
19 * the OpenGL Shading Language.
20*/
21
22#include <osg/Notify>
23#include <osgGA/GUIEventAdapter>
24#include <osgGA/GUIActionAdapter>
25#include <osgDB/ReadFile>
26#include <osgUtil/Optimizer>
27#include <osgProducer/Viewer>
28#include <osgGL2/Version>
29
30#include "GL2Scene.h"
31
32using namespace osg;
33
34///////////////////////////////////////////////////////////////////////////
35
36class KeyHandler: public osgGA::GUIEventHandler
37{
38    public:
39        KeyHandler( GL2ScenePtr gl2Scene ) :
40                _gl2Scene(gl2Scene)
41        {}
42
43        bool handle( const osgGA::GUIEventAdapter& ea, osgGA::GUIActionAdapter& )
44        {
45            if( ea.getEventType() != osgGA::GUIEventAdapter::KEYDOWN )
46                return false;
47
48            switch( ea.getKey() )
49            {
50                case 'x':
51                    _gl2Scene->reloadShaderSource();
52                    return true;
53                case 'y':
54                    _gl2Scene->toggleShaderEnable();
55                    return true;
56            }
57            return false;
58        }
59
60    private:
61        GL2ScenePtr _gl2Scene;
62};
63
64///////////////////////////////////////////////////////////////////////////
65
66int main( int argc, char **argv )
67{
68    // use an ArgumentParser object to manage the program arguments.
69    osg::ArgumentParser args(&argc,argv);
70   
71    // set up the usage document
72    args.getApplicationUsage()->setApplicationName(args.getApplicationName());
73    args.getApplicationUsage()->setDescription(args.getApplicationName() +
74            " demonstrates the OpenGL Shading Language using osgGL2");
75    args.getApplicationUsage()->setCommandLineUsage(args.getApplicationName());
76    args.getApplicationUsage()->addCommandLineOption("-h or --help","Display this information");
77
78    args.getApplicationUsage()->addKeyboardMouseBinding( "x", "Reload and recompile shader source files." );
79    args.getApplicationUsage()->addKeyboardMouseBinding( "y", "Toggle shader enable" );
80
81    // construct the viewer.
82    osgProducer::Viewer viewer(args);
83    viewer.setUpViewer( osgProducer::Viewer::STANDARD_SETTINGS );
84    viewer.getUsage( *args.getApplicationUsage() );
85
86    if( args.read("-h") || args.read("--help") )
87    {
88        args.getApplicationUsage()->write(std::cout);
89        return 1;
90    }
91
92    // any option left unread are converted into errors to write out later.
93    args.reportRemainingOptionsAsUnrecognized();
94    if( args.errors() )
95    {
96        args.writeErrorMessages(std::cout);
97        return 1;
98    }
99
100    // create the scene
101    osg::notify(osg::NOTICE) << "osgGL2 version " << osgGL2GetVersion() << std::endl;
102    GL2ScenePtr gl2Scene = new GL2Scene;
103
104    viewer.setSceneData( gl2Scene->getRootNode().get() );
105    viewer.getEventHandlerList().push_front( new KeyHandler(gl2Scene) );
106    viewer.realize();
107    while( !viewer.done() )
108    {
109        viewer.sync();
110        viewer.update();
111        viewer.frame();
112    }
113    viewer.sync();
114    return 0;
115}
116
117/*EOF*/
Note: See TracBrowser for help on using the browser.