root/OpenSceneGraph/trunk/examples/osgshaders/osgshaders.cpp
@
6941
| Revision 6941, 2.6 kB (checked in by robert, 6 years ago) | |
|---|---|
|
|
| Rev | Line | |
|---|---|---|
| [6941] | 1 | /* OpenSceneGraph example, osgshaders. |
| 2 | * | |
| 3 | * Permission is hereby granted, free of charge, to any person obtaining a copy | |
| 4 | * of this software and associated documentation files (the "Software"), to deal | |
| 5 | * in the Software without restriction, including without limitation the rights | |
| 6 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | |
| 7 | * copies of the Software, and to permit persons to whom the Software is | |
| 8 | * furnished to do so, subject to the following conditions: | |
| 9 | * | |
| 10 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | |
| 11 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | |
| 12 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | |
| 13 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | |
| 14 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | |
| 15 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | |
| 16 | * THE SOFTWARE. | |
| [2027] | 17 | */ |
| 18 | ||
| [4138] | 19 | /* file: examples/osgglsl/osgshaders.cpp |
| 20 | * author: Mike Weiblen 2005-04-05 | |
| [2027] | 21 | * |
| [3984] | 22 | * A demo of the OpenGL Shading Language shaders using core OSG. |
| [2027] | 23 | * |
| 24 | * See http://www.3dlabs.com/opengl2/ for more information regarding | |
| 25 | * the OpenGL Shading Language. | |
| 26 | */ | |
| 27 | ||
| [2352] | 28 | #include <osg/Notify> |
| 29 | #include <osgGA/GUIEventAdapter> | |
| 30 | #include <osgGA/GUIActionAdapter> | |
| [2027] | 31 | #include <osgDB/ReadFile> |
| 32 | #include <osgUtil/Optimizer> | |
| [5956] | 33 | #include <osgViewer/Viewer> |
| [2027] | 34 | |
| [2352] | 35 | #include "GL2Scene.h" |
| [2027] | 36 | |
| [2352] | 37 | using namespace osg; |
| 38 | ||
| 39 | /////////////////////////////////////////////////////////////////////////// | |
| 40 | ||
| 41 | class KeyHandler: public osgGA::GUIEventHandler | |
| [2027] | 42 | { |
| [2352] | 43 | public: |
| [4138] | 44 | KeyHandler( GL2ScenePtr gl2Scene ) : |
| 45 | _gl2Scene(gl2Scene) | |
| 46 | {} | |
| [2027] | 47 | |
| [4138] | 48 | bool handle( const osgGA::GUIEventAdapter& ea, osgGA::GUIActionAdapter& ) |
| 49 | { | |
| 50 | if( ea.getEventType() != osgGA::GUIEventAdapter::KEYDOWN ) | |
| 51 | return false; | |
| [2352] | 52 | |
| [4138] | 53 | switch( ea.getKey() ) |
| 54 | { | |
| 55 | case 'x': | |
| 56 | _gl2Scene->reloadShaderSource(); | |
| 57 | return true; | |
| 58 | case 'y': | |
| 59 | _gl2Scene->toggleShaderEnable(); | |
| 60 | return true; | |
| 61 | } | |
| 62 | return false; | |
| 63 | } | |
| [2352] | 64 | |
| 65 | private: | |
| [4138] | 66 | GL2ScenePtr _gl2Scene; |
| [2352] | 67 | }; |
| 68 | ||
| 69 | /////////////////////////////////////////////////////////////////////////// | |
| 70 | ||
| [5956] | 71 | int main(int, char **) |
| [2352] | 72 | { |
| [2027] | 73 | // construct the viewer. |
| [5956] | 74 | osgViewer::Viewer viewer; |
| [2027] | 75 | |
| [2352] | 76 | // create the scene |
| 77 | GL2ScenePtr gl2Scene = new GL2Scene; | |
| [2027] | 78 | |
| [2352] | 79 | viewer.setSceneData( gl2Scene->getRootNode().get() ); |
| [5381] | 80 | |
| [5956] | 81 | viewer.addEventHandler( new KeyHandler(gl2Scene) ); |
| [5381] | 82 | |
| [5956] | 83 | return viewer.run(); |
| [2027] | 84 | } |
| 85 | ||
| [2352] | 86 | /*EOF*/ |
Note: See TracBrowser
for help on using the browser.
