2007-06-12 22:20:16 +08:00
/* OpenSceneGraph example, osgmovie.
*
* Permission is hereby granted , free of charge , to any person obtaining a copy
* of this software and associated documentation files ( the " Software " ) , to deal
* in the Software without restriction , including without limitation the rights
* to use , copy , modify , merge , publish , distribute , sublicense , and / or sell
* copies of the Software , and to permit persons to whom the Software is
* furnished to do so , subject to the following conditions :
*
* THE SOFTWARE IS PROVIDED " AS IS " , WITHOUT WARRANTY OF ANY KIND , EXPRESS OR
* IMPLIED , INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY ,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT . IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM , DAMAGES OR OTHER
* LIABILITY , WHETHER IN AN ACTION OF CONTRACT , TORT OR OTHERWISE , ARISING FROM ,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE .
*/
2004-01-30 22:06:29 +08:00
2007-01-08 18:00:16 +08:00
# include <osgViewer/Viewer>
2007-06-13 02:58:32 +08:00
# include <osgViewer/ViewerEventHandlers>
2004-01-30 22:06:29 +08:00
# include <osgDB/ReadFile>
# include <osg/Geode>
# include <osg/Geometry>
# include <osg/StateSet>
# include <osg/Material>
# include <osg/Texture2D>
# include <osg/TextureRectangle>
2007-05-08 20:18:57 +08:00
# include <osg/TextureCubeMap>
2004-01-30 22:06:29 +08:00
# include <osg/TexMat>
# include <osg/CullFace>
2004-03-13 05:04:20 +08:00
# include <osg/ImageStream>
2006-01-13 06:43:36 +08:00
# include <osg/io_utils>
2004-01-30 22:06:29 +08:00
# include <osgGA/TrackballManipulator>
2007-12-07 01:53:22 +08:00
# include <osgGA/StateSetManipulator>
2006-01-13 06:43:36 +08:00
# include <osgGA/EventVisitor>
2004-01-30 22:06:29 +08:00
2007-01-08 18:00:16 +08:00
# include <iostream>
2005-02-09 18:39:45 +08:00
2007-01-08 18:00:16 +08:00
osg : : ImageStream * s_imageStream = 0 ;
2004-03-13 05:04:20 +08:00
class MovieEventHandler : public osgGA : : GUIEventHandler
{
public :
2008-08-15 21:07:04 +08:00
MovieEventHandler ( ) : _trackMouse ( false ) , _playToggle ( true ) { }
2007-05-08 20:18:57 +08:00
void setMouseTracking ( bool track ) { _trackMouse = track ; }
bool getMouseTracking ( ) const { return _trackMouse ; }
2004-03-13 05:04:20 +08:00
void set ( osg : : Node * node ) ;
2006-01-13 06:43:36 +08:00
virtual bool handle ( const osgGA : : GUIEventAdapter & ea , osgGA : : GUIActionAdapter & aa , osg : : Object * , osg : : NodeVisitor * nv ) ;
2004-03-13 05:04:20 +08:00
virtual void getUsage ( osg : : ApplicationUsage & usage ) const ;
2007-12-11 01:30:18 +08:00
typedef std : : vector < osg : : observer_ptr < osg : : ImageStream > > ImageStreamList ;
2004-03-13 05:04:20 +08:00
protected :
virtual ~ MovieEventHandler ( ) { }
class FindImageStreamsVisitor : public osg : : NodeVisitor
{
public :
FindImageStreamsVisitor ( ImageStreamList & imageStreamList ) :
_imageStreamList ( imageStreamList ) { }
virtual void apply ( osg : : Geode & geode )
{
apply ( geode . getStateSet ( ) ) ;
for ( unsigned int i = 0 ; i < geode . getNumDrawables ( ) ; + + i )
{
apply ( geode . getDrawable ( i ) - > getStateSet ( ) ) ;
}
traverse ( geode ) ;
}
virtual void apply ( osg : : Node & node )
{
apply ( node . getStateSet ( ) ) ;
traverse ( node ) ;
}
inline void apply ( osg : : StateSet * stateset )
{
if ( ! stateset ) return ;
osg : : StateAttribute * attr = stateset - > getTextureAttribute ( 0 , osg : : StateAttribute : : TEXTURE ) ;
if ( attr )
{
osg : : Texture2D * texture2D = dynamic_cast < osg : : Texture2D * > ( attr ) ;
if ( texture2D ) apply ( dynamic_cast < osg : : ImageStream * > ( texture2D - > getImage ( ) ) ) ;
osg : : TextureRectangle * textureRec = dynamic_cast < osg : : TextureRectangle * > ( attr ) ;
if ( textureRec ) apply ( dynamic_cast < osg : : ImageStream * > ( textureRec - > getImage ( ) ) ) ;
}
}
inline void apply ( osg : : ImageStream * imagestream )
{
2005-02-09 18:39:45 +08:00
if ( imagestream )
{
_imageStreamList . push_back ( imagestream ) ;
s_imageStream = imagestream ;
}
2004-03-13 05:04:20 +08:00
}
ImageStreamList & _imageStreamList ;
} ;
2008-08-15 21:07:04 +08:00
bool _playToggle ;
2007-05-08 20:18:57 +08:00
bool _trackMouse ;
2004-03-13 05:04:20 +08:00
ImageStreamList _imageStreamList ;
} ;
void MovieEventHandler : : set ( osg : : Node * node )
{
_imageStreamList . clear ( ) ;
if ( node )
{
FindImageStreamsVisitor fisv ( _imageStreamList ) ;
node - > accept ( fisv ) ;
}
}
2006-01-13 06:43:36 +08:00
bool MovieEventHandler : : handle ( const osgGA : : GUIEventAdapter & ea , osgGA : : GUIActionAdapter & aa , osg : : Object * , osg : : NodeVisitor * nv )
2004-03-13 05:04:20 +08:00
{
switch ( ea . getEventType ( ) )
{
2006-01-13 06:43:36 +08:00
case ( osgGA : : GUIEventAdapter : : MOVE ) :
case ( osgGA : : GUIEventAdapter : : PUSH ) :
case ( osgGA : : GUIEventAdapter : : RELEASE ) :
{
2007-05-08 20:18:57 +08:00
if ( _trackMouse )
2006-01-13 06:43:36 +08:00
{
2007-05-08 20:18:57 +08:00
osgViewer : : View * view = dynamic_cast < osgViewer : : View * > ( & aa ) ;
osgUtil : : LineSegmentIntersector : : Intersections intersections ;
2008-04-11 18:10:40 +08:00
bool foundIntersection = view = = 0 ? false :
( nv = = 0 ? view - > computeIntersections ( ea . getX ( ) , ea . getY ( ) , intersections ) :
view - > computeIntersections ( ea . getX ( ) , ea . getY ( ) , nv - > getNodePath ( ) , intersections ) ) ;
if ( foundIntersection )
2006-01-13 06:43:36 +08:00
{
2007-05-08 20:18:57 +08:00
// use the nearest intersection
const osgUtil : : LineSegmentIntersector : : Intersection & intersection = * ( intersections . begin ( ) ) ;
osg : : Drawable * drawable = intersection . drawable . get ( ) ;
osg : : Geometry * geometry = drawable ? drawable - > asGeometry ( ) : 0 ;
osg : : Vec3Array * vertices = geometry ? dynamic_cast < osg : : Vec3Array * > ( geometry - > getVertexArray ( ) ) : 0 ;
if ( vertices )
2006-01-13 06:43:36 +08:00
{
2007-05-08 20:18:57 +08:00
// get the vertex indices.
const osgUtil : : LineSegmentIntersector : : Intersection : : IndexList & indices = intersection . indexList ;
const osgUtil : : LineSegmentIntersector : : Intersection : : RatioList & ratios = intersection . ratioList ;
2007-01-10 01:35:46 +08:00
2007-05-08 20:18:57 +08:00
if ( indices . size ( ) = = 3 & & ratios . size ( ) = = 3 )
2006-01-13 06:43:36 +08:00
{
2007-05-08 20:18:57 +08:00
unsigned int i1 = indices [ 0 ] ;
unsigned int i2 = indices [ 1 ] ;
unsigned int i3 = indices [ 2 ] ;
float r1 = ratios [ 0 ] ;
float r2 = ratios [ 1 ] ;
float r3 = ratios [ 2 ] ;
osg : : Array * texcoords = ( geometry - > getNumTexCoordArrays ( ) > 0 ) ? geometry - > getTexCoordArray ( 0 ) : 0 ;
osg : : Vec2Array * texcoords_Vec2Array = dynamic_cast < osg : : Vec2Array * > ( texcoords ) ;
if ( texcoords_Vec2Array )
{
// we have tex coord array so now we can compute the final tex coord at the point of intersection.
osg : : Vec2 tc1 = ( * texcoords_Vec2Array ) [ i1 ] ;
osg : : Vec2 tc2 = ( * texcoords_Vec2Array ) [ i2 ] ;
osg : : Vec2 tc3 = ( * texcoords_Vec2Array ) [ i3 ] ;
osg : : Vec2 tc = tc1 * r1 + tc2 * r2 + tc3 * r3 ;
osg : : notify ( osg : : NOTICE ) < < " We hit tex coords " < < tc < < std : : endl ;
}
}
else
{
osg : : notify ( osg : : NOTICE ) < < " Intersection has insufficient indices to work with " ;
2006-01-13 06:43:36 +08:00
}
2007-01-10 01:35:46 +08:00
2007-05-08 20:18:57 +08:00
}
}
else
{
osg : : notify ( osg : : NOTICE ) < < " No intersection " < < std : : endl ;
2007-01-10 01:35:46 +08:00
}
2006-01-13 06:43:36 +08:00
}
break ;
}
2004-03-13 05:04:20 +08:00
case ( osgGA : : GUIEventAdapter : : KEYDOWN ) :
{
2007-12-07 01:53:22 +08:00
if ( ea . getKey ( ) = = ' p ' )
2004-03-13 05:04:20 +08:00
{
for ( ImageStreamList : : iterator itr = _imageStreamList . begin ( ) ;
itr ! = _imageStreamList . end ( ) ;
+ + itr )
{
2008-08-15 21:07:04 +08:00
_playToggle = ! _playToggle ;
if ( _playToggle )
2007-12-07 01:53:22 +08:00
{
// playing, so pause
std : : cout < < " Play " < < std : : endl ;
( * itr ) - > play ( ) ;
}
else
{
// playing, so pause
std : : cout < < " Pause " < < std : : endl ;
( * itr ) - > pause ( ) ;
}
2007-11-05 00:08:05 +08:00
}
return true ;
}
2004-03-13 05:04:20 +08:00
else if ( ea . getKey ( ) = = ' r ' )
{
2005-09-12 03:05:30 +08:00
for ( ImageStreamList : : iterator itr = _imageStreamList . begin ( ) ;
itr ! = _imageStreamList . end ( ) ;
+ + itr )
{
std : : cout < < " Restart " < < std : : endl ;
( * itr ) - > rewind ( ) ;
( * itr ) - > play ( ) ;
}
2004-03-13 05:04:20 +08:00
return true ;
}
2007-12-07 01:53:22 +08:00
else if ( ea . getKey ( ) = = ' L ' )
2004-03-13 05:04:20 +08:00
{
2005-09-12 03:05:30 +08:00
for ( ImageStreamList : : iterator itr = _imageStreamList . begin ( ) ;
itr ! = _imageStreamList . end ( ) ;
+ + itr )
{
if ( ( * itr ) - > getLoopingMode ( ) = = osg : : ImageStream : : LOOPING )
{
std : : cout < < " Toggle Looping Off " < < std : : endl ;
( * itr ) - > setLoopingMode ( osg : : ImageStream : : NO_LOOPING ) ;
}
else
{
std : : cout < < " Toggle Looping On " < < std : : endl ;
( * itr ) - > setLoopingMode ( osg : : ImageStream : : LOOPING ) ;
}
}
2004-03-13 05:04:20 +08:00
return true ;
}
return false ;
}
default :
return false ;
}
2006-01-13 06:43:36 +08:00
return false ;
2004-03-13 05:04:20 +08:00
}
void MovieEventHandler : : getUsage ( osg : : ApplicationUsage & usage ) const
{
2007-12-07 01:53:22 +08:00
usage . addKeyboardMouseBinding ( " p " , " Play/Pause movie " ) ;
2005-09-12 03:05:30 +08:00
usage . addKeyboardMouseBinding ( " r " , " Restart movie " ) ;
2004-03-13 05:04:20 +08:00
usage . addKeyboardMouseBinding ( " l " , " Toggle looping of movie " ) ;
}
2007-09-26 01:01:16 +08:00
osg : : Geometry * myCreateTexturedQuadGeometry ( const osg : : Vec3 & pos , float width , float height , osg : : Image * image , bool useTextureRectangle , bool xyPlane , bool option_flip )
2004-01-30 22:06:29 +08:00
{
2007-06-13 00:55:44 +08:00
bool flip = image - > getOrigin ( ) = = osg : : Image : : TOP_LEFT ;
2007-09-26 01:01:16 +08:00
if ( option_flip ) flip = ! flip ;
2004-03-13 04:23:55 +08:00
if ( useTextureRectangle )
{
2005-11-11 20:45:59 +08:00
osg : : Geometry * pictureQuad = osg : : createTexturedQuadGeometry ( pos ,
2004-03-13 04:23:55 +08:00
osg : : Vec3 ( width , 0.0f , 0.0f ) ,
2007-09-25 23:01:11 +08:00
xyPlane ? osg : : Vec3 ( 0.0f , height , 0.0f ) : osg : : Vec3 ( 0.0f , 0.0f , height ) ,
2007-06-13 00:55:44 +08:00
0.0f , flip ? image - > t ( ) : 0.0 , image - > s ( ) , flip ? 0.0 : image - > t ( ) ) ;
2005-06-08 23:57:05 +08:00
2007-06-12 22:20:16 +08:00
osg : : TextureRectangle * texture = new osg : : TextureRectangle ( image ) ;
texture - > setWrap ( osg : : Texture : : WRAP_S , osg : : Texture : : CLAMP_TO_EDGE ) ;
texture - > setWrap ( osg : : Texture : : WRAP_T , osg : : Texture : : CLAMP_TO_EDGE ) ;
2004-03-13 04:23:55 +08:00
pictureQuad - > getOrCreateStateSet ( ) - > setTextureAttributeAndModes ( 0 ,
2007-06-12 22:20:16 +08:00
texture ,
osg : : StateAttribute : : ON ) ;
2004-03-13 04:23:55 +08:00
return pictureQuad ;
}
else
{
2005-11-11 20:45:59 +08:00
osg : : Geometry * pictureQuad = osg : : createTexturedQuadGeometry ( pos ,
2004-03-13 04:23:55 +08:00
osg : : Vec3 ( width , 0.0f , 0.0f ) ,
2007-09-25 23:01:11 +08:00
xyPlane ? osg : : Vec3 ( 0.0f , height , 0.0f ) : osg : : Vec3 ( 0.0f , 0.0f , height ) ,
2007-06-13 00:55:44 +08:00
0.0f , flip ? 1.0f : 0.0f , 1.0f , flip ? 0.0f : 1.0f ) ;
2005-06-08 23:57:05 +08:00
osg : : Texture2D * texture = new osg : : Texture2D ( image ) ;
2007-06-12 22:20:16 +08:00
texture - > setFilter ( osg : : Texture : : MIN_FILTER , osg : : Texture : : LINEAR ) ;
texture - > setWrap ( osg : : Texture : : WRAP_S , osg : : Texture : : CLAMP_TO_EDGE ) ;
texture - > setWrap ( osg : : Texture : : WRAP_T , osg : : Texture : : CLAMP_TO_EDGE ) ;
2004-03-13 04:23:55 +08:00
pictureQuad - > getOrCreateStateSet ( ) - > setTextureAttributeAndModes ( 0 ,
2005-06-08 23:57:05 +08:00
texture ,
2004-03-13 04:23:55 +08:00
osg : : StateAttribute : : ON ) ;
return pictureQuad ;
2004-01-30 22:06:29 +08:00
}
}
int main ( int argc , char * * argv )
{
// use an ArgumentParser object to manage the program arguments.
osg : : ArgumentParser arguments ( & argc , argv ) ;
// set up the usage document, in case we need to print out how to use this program.
arguments . getApplicationUsage ( ) - > setApplicationName ( arguments . getApplicationName ( ) ) ;
2005-11-16 06:07:54 +08:00
arguments . getApplicationUsage ( ) - > setDescription ( arguments . getApplicationName ( ) + " example demonstrates the use of ImageStream for rendering movies as textures. " ) ;
2004-01-30 22:06:29 +08:00
arguments . getApplicationUsage ( ) - > setCommandLineUsage ( arguments . getApplicationName ( ) + " [options] filename ... " ) ;
arguments . getApplicationUsage ( ) - > addCommandLineOption ( " -h or --help " , " Display this information " ) ;
2007-01-08 18:00:16 +08:00
arguments . getApplicationUsage ( ) - > addCommandLineOption ( " --texture2D " , " Use Texture2D rather than TextureRectangle. " ) ;
arguments . getApplicationUsage ( ) - > addCommandLineOption ( " --shader " , " Use shaders to post process the video. " ) ;
2007-09-26 01:02:22 +08:00
arguments . getApplicationUsage ( ) - > addCommandLineOption ( " --interactive " , " Use camera manipulator to allow movement around movie. " ) ;
arguments . getApplicationUsage ( ) - > addCommandLineOption ( " --flip " , " Flip the movie so top becomes bottom. " ) ;
2007-11-17 19:50:13 +08:00
arguments . getApplicationUsage ( ) - > addCommandLineOption ( " --devices " , " Print the Video input capability via QuickTime and exit. " ) ;
2004-01-30 22:06:29 +08:00
2005-06-08 23:57:05 +08:00
bool useTextureRectangle = true ;
bool useShader = false ;
2004-01-30 22:06:29 +08:00
// construct the viewer.
2007-09-25 21:51:03 +08:00
osgViewer : : Viewer viewer ( arguments ) ;
2005-06-08 23:57:05 +08:00
2007-05-08 23:32:35 +08:00
if ( arguments . argc ( ) < = 1 )
{
arguments . getApplicationUsage ( ) - > write ( std : : cout , osg : : ApplicationUsage : : COMMAND_LINE_OPTION ) ;
return 1 ;
2007-11-17 19:50:13 +08:00
}
// if user requests devices video capability.
if ( arguments . read ( " -devices " ) | | arguments . read ( " --devices " ) )
{
// Force load QuickTime plugin, probe video capability, exit
osgDB : : readImageFile ( " devices.live " ) ;
return 1 ;
2007-05-08 23:32:35 +08:00
}
2005-06-08 23:57:05 +08:00
while ( arguments . read ( " --texture2D " ) ) useTextureRectangle = false ;
while ( arguments . read ( " --shader " ) ) useShader = true ;
2004-01-30 22:06:29 +08:00
2008-04-11 18:10:40 +08:00
bool mouseTracking = false ;
while ( arguments . read ( " --mouse " ) ) mouseTracking = true ;
2004-01-30 22:06:29 +08:00
// if user request help write it out to cout.
if ( arguments . read ( " -h " ) | | arguments . read ( " --help " ) )
{
arguments . getApplicationUsage ( ) - > write ( std : : cout ) ;
return 1 ;
}
2007-09-25 23:01:11 +08:00
bool fullscreen = ! arguments . read ( " --interactive " ) ;
2007-09-26 01:01:16 +08:00
bool flip = arguments . read ( " --flip " ) ;
2005-06-08 23:57:05 +08:00
2007-09-25 23:01:11 +08:00
osg : : ref_ptr < osg : : Geode > geode = new osg : : Geode ;
2007-05-08 23:32:35 +08:00
2007-09-25 23:01:11 +08:00
osg : : StateSet * stateset = geode - > getOrCreateStateSet ( ) ;
stateset - > setMode ( GL_LIGHTING , osg : : StateAttribute : : OFF ) ;
2007-05-08 23:32:35 +08:00
2007-09-25 23:01:11 +08:00
if ( useShader )
{
//useTextureRectangle = false;
static const char * shaderSourceTextureRec = {
" uniform vec4 cutoff_color; \n "
" uniform samplerRect movie_texture; \n "
" void main(void) \n "
" { \n "
" vec4 texture_color = textureRect(movie_texture, gl_TexCoord[0]); \n "
" if (all(lessThanEqual(texture_color,cutoff_color))) discard; \n "
" gl_FragColor = texture_color; \n "
" } \n "
} ;
static const char * shaderSourceTexture2D = {
" uniform vec4 cutoff_color; \n "
" uniform sampler2D movie_texture; \n "
" void main(void) \n "
" { \n "
" vec4 texture_color = texture2D(movie_texture, gl_TexCoord[0]); \n "
" if (all(lessThanEqual(texture_color,cutoff_color))) discard; \n "
" gl_FragColor = texture_color; \n "
" } \n "
} ;
osg : : Program * program = new osg : : Program ;
program - > addShader ( new osg : : Shader ( osg : : Shader : : FRAGMENT ,
useTextureRectangle ? shaderSourceTextureRec : shaderSourceTexture2D ) ) ;
stateset - > addUniform ( new osg : : Uniform ( " cutoff_color " , osg : : Vec4 ( 0.1f , 0.1f , 0.1f , 1.0f ) ) ) ;
stateset - > addUniform ( new osg : : Uniform ( " movie_texture " , 0 ) ) ;
stateset - > setAttribute ( program ) ;
2007-05-08 23:32:35 +08:00
2007-09-25 23:01:11 +08:00
}
2007-05-08 23:32:35 +08:00
2007-09-25 23:01:11 +08:00
osg : : Vec3 pos ( 0.0f , 0.0f , 0.0f ) ;
osg : : Vec3 topleft = pos ;
osg : : Vec3 bottomright = pos ;
bool xyPlane = fullscreen ;
for ( int i = 1 ; i < arguments . argc ( ) ; + + i )
{
if ( arguments . isString ( i ) )
2004-03-13 04:23:55 +08:00
{
2007-09-25 23:01:11 +08:00
osg : : Image * image = osgDB : : readImageFile ( arguments [ i ] ) ;
osg : : ImageStream * imagestream = dynamic_cast < osg : : ImageStream * > ( image ) ;
if ( imagestream ) imagestream - > play ( ) ;
2007-05-08 20:18:57 +08:00
2007-09-25 23:01:11 +08:00
if ( image )
{
2008-07-22 23:58:40 +08:00
osg : : notify ( osg : : NOTICE ) < < " image->s() " < < image - > s ( ) < < " image-t()= " < < image - > t ( ) < < std : : endl ;
2007-09-26 01:01:16 +08:00
geode - > addDrawable ( myCreateTexturedQuadGeometry ( pos , image - > s ( ) , image - > t ( ) , image , useTextureRectangle , xyPlane , flip ) ) ;
2007-09-25 23:01:11 +08:00
bottomright = pos + osg : : Vec3 ( static_cast < float > ( image - > s ( ) ) , static_cast < float > ( image - > t ( ) ) , 0.0f ) ;
2007-05-08 20:18:57 +08:00
2008-07-22 23:58:40 +08:00
if ( xyPlane ) pos . y ( ) + = image - > t ( ) * 1.05f ;
else pos . z ( ) + = image - > t ( ) * 1.05f ;
2005-04-22 23:44:21 +08:00
}
2007-09-25 23:01:11 +08:00
else
{
std : : cout < < " Unable to read file " < < arguments [ i ] < < std : : endl ;
}
2005-04-22 23:44:21 +08:00
}
}
2007-09-25 23:01:11 +08:00
// set the scene to render
viewer . setSceneData ( geode . get ( ) ) ;
if ( viewer . getSceneData ( ) = = 0 )
{
arguments . getApplicationUsage ( ) - > write ( std : : cout ) ;
return 1 ;
}
2004-03-13 04:23:55 +08:00
2004-03-13 05:04:20 +08:00
// pass the model to the MovieEventHandler so it can pick out ImageStream's to manipulate.
2006-01-13 06:43:36 +08:00
MovieEventHandler * meh = new MovieEventHandler ( ) ;
2008-04-11 18:10:40 +08:00
meh - > setMouseTracking ( mouseTracking ) ;
2007-12-07 01:53:22 +08:00
meh - > set ( viewer . getSceneData ( ) ) ;
viewer . addEventHandler ( meh ) ;
viewer . addEventHandler ( new osgViewer : : StatsHandler ) ;
viewer . addEventHandler ( new osgGA : : StateSetManipulator ( viewer . getCamera ( ) - > getOrCreateStateSet ( ) ) ) ;
viewer . addEventHandler ( new osgViewer : : WindowSizeHandler ) ;
// add the record camera path handler
viewer . addEventHandler ( new osgViewer : : RecordCameraPathHandler ) ;
2004-03-13 04:23:55 +08:00
2007-12-11 01:30:18 +08:00
// report any errors if they have occurred when parsing the program arguments.
2004-01-30 22:06:29 +08:00
if ( arguments . errors ( ) )
{
arguments . writeErrorMessages ( std : : cout ) ;
return 1 ;
}
2007-09-25 23:01:11 +08:00
if ( fullscreen )
{
viewer . realize ( ) ;
2007-05-08 20:18:57 +08:00
2007-09-25 23:01:11 +08:00
viewer . getCamera ( ) - > setViewMatrix ( osg : : Matrix : : identity ( ) ) ;
viewer . getCamera ( ) - > setProjectionMatrixAsOrtho2D ( topleft . x ( ) , bottomright . x ( ) , topleft . y ( ) , bottomright . y ( ) ) ;
2004-01-30 22:06:29 +08:00
2007-09-25 23:01:11 +08:00
while ( ! viewer . done ( ) )
{
viewer . frame ( ) ;
}
return 0 ;
}
else
{
// create the windows and run the threads.
return viewer . run ( ) ;
}
2004-01-30 22:06:29 +08:00
}