Index: trunk/VUT/GtpVisibility/include/QueryManager.h
===================================================================
--- trunk/VUT/GtpVisibility/include/QueryManager.h	(revision 143)
+++ trunk/VUT/GtpVisibility/include/QueryManager.h	(revision 144)
@@ -51,5 +51,5 @@
 			    InfoContainer<NodeInfo> *visibleNodes,
 			    InfoContainer<MeshInfo> *visibleGeometry,
-			    bool projectedPixels = false
+			    bool relativeVisibility = false
 			    ) = 0;
     
@@ -62,5 +62,5 @@
 			       InfoContainer<NodeInfo> *visibleNodes,
 			       InfoContainer<MeshInfo> *visibleGeometry,
-			       bool projectedPixels = false
+			       bool relativeVisibility = false
 			       ) = 0;
     
Index: trunk/VUT/GtpVisibility/include/VisibilityInfo.h
===================================================================
--- trunk/VUT/GtpVisibility/include/VisibilityInfo.h	(revision 143)
+++ trunk/VUT/GtpVisibility/include/VisibilityInfo.h	(revision 144)
@@ -27,4 +27,5 @@
 	HierarchyNode *GetNode() const {return mNode;}
 
+	float ComputeRelativeVisibility() { float result = mVisiblePixels; if (mProjectedPixels) result /= (float)mProjectedPixels; return result;}
 	//bool operator<(const NodeInfo& rhs) const {return mNode < rhs.mNode;}
 
Index: trunk/VUT/GtpVisibility/include/DummyQueryManager.h
===================================================================
--- trunk/VUT/GtpVisibility/include/DummyQueryManager.h	(revision 143)
+++ trunk/VUT/GtpVisibility/include/DummyQueryManager.h	(revision 144)
@@ -25,6 +25,5 @@
 			    InfoContainer<NodeInfo> *visibleNodes,
 			    InfoContainer<MeshInfo> *visibleGeometry,
-			    bool projectedPixels = false
-			    );
+			    bool relativeVisibility = false );
     
     /**
@@ -35,5 +34,5 @@
 			       InfoContainer<NodeInfo> *visibleNodes,
 			       InfoContainer<MeshInfo> *visibleGeometry,
-			       bool projectedPixels = false
+			       bool relativeVisibility = false
 			       );
     
Index: trunk/VUT/GtpVisibility/scripts/GtpVisibility.vcproj
===================================================================
--- trunk/VUT/GtpVisibility/scripts/GtpVisibility.vcproj	(revision 136)
+++ trunk/VUT/GtpVisibility/scripts/GtpVisibility.vcproj	(revision 144)
@@ -133,4 +133,7 @@
 			</File>
 			<File
+				RelativePath="..\src\VisibilityInfo.cpp">
+			</File>
+			<File
 				RelativePath="..\src\VisibilityManager.cpp">
 			</File>
Index: trunk/VUT/GtpVisibility/src/DummyQueryManager.cpp
===================================================================
--- trunk/VUT/GtpVisibility/src/DummyQueryManager.cpp	(revision 143)
+++ trunk/VUT/GtpVisibility/src/DummyQueryManager.cpp	(revision 144)
@@ -11,6 +11,5 @@
 					     InfoContainer<NodeInfo> *visibleNodes,
 					     InfoContainer<MeshInfo> *visibleGeometry,
-					     bool projectedPixels
-					     )
+					     bool relativeVisibility)
   {
 	  visibleNodes->push_back(NodeInfo(mHierarchyInterface->GetSceneRoot(), 0, 0));
@@ -30,6 +29,5 @@
 						InfoContainer<NodeInfo> *visibleNodes,
 						InfoContainer<MeshInfo> *visibleGeometry,
-						bool projectedPixels
-						)
+						bool relativeVisibility)
   {
 	  visibleNodes->push_back(NodeInfo(mHierarchyInterface->GetSceneRoot(), 0, 0));
Index: trunk/VUT/work/TestCullingTerrain/TerrainFrameListener.cpp
===================================================================
--- trunk/VUT/work/TestCullingTerrain/TerrainFrameListener.cpp	(revision 143)
+++ trunk/VUT/work/TestCullingTerrain/TerrainFrameListener.cpp	(revision 144)
@@ -353,5 +353,5 @@
 }
 //-----------------------------------------------------------------------
-void TerrainFrameListener::ApplyVisibilityQuery(bool fromPoint, bool projectedPixels)
+void TerrainFrameListener::ApplyVisibilityQuery(bool fromPoint, bool relativeVisibility)
 {
 	InfoContainer<GtpVisibility::NodeInfo> visibleNodes;
@@ -362,10 +362,10 @@
 		mVisibilityManager->GetQueryManager()->
 			ComputeFromPointVisibility(mCamNode->getPosition(), &visibleNodes, 
-									   &visibleGeometry, projectedPixels);
+									   &visibleGeometry, relativeVisibility);
 	}
 	else
 	{
 		mVisibilityManager->GetQueryManager()->ComputeCameraVisibility(*mCamera,
-			    &visibleNodes, &visibleGeometry, projectedPixels);
+			    &visibleNodes, &visibleGeometry, relativeVisibility);
 	}
 
@@ -405,5 +405,5 @@
 		//-- visibility queries stats
 		int idx = fromPoint ?  1 : 0;
-		idx += projectedPixels ? 2 : 0;
+		idx += relativeVisibility ? 2 : 0;
 
 		sprintf(str, ": %s", queryTypeCaptions[idx].c_str()); 
Index: trunk/VUT/work/TestCullingTerrain/TestCullingTerrainApplication.cpp
===================================================================
--- trunk/VUT/work/TestCullingTerrain/TestCullingTerrainApplication.cpp	(revision 139)
+++ trunk/VUT/work/TestCullingTerrain/TestCullingTerrainApplication.cpp	(revision 144)
@@ -71,5 +71,6 @@
 	bool result = ExampleApplication::setup();
 
-	createRenderTargetListener();
+	if (mWindow)
+		createRenderTargetListener();
 
 	return result;
Index: trunk/VUT/work/TestCullingTerrain/TerrainFrameListener.h
===================================================================
--- trunk/VUT/work/TestCullingTerrain/TerrainFrameListener.h	(revision 143)
+++ trunk/VUT/work/TestCullingTerrain/TerrainFrameListener.h	(revision 144)
@@ -120,5 +120,5 @@
 		visible pixels / projected pixels.
 	*/
