Index: GTP/trunk/App/Demos/Geom/Demo_LodTrees/main.cpp
===================================================================
--- GTP/trunk/App/Demos/Geom/Demo_LodTrees/main.cpp	(revision 1813)
+++ GTP/trunk/App/Demos/Geom/Demo_LodTrees/main.cpp	(revision 1840)
@@ -21,4 +21,7 @@
 #define dist_max 800
 
+#define ENABLE_TERRAIN_SHADOWS
+#define TERRAIN_SHADOW_SIZE 2048
+
 //Global variables
 Geometry::GeoMeshLoader *meshloader=NULL;
@@ -35,4 +38,7 @@
 OverlayElement* mInfo2;
 OverlayElement* mHelp;
+Ogre::Light *theLight = NULL;
+Ogre::Viewport *shadowViewport = NULL;
+RenderTarget *render_target = NULL;
 
 char HelpString[]="(F1) Quit Help\n"
@@ -78,11 +84,4 @@
 	bool frameStarted(const FrameEvent& evt)
     {
-		static bool firstFrame=true;
-		if (firstFrame)
-		{
-			CalculateShadowMap();
-			firstFrame=false;
-		}
-
 		// Move upto 80 units/second
 		Real MoveFactor = 120.0 * evt.timeSinceLastFrame;
@@ -133,5 +132,5 @@
 				lodfactor=1.0f;
 
-			if (fabsf(lodfactorBefore[i]-lodfactor)>0.1f)
+			if (fabsf(lodfactorBefore[i]-lodfactor)>0.05f)
 			{
 				lod_tree_types[i]->GoToLod(lodfactor);
@@ -216,8 +215,4 @@
 		return true;
     }
-
-	void CalculateShadowMap(void)
-	{
-	}
 };
 
@@ -253,5 +248,7 @@
 
 
-class LodTreeApplication : public ExampleApplication
+#include "OgreTerrainSceneManager.h" 
+
+class LodTreeApplication : public ExampleApplication, public RenderTargetListener
 {
 protected:
@@ -270,8 +267,31 @@
     void chooseSceneManager(void)
     {
-        // Get the SceneManager, in this case a generic one
-	//	mSceneMgr = mRoot->getSceneManager(Ogre::ST_EXTERIOR_CLOSE);
         mSceneMgr = mRoot->createSceneManager("TerrainSceneManager");
     }
+
+    // render target events
+    void preRenderTargetUpdate(const RenderTargetEvent& evt)
+    {
+		if (render_target)
+		{
+			(static_cast<TerrainSceneManager*>(mSceneMgr))->getTerrainRootNode()->setVisible(false);
+			mSceneMgr->setSkyBox(false, "Examples/CloudyNoonSkyBox");
+			mSceneMgr->setFog(FOG_EXP, Ogre::ColourValue(0.5f,0.5f,0.5f), 1000 );
+			mInfo2->hide();
+		}
+    }
+    void postRenderTargetUpdate(const RenderTargetEvent& evt)
+    {
+		if (render_target)
+		{
+			(static_cast<TerrainSceneManager*>(mSceneMgr))->getTerrainRootNode()->setVisible(true);
+			mSceneMgr->setSkyBox(true, "Examples/CloudyNoonSkyBox");
+			mSceneMgr->setFog( FOG_EXP, Ogre::ColourValue(0.4f,0.5f,0.6f), 0.001 );
+			mInfo2->show();
+//			render_target->removeAllListeners();
+//			render_target->removeAllViewports();
+			render_target->setAutoUpdated(false);
+		}
+	}
 
 
@@ -285,15 +305,14 @@
 		theCam->setNearClipDistance(0.1f);
 
-		mSceneMgr->setFog( FOG_EXP, Ogre::ColourValue(0.4f,0.5f,0.6f), 0.001 );
+//		mSceneMgr->setFog( FOG_EXP, Ogre::ColourValue(0.4f,0.5f,0.6f), 0.001 );
 
         // Create a directional light
-		Light* l = mSceneMgr->createLight("MainLight");
-		l->setType(Light::LT_DIRECTIONAL);
-        l->setDirection(0.1,-1.0,-0.2);
+		theLight = mSceneMgr->createLight("MainLight");
+		theLight->setType(Light::LT_DIRECTIONAL);
+        theLight->setDirection(0.1,-1.0,-0.2);		
         
 		// terrain
 		mSceneMgr->setWorldGeometry( "terrain.cfg" );
-
-       
+     
         mSceneMgr->setSkyBox(true, "Examples/CloudyNoonSkyBox");
 
@@ -343,22 +362,38 @@
 		mInfo->setCaption("\nMaintain F2 to disable LOD");
 
+#ifdef ENABLE_TERRAIN_SHADOWS
+
 		// create the shadow texture
 		TexturePtr shadow_map = Ogre::TextureManager::getSingleton().createManual("TheShadowMap",
 			ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME,TEX_TYPE_2D,
-			256,256,0,PF_R8G8B8,TU_STATIC_WRITE_ONLY|TU_RENDERTARGET);
-
-/*		// en vez de crear la textura aqui se puee intentar cargar de fichero una y modificarla
+			TERRAIN_SHADOW_SIZE,TERRAIN_SHADOW_SIZE,0,PF_R8G8B8,TU_RENDERTARGET);
+
 		HardwarePixelBufferSharedPtr shadowBuffer = shadow_map->getBuffer();
-		RenderTarget *render_target = shadowBuffer->getRenderTarget();*/
-
-		HardwarePixelBufferSharedPtr shadowBuffer = shadow_map->getBuffer();
-		RenderTarget *render_target = shadowBuffer->getRenderTarget();
-
-
-//		RenderTarget *rttTex = shadow_map->getBuffer()->getRenderTarget();
-//			mSceneMgr->createCamera("lightCam");
-	
-
-
+		render_target = shadowBuffer->getRenderTarget();
+
+		Ogre::Camera *lightCam = mSceneMgr->createCamera("lightCam");
+		lightCam->setProjectionType(Ogre::PT_ORTHOGRAPHIC);
+		lightCam->setAspectRatio(1.0);
+		lightCam->setFOVy(Degree(164));
+		lightCam->rotate(Vector3(1,0,0),Degree(-90));
+		lightCam->move(BS_center+Ogre::Vector3(-50,400,78));
+
+		shadowViewport = render_target->addViewport(lightCam);
+		shadowViewport->setClearEveryFrame(true);
+		shadowViewport->setBackgroundColour(ColourValue::White);
+
+		render_target->addListener(this);
+
+		MaterialPtr terrainMat = MaterialManager::getSingleton().getByName("Demos/TerrainMixed");
+		Ogre::Pass *thePass = terrainMat->getTechnique(0)->createPass();
+		thePass->setSceneBlending(Ogre::SBT_MODULATE);
+		Ogre::TextureUnitState *texState = thePass->createTextureUnitState();
+		texState->setTextureName("TheShadowMap");
+		thePass->_load();
+
+		terrainMat->compile();
+		terrainMat->load();
+
+#endif
     }
 
