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

Revision 5956, 2.1 kB (checked in by robert, 7 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/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield
2 * Copyright (C) 2003-2005 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/osgglsl/osgshaders.cpp
14 * author:        Mike Weiblen 2005-04-05
15 *
16 * A demo of the OpenGL Shading Language shaders using core OSG.
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 <osgViewer/Viewer>
28
29#include "GL2Scene.h"
30
31using namespace osg;
32
33///////////////////////////////////////////////////////////////////////////
34
35class 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
65int main(int, char **)
66{
67    // construct the viewer.
68    osgViewer::Viewer viewer;
69
70    // create the scene
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/*EOF*/
Note: See TracBrowser for help on using the browser.