Index: experimental/distortionNG/extViewer.cpp
===================================================================
--- experimental/distortionNG/extViewer.cpp	(revision 335)
+++ experimental/distortionNG/extViewer.cpp	(revision 336)
@@ -33,5 +33,5 @@
 }
 
-static osg::Texture* loadTexture( const std::string& fileName )
+static osg::Texture2D* loadTexture( const std::string& fileName )
 {
     std::string foundFileName = osgDB::findDataFile(fileName);
@@ -44,6 +44,34 @@
 			osg::Texture2D* texture = new osg::Texture2D;
             texture->setImage(image);
-            texture->setFilter(osg::Texture2D::MIN_FILTER, osg::Texture2D::NEAREST);
-            texture->setFilter(osg::Texture2D::MAG_FILTER, osg::Texture2D::NEAREST);
+            //texture->setFilter(osg::Texture2D::MIN_FILTER, osg::Texture2D::NEAREST);
+            //texture->setFilter(osg::Texture2D::MAG_FILTER, osg::Texture2D::NEAREST);
+            //texture->setWrap(osg::Texture2D::WRAP_S, osg::Texture2D::CLAMP_TO_EDGE);
+            //texture->setWrap(osg::Texture2D::WRAP_T, osg::Texture2D::CLAMP_TO_EDGE);
+			texture->setFilter(osg::Texture::MIN_FILTER,osg::Texture::LINEAR);
+			texture->setFilter(osg::Texture::MAG_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);
+            return texture;
+        }
+    }
+
+    OSG_NOTIFY(osg::WARN) << "File \"" << fileName << "\" not found." << std::endl;
+
+    return NULL;
+}
+
+static osg::TextureRectangle* loadTextureRect( const std::string& fileName )
+{
+    std::string foundFileName = osgDB::findDataFile(fileName);
+    if (foundFileName.length() != 0 )
+    {
+        // load distortion map texture file
+        osg::Image* image = osgDB::readImageFile(foundFileName);
+        if (image)
+        {
+			osg::TextureRectangle* texture = new osg::TextureRectangle;
+            texture->setImage(image);
+            texture->setFilter(osg::Texture2D::MIN_FILTER, osg::Texture2D::LINEAR);
+            texture->setFilter(osg::Texture2D::MAG_FILTER, osg::Texture2D::LINEAR);
             texture->setWrap(osg::Texture2D::WRAP_S, osg::Texture2D::CLAMP_TO_EDGE);
             texture->setWrap(osg::Texture2D::WRAP_T, osg::Texture2D::CLAMP_TO_EDGE);
@@ -135,24 +163,4 @@
 		geom->addPrimitiveSet( de.get() );
 	}
-
-	//if (intensityMap && !applyIntensityMapAsColours)
-	//{
-	//	// create shaders for distortion
-	//	osg::Program* distortProgram = new osg::Program;
-	//	distortProgram->setName( "distortion" );
-	//	osg::Shader* vShader = osg::Shader::readShaderFile( osg::Shader::VERTEX, "shader.vert" ); 
-	//	vShader->setName("intensityMapVertShader");
-	//	osg::Shader* fShader = osg::Shader::readShaderFile( osg::Shader::FRAGMENT, "shader.frag" ); 
-	//	fShader->setName("intensityMapFragShader");
-
-	//	if ( vShader && fShader )
-	//	{
-	//		//distortProgram->addShader( vShader );
-	//		distortProgram->addShader( fShader );
-	//		geom->getOrCreateStateSet()->addUniform( new osg::Uniform("sceneTexture", 0) );
-	//		geom->getOrCreateStateSet()->addUniform( new osg::Uniform("intensityMapTexture", 1) );
-	//		geom->getOrCreateStateSet()->setAttributeAndModes(distortProgram, osg::StateAttribute::ON);
-	//	}
-	//}
 
 	return geom.release();
@@ -261,33 +269,28 @@
 		// new we need to add the scene texture to the mesh, we do so by creating a
         // StateSet to contain the Texture StateAttribute.
-        osg::StateSet* stateset = geode->getOrCreateStateSet();
-        //stateset->setTextureAttributeAndModes(0, sceneTexture,osg::StateAttribute::ON);
-        //stateset->setMode(GL_LIGHTING,osg::StateAttribute::OFF);
-
-		//osg::TexMat* texmat = new osg::TexMat;
-  //      texmat->setScaleByTextureRectangleSize(true);
-  //      stateset->setTextureAttributeAndModes(0, texmat, osg::StateAttribute::ON);
+	    osg::StateSet* stateset = geode->getOrCreateStateSet();
+        stateset->setTextureAttributeAndModes(0, sceneTexture,osg::StateAttribute::ON);
+        stateset->setMode(GL_LIGHTING,osg::StateAttribute::OFF);
+
+		osg::TexMat* texmat = new osg::TexMat;
+        texmat->setScaleByTextureRectangleSize(true);
+        stateset->setTextureAttributeAndModes(0, texmat, osg::StateAttribute::ON);
 
 		// If the intensityMap is used but not applyIntensityMapAsColours: Apply intensityMap as intensityMapTexture on unit 1
 		if (!applyIntensityMapAsColours && intensityMap)
         {
-			osg::Texture2D* intensityMapTexture = new osg::Texture2D(intensityMap);
-            intensityMapTexture->setFilter(osg::Texture2D::MIN_FILTER, osg::Texture2D::NEAREST);
-            intensityMapTexture->setFilter(osg::Texture2D::MAG_FILTER, osg::Texture2D::NEAREST);
-            intensityMapTexture->setWrap(osg::Texture2D::WRAP_S, osg::Texture2D::CLAMP_TO_EDGE);
-            intensityMapTexture->setWrap(osg::Texture2D::WRAP_T, osg::Texture2D::CLAMP_TO_EDGE);
+			osg::TextureRectangle* intensityMapTexture = new osg::TextureRectangle(intensityMap);
+			intensityMapTexture->setTextureSize(tex_width, tex_height);
+			//intensityMapTexture->setInternalFormat(GL_RGB);
+		 //   intensityMapTexture->setFilter(osg::Texture::MIN_FILTER,osg::Texture::LINEAR);
+			//intensityMapTexture->setFilter(osg::Texture::MAG_FILTER,osg::Texture::LINEAR);
+			intensityMapTexture->setWrap(osg::Texture::WRAP_S,osg::Texture::CLAMP_TO_EDGE);
+			intensityMapTexture->setWrap(osg::Texture::WRAP_T,osg::Texture::CLAMP_TO_EDGE);
 
             stateset->setTextureAttributeAndModes(1, intensityMapTexture, osg::StateAttribute::ON);
 
-			osg::Texture* tmp = loadTexture( "test.jpg" );
-			if(tmp)
-			{
-				stateset->setTextureAttributeAndModes(0, tmp,osg::StateAttribute::ON);
-
-				osg::TexMat* texmat = new osg::TexMat;
-				texmat->setScaleByTextureRectangleSize(true);
-				stateset->setTextureAttributeAndModes(0, texmat, osg::StateAttribute::ON);
-			}
-
+			//osg::TexMat* texmat1 = new osg::TexMat;
+			//texmat1->setScaleByTextureRectangleSize(true);
+			//stateset->setTextureAttributeAndModes(1, texmat1, osg::StateAttribute::ON);
         }
 
@@ -319,5 +322,5 @@
         camera->setGraphicsContext(gc.get());
         camera->setClearMask(GL_DEPTH_BUFFER_BIT | GL_COLOR_BUFFER_BIT );
-        camera->setClearColor( osg::Vec4(0.0,1.0,0.0,1.0) );
+        camera->setClearColor( osg::Vec4(0.0,0.0,0.0,1.0) );
         camera->setViewport(new osg::Viewport(0, 0, width, height));
         GLenum buffer = traits->doubleBuffer ? GL_BACK : GL_FRONT;
