From 38f938619e3d3320b266c0443f7b7c704667b71c Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Wed, 24 Nov 2004 19:10:44 +0000 Subject: [PATCH] from Mike Weiblen, added wrap mode to planet texture to avoid black seam, and add option of specifying the texture to use in osgshape. --- examples/osgplanets/osgplanets.cpp | 10 ++++++++-- examples/osgshape/osgshape.cpp | 20 ++++++++++++++++---- 2 files changed, 24 insertions(+), 6 deletions(-) diff --git a/examples/osgplanets/osgplanets.cpp b/examples/osgplanets/osgplanets.cpp index a32b24b2a..5324789ef 100644 --- a/examples/osgplanets/osgplanets.cpp +++ b/examples/osgplanets/osgplanets.cpp @@ -455,7 +455,10 @@ osg::Geode* SolarSystem::createPlanet( double radius, const std::string& name, c osg::Image* image = osgDB::readImageFile( textureName ); if ( image ) { - geodePlanet->getOrCreateStateSet()->setTextureAttributeAndModes( 0, new osg::Texture2D( image ), osg::StateAttribute::ON ); + osg::Texture2D* tex2d = new osg::Texture2D( image ); + tex2d->setWrap( osg::Texture::WRAP_S, osg::Texture::REPEAT ); + tex2d->setWrap( osg::Texture::WRAP_T, osg::Texture::REPEAT ); + geodePlanet->getOrCreateStateSet()->setTextureAttributeAndModes( 0, tex2d, osg::StateAttribute::ON ); // reset the object color to white to allow the texture to set the colour. //sPlanetSphere->setColor( osg::Vec4(1.0f,1.0f,1.0f,1.0f) ); @@ -491,7 +494,10 @@ osg::Geode* SolarSystem::createPlanet( double radius, const std::string& name, c texenv->setOperand2_RGB(osg::TexEnvCombine::SRC_COLOR); stateset->setTextureAttribute( 1, texenv ); - stateset->setTextureAttributeAndModes( 1, new osg::Texture2D( image ), osg::StateAttribute::ON ); + osg::Texture2D* tex2d = new osg::Texture2D( image ); + tex2d->setWrap( osg::Texture::WRAP_S, osg::Texture::REPEAT ); + tex2d->setWrap( osg::Texture::WRAP_T, osg::Texture::REPEAT ); + stateset->setTextureAttributeAndModes( 1, tex2d, osg::StateAttribute::ON ); } } diff --git a/examples/osgshape/osgshape.cpp b/examples/osgshape/osgshape.cpp index 35d191784..a8f9d4edb 100644 --- a/examples/osgshape/osgshape.cpp +++ b/examples/osgshape/osgshape.cpp @@ -12,7 +12,7 @@ // for the grid data.. #include "../osghangglide/terrain_coords.h" -osg::Geode* createShapes() +osg::Geode* createShapes( char* img_filename ) { osg::Geode* geode = new osg::Geode(); @@ -21,7 +21,9 @@ osg::Geode* createShapes() // --------------------------------------- osg::StateSet* stateset = new osg::StateSet(); - osg::Image* image = osgDB::readImageFile("Images/lz.rgb"); + if( ! img_filename ) img_filename = "Images/lz.rgb"; + osg::Image* image = osgDB::readImageFile( img_filename ); + if (image) { osg::Texture2D* texture = new osg::Texture2D; @@ -91,7 +93,7 @@ int main( int argc, char **argv ) // set up the usage document, in case we need to print out how to use this program. arguments.getApplicationUsage()->setDescription(arguments.getApplicationName()+" is the example which demonstrates the osg::Shape classes."); - arguments.getApplicationUsage()->setCommandLineUsage(arguments.getApplicationName()+" [options] filename ..."); + arguments.getApplicationUsage()->setCommandLineUsage(arguments.getApplicationName()+" [options] [image_filename]"); arguments.getApplicationUsage()->addCommandLineOption("-h or --help","Display this information"); // construct the viewer. @@ -119,8 +121,18 @@ int main( int argc, char **argv ) arguments.writeErrorMessages(std::cout); return 1; } + + char* img_filename = 0; + for( int pos = 1; pos < arguments.argc(); ++pos ) + { + if( arguments.isString(pos) ) + { + img_filename = arguments[pos]; + break; + } + } - osg::Node* node = createShapes(); + osg::Node* node = createShapes( img_filename ); // add model to viewer. viewer.setSceneData( node );