-	void ApplyVisibilityQuery(bool fromPoint, bool projectedPixels);
+	void ApplyVisibilityQuery(bool fromPoint, bool relativeVisibility);
 
 	void toggleShowQueryStats();
Index: trunk/VUT/Ogre/include/OgrePlatformQueryManager.h
===================================================================
--- trunk/VUT/Ogre/include/OgrePlatformQueryManager.h	(revision 143)
+++ trunk/VUT/Ogre/include/OgrePlatformQueryManager.h	(revision 144)
@@ -41,5 +41,5 @@
 			    InfoContainer<GtpVisibility::NodeInfo> *visibleNodes,
 			    InfoContainer<GtpVisibility::MeshInfo> *visibleGeometry,
-			    bool projectedPixels = false
+			    bool relativeVisibility = false
 			    );
     
@@ -52,5 +52,5 @@
 			       InfoContainer<GtpVisibility::NodeInfo> *visibleNodes,
 			       InfoContainer<GtpVisibility::MeshInfo> *visibleGeometry,
-			       bool projectedPixels = false
+			       bool relativeVisibility = false
 			       );
     
@@ -73,5 +73,5 @@
 	     );  
 
-	/** Sets a viewport to render into.
+	/** Sets a viewport for rendering.
 	*/
 	void SetViewport(Viewport *vp);
Index: trunk/VUT/Ogre/src/OgrePlatformQueryManager.cpp
===================================================================
--- trunk/VUT/Ogre/src/OgrePlatformQueryManager.cpp	(revision 143)
+++ trunk/VUT/Ogre/src/OgrePlatformQueryManager.cpp	(revision 144)
@@ -23,5 +23,5 @@
 			    InfoContainer<GtpVisibility::NodeInfo> *visibleNodes,
 			    InfoContainer<GtpVisibility::MeshInfo> *visibleGeometry,
