| 1 | |
|---|
| 2 | |
|---|
| 3 | |
|---|
| 4 | |
|---|
| 5 | |
|---|
| 6 | |
|---|
| 7 | |
|---|
| 8 | |
|---|
| 9 | |
|---|
| 10 | |
|---|
| 11 | |
|---|
| 12 | |
|---|
| 13 | |
|---|
| 14 | |
|---|
| 15 | |
|---|
| 16 | |
|---|
| 17 | |
|---|
| 18 | |
|---|
| 19 | |
|---|
| 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 | |
|---|
| 32 | using namespace osg; |
|---|
| 33 | |
|---|
| 34 | |
|---|
| 35 | |
|---|
| 36 | class 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 | |
|---|
| 66 | int main( int argc, char **argv ) |
|---|
| 67 | { |
|---|
| 68 | |
|---|
| 69 | osg::ArgumentParser args(&argc,argv); |
|---|
| 70 | |
|---|
| 71 | |
|---|
| 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 | |
|---|
| 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 | |
|---|
| 93 | args.reportRemainingOptionsAsUnrecognized(); |
|---|
| 94 | if( args.errors() ) |
|---|
| 95 | { |
|---|
| 96 | args.writeErrorMessages(std::cout); |
|---|
| 97 | return 1; |
|---|
| 98 | } |
|---|
| 99 | |
|---|
| 100 | |
|---|
| 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 | |
|---|