Index: GTP/trunk/App/Demos/Geom/Demo_LodTrees/Demo_LodTrees.vcproj
===================================================================
--- GTP/trunk/App/Demos/Geom/Demo_LodTrees/Demo_LodTrees.vcproj	(revision 1321)
+++ GTP/trunk/App/Demos/Geom/Demo_LodTrees/Demo_LodTrees.vcproj	(revision 1840)
@@ -21,5 +21,5 @@
 				Optimization="0"
 				ImproveFloatingPointConsistency="TRUE"
-				AdditionalIncludeDirectories="..\OgreStuff\include;..\..\..\..\Lib\Geom\shared\GTGeometry\include"
+				AdditionalIncludeDirectories="..\OgreStuff\include;..\..\..\..\Lib\Geom\shared\GTGeometry\include;..\OgreStuff\include\opt"
 				PreprocessorDefinitions="WIN32;_DEBUG;_WINDOWS"
 				MinimalRebuild="TRUE"
@@ -35,8 +35,8 @@
 			<Tool
 				Name="VCLinkerTool"
-				AdditionalDependencies="OgreMain_d.lib GTGeometry_d.lib"
+				AdditionalDependencies="OgreMain_d.lib GTGeometry_d.lib Plugin_OctreeSceneManager.lib"
 				OutputFile="$(OutDir)/Demo_LodTrees.exe"
 				LinkIncremental="2"
-				AdditionalLibraryDirectories="..\OgreStuff\lib;..\..\..\..\Lib\Geom\shared\GTGeometry\build\Debug\"
+				AdditionalLibraryDirectories="..\OgreStuff\lib;..\..\..\..\Lib\Geom\shared\GTGeometry\build\Debug\;..\OgreStuff\lib\opt\debug\"
 				GenerateDebugInformation="TRUE"
 				ProgramDatabaseFile="$(OutDir)/Demo_LodTrees.pdb"
@@ -48,5 +48,6 @@
 				Name="VCPostBuildEventTool"
 				CommandLine="xcopy /Y ..\OgreStuff\bin\Debug\*.dll build\Debug
-xcopy /Y ..\OgreStuff\bin\Debug\*.cfg build\Debug"/>
+xcopy /Y ..\OgreStuff\bin\Debug\*.cfg build\Debug
+"/>
 			<Tool
 				Name="VCPreBuildEventTool"/>
@@ -74,5 +75,5 @@
 			<Tool
 				Name="VCCLCompilerTool"
-				AdditionalIncludeDirectories="..\OgreStuff\include;..\..\..\..\Lib\Geom\shared\GTGeometry\include"
+				AdditionalIncludeDirectories="..\OgreStuff\include;..\..\..\..\Lib\Geom\shared\GTGeometry\include;..\OgreStuff\include\opt"
 				PreprocessorDefinitions="WIN32;NDEBUG;_WINDOWS"
 				RuntimeLibrary="4"
@@ -85,8 +86,8 @@
 			<Tool
 				Name="VCLinkerTool"
-				AdditionalDependencies="OgreMain.lib GTGeometry.lib"
+				AdditionalDependencies="OgreMain.lib GTGeometry.lib Plugin_OctreeSceneManager.lib"
 				OutputFile="$(OutDir)/Demo_LodTrees.exe"
 				LinkIncremental="1"
-				AdditionalLibraryDirectories="..\OgreStuff\lib;..\..\..\..\Lib\Geom\shared\GTGeometry\build\Release\"
+				AdditionalLibraryDirectories="..\OgreStuff\lib;..\..\..\..\Lib\Geom\shared\GTGeometry\build\Release\;..\OgreStuff\lib\opt\debug\"
 				IgnoreDefaultLibraryNames=""
 				GenerateDebugInformation="TRUE"
@@ -100,5 +101,6 @@
 				Name="VCPostBuildEventTool"
 				CommandLine="xcopy /Y ..\OgreStuff\bin\Release\*.dll build\Release
-xcopy /Y ..\OgreStuff\bin\Release\*.cfg build\Release"/>
+xcopy /Y ..\OgreStuff\bin\Release\*.cfg build\Release
+"/>
 			<Tool
 				Name="VCPreBuildEventTool"/>
