root/OpenSceneGraph/trunk/examples/osgshaders/osgshaders.cpp
@
13347
| Revision 6941, 2.6 kB (checked in by robert, 6 years ago) | |
|---|---|
|
|
| Line | |
|---|---|
| 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. |
| 17 | */ |
| 18 | |
| 19 | /* file: examples/osgglsl/osgshaders.cpp |
| 20 | * author: Mike Weiblen 2005-04-05 |
| 21 | * |
| 22 | * A demo of the OpenGL Shading Language shaders using core OSG. |
| 23 | * |
| 24 | * See http://www.3dlabs.com/opengl2/ for more information regarding |
| 25 | * the OpenGL Shading Language. |
| 26 | */ |
| 27 | |
| 28 | #include <osg/Notify> |
| 29 | #include <osgGA/GUIEventAdapter> |
| 30 | #include <osgGA/GUIActionAdapter> |
| 31 | #include <osgDB/ReadFile> |
| 32 | #include <osgUtil/Optimizer> |
| 33 | #include <osgViewer/Viewer> |
| 34 | |
| 35 | #include "GL2Scene.h" |
| 36 | |
| 37 | using namespace osg; |
| 38 | |
| 39 | /////////////////////////////////////////////////////////////////////////// |
| 40 | |
| 41 | class KeyHandler: public osgGA::GUIEventHandler |
| 42 | { |
| 43 | public: |
| 44 | KeyHandler( GL2ScenePtr gl2Scene ) : |
| 45 | _gl2Scene(gl2Scene) |
| 46 | {} |
| 47 | |
| 48 | bool handle( const osgGA::GUIEventAdapter& ea, osgGA::GUIActionAdapter& ) |
| 49 | { |
| 50 | if( ea.getEventType() != osgGA::GUIEventAdapter::KEYDOWN ) |
| 51 | return false; |
| 52 | |
| 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 | } |
| 64 | |
| 65 | private: |
| 66 | GL2ScenePtr _gl2Scene; |
| 67 | }; |
| 68 | |
| 69 | /////////////////////////////////////////////////////////////////////////// |
| 70 | |
| 71 | int main(int, char **) |
| 72 | { |
| 73 | // construct the viewer. |
| 74 | osgViewer::Viewer viewer; |
| 75 | |
| 76 | // create the scene |
| 77 | GL2ScenePtr gl2Scene = new GL2Scene; |
| 78 | |
| 79 | viewer.setSceneData( gl2Scene->getRootNode().get() ); |
| 80 | |
| 81 | viewer.addEventHandler( new KeyHandler(gl2Scene) ); |
| 82 | |
| 83 | return viewer.run(); |
| 84 | } |
| 85 | |
| 86 | /*EOF*/ |
Note: See TracBrowser
for help on using the browser.