-			    bool projectedPixels)
+			    bool relativeVisibility)
 {
 	// we need access to the scene manager and the rendersystem
@@ -68,5 +68,5 @@
 	*/
 	// for relative visibility we need 2 rendering passes
-	int n = projectedPixels ? 2 : 1;
+	int n = relativeVisibility ? 2 : 1;
 	
 	for (int i=0; i<n; ++i)
@@ -104,5 +104,5 @@
 
 	//---- collect results
-	unsigned int visiblePixels = 0;
+	
 	std::pair<InfoContainer<GtpVisibility::NodeInfo>::iterator, bool> insertNode;
 	std::pair<InfoContainer<GtpVisibility::MeshInfo>::iterator, bool> insertGeom;
@@ -116,14 +116,12 @@
 	for (nodeIt = nodeList->begin(); nodeIt != nodeIt_end; ++nodeIt)
 	{
+		unsigned int visiblePixels = 0;
 		(*visQueryIt)->GetQueryResult(visiblePixels, true);
 	
-		int visiblePixels = visiblePixels;
-		int projectedPixels = 0;
-
-		if (projectedPixels)
-		{
-			(*projQueryIt)->GetQueryResult(visiblePixels, true);
-	
-			mProjectedPixels = visiblePixels;
+		unsigned int projectedPixels = 0;
+
+		if (relativeVisibility)
+		{
+			(*projQueryIt)->GetQueryResult(projectedPixels, true);
 		
 			++projQueryIt;
@@ -145,14 +143,12 @@
 	for (geometryIt = geometryList.begin(); geometryIt != geometryIt_end; ++geometryIt)
 	{
+		unsigned int visiblePixels = 0;
 		(*visQueryIt)->GetQueryResult(visiblePixels, true);
 		
-		int visiblePixels = visiblePixels;
-		int projectedPixels = 0;
-
-		if (projectedPixels)
-		{
-			(*projQueryIt)->GetQueryResult(visiblePixels, true);
-
-			mProjectedPixels = visiblePixels;
+		unsigned int projectedPixels = 0;
+
+		if (relativeVisibility)
+		{
+			(*projQueryIt)->GetQueryResult(projectedPixels, true);
 
 			++projQueryIt;
@@ -163,7 +159,8 @@
 		// approximate depth ordering during rendering => 
 		// geometry maybe occluded
-		if (isVisible)
+		if (visiblePixels > 0)
 		{			 
-			visibleGeometry->push_back(GtpVisibility::MeshInfo(*geometryIt,visiblePixels, projectedPixels));
+			visibleGeometry->push_back(GtpVisibility::MeshInfo(*geometryIt, 
+				visiblePixels, projectedPixels));
 		}
 	}
@@ -181,8 +178,18 @@
 }
 //-----------------------------------------------------------------------
+inline bool nodeinfo_lower(const GtpVisibility::NodeInfo &info1, const GtpVisibility::NodeInfo &info2) 
+{ 
+	return info1.GetNode() < info2.GetNode(); 
+}
+//-----------------------------------------------------------------------
+inline bool meshinfo_lower(const GtpVisibility::MeshInfo &info1, const GtpVisibility::MeshInfo &info2) 
+{ 
+	return info1.GetMesh() < info2.GetMesh(); 
+}
+//-----------------------------------------------------------------------
 void PlatformQueryManager::ComputeFromPointVisibility(const Vector3 &point,
 			       InfoContainer<GtpVisibility::NodeInfo> *visibleNodes,
 			       InfoContainer<GtpVisibility::MeshInfo> *visibleGeometry,
-			       bool projectedPixels)
+			       bool relativeVisibility)
 {
 	SceneManager *sm = dynamic_cast<PlatformHierarchyInterface *>(mHierarchyInterface)->GetSceneManager();
@@ -221,5 +228,5 @@
 		LogManager::getSingleton().logMessage(d.str());
 
-		ComputeCameraVisibility(*cam, visibleNodes, visibleGeometry, projectedPixels);
+		ComputeCameraVisibility(*cam, visibleNodes, visibleGeometry, relativeVisibility);
 		
 		//mViewport->getTarget()->update(); for(int j=0; j<10000000; j++)	printf("HAAHHAHAHAHAH");
@@ -240,5 +247,5 @@
 
 	// --- visible nodes
-	sort(visibleNodes->begin(), visibleNodes->end());
+	sort(visibleNodes->begin(), visibleNodes->end(), nodeinfo_lower);
 	InfoContainer<GtpVisibility::NodeInfo>::iterator visibleNodesIt,
 		visibleNodesIt_end = visibleNodes->end();
@@ -256,6 +263,9 @@
 		{
 			// add visibility
-			nodeInfo->SetVisibility(nodeInfo->GetVisiblePixels() + 
+			nodeInfo->SetVisiblePixels(nodeInfo->GetVisiblePixels() + 
 				(*visibleNodesIt).GetVisiblePixels());
+		
+			nodeInfo->SetProjectedPixels(nodeInfo->GetProjectedPixels() + 
+				(*visibleNodesIt).GetProjectedPixels());
 		}
 
@@ -267,5 +277,5 @@
 
 	// --- visible geometry
-	sort(visibleGeometry->begin(), visibleGeometry->end());
+	sort(visibleGeometry->begin(), visibleGeometry->end(), meshinfo_lower);
 	InfoContainer<GtpVisibility::MeshInfo>::iterator visibleGeomIt,
 		visibleGeomIt_end = visibleGeometry->end();
@@ -283,12 +293,15 @@
 		{
 			// add visibility
-			geomInfo->SetVisibility(geomInfo->GetVisiblePixels() + 
+			geomInfo->SetVisiblePixels(geomInfo->GetVisiblePixels() + 
 				(*visibleGeomIt).GetVisiblePixels());
+
+			geomInfo->SetProjectedPixels(nodeInfo->GetProjectedPixels() + 
+				(*visibleNodesIt).GetProjectedPixels());
 		}
 	}
 
 	// now delete duplicates
-	visibleGeometry->erase(std::unique(visibleGeometry->begin(), 
-		visibleGeometry->end(), meshinfo_eq), visibleGeometry->end());
+	visibleGeometry->erase(std::unique(visibleGeometry->begin(), visibleGeometry->end(), 
+		meshinfo_eq), visibleGeometry->end());
 	
 }
