|
Revision 5956, 2.1 kB
(checked in by robert, 6 years ago)
|
|
Ported following examples to osgViewer:
osgshaders
osgshaderterrain
osgshadow
osgshadowtexture
|
-
Property svn:eol-style set to
native
-
Property svn:keywords set to
Author Date Id Revision
|
| Line | |
|---|
| 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 <osgViewer/Viewer> |
|---|
| 28 | |
|---|
| 29 | #include "GL2Scene.h" |
|---|
| 30 | |
|---|
| 31 | using namespace osg; |
|---|
| 32 | |
|---|
| 33 | |
|---|
| 34 | |
|---|
| 35 | class KeyHandler: public osgGA::GUIEventHandler |
|---|
| 36 | { |
|---|
| 37 | public: |
|---|
| 38 | KeyHandler( GL2ScenePtr gl2Scene ) : |
|---|
| 39 | _gl2Scene(gl2Scene) |
|---|
| 40 | {} |
|---|
| 41 | |
|---|
| 42 | bool handle( const osgGA::GUIEventAdapter& ea, osgGA::GUIActionAdapter& ) |
|---|
| 43 | { |
|---|
| 44 | if( ea.getEventType() != osgGA::GUIEventAdapter::KEYDOWN ) |
|---|
| 45 | return false; |
|---|
| 46 | |
|---|
| 47 | switch( ea.getKey() ) |
|---|
| 48 | { |
|---|
| 49 | case 'x': |
|---|
| 50 | _gl2Scene->reloadShaderSource(); |
|---|
| 51 | return true; |
|---|
| 52 | case 'y': |
|---|
| 53 | _gl2Scene->toggleShaderEnable(); |
|---|
| 54 | return true; |
|---|
| 55 | } |
|---|
| 56 | return false; |
|---|
| 57 | } |
|---|
| 58 | |
|---|
| 59 | private: |
|---|
| 60 | GL2ScenePtr _gl2Scene; |
|---|
| 61 | }; |
|---|
| 62 | |
|---|
| 63 | |
|---|
| 64 | |
|---|
| 65 | int main(int, char **) |
|---|
| 66 | { |
|---|
| 67 | |
|---|
| 68 | osgViewer::Viewer viewer; |
|---|
| 69 | |
|---|
| 70 | |
|---|
| 71 | GL2ScenePtr gl2Scene = new GL2Scene; |
|---|
| 72 | |
|---|
| 73 | viewer.setSceneData( gl2Scene->getRootNode().get() ); |
|---|
| 74 | |
|---|
| 75 | viewer.addEventHandler( new KeyHandler(gl2Scene) ); |
|---|
| 76 | |
|---|
| 77 | return viewer.run(); |
|---|
| 78 | } |
|---|
| 79 | |
|---|
| 80 | |
|---|