Index: trunk/VUT/OcclusionCullingSceneManager/include/OgreSolidHalfBoundingBox.h
===================================================================
--- trunk/VUT/OcclusionCullingSceneManager/include/OgreSolidHalfBoundingBox.h	(revision 51)
+++ trunk/VUT/OcclusionCullingSceneManager/include/OgreSolidHalfBoundingBox.h	(revision 54)
@@ -17,6 +17,6 @@
 	public:
 
-		SolidHalfBoundingBox(bool isFirstHalf);
-		void setupBoundingBox(const AxisAlignedBox& aabb);
+		SolidHalfBoundingBox( bool isFirstHalf );
+		void setupBoundingBox( const AxisAlignedBox& aabb );
 		/** Override this method to prevent parent transforms (rotation,translation,scale)
 		and to make it public.
@@ -29,6 +29,13 @@
 		@param the axis aligned bounding box for setting up the list.
         */
-		void setupBoundingBoxVertices(const AxisAlignedBox& aab);
-
+		void setupBoundingBoxVertices( const AxisAlignedBox& aab );
+		/** 
+			Sets the material used for occlusion queries. 
+			@remarks the material is called "OcclusionQuery" and
+			uses no lighting, no depth write, and no colours
+		*/
+		void setOcclusionQueryMaterial( void );
+		/** Whether this half box is the first or the second half of the bounding box. 
+		*/
 		bool mIsFirstHalf;	
 	};
Index: trunk/VUT/OcclusionCullingSceneManager/src/OgreSolidHalfBoundingBox.cpp
===================================================================
--- trunk/VUT/OcclusionCullingSceneManager/src/OgreSolidHalfBoundingBox.cpp	(revision 51)
+++ trunk/VUT/OcclusionCullingSceneManager/src/OgreSolidHalfBoundingBox.cpp	(revision 54)
@@ -5,4 +5,5 @@
 #include "OgreHardwareBufferManager.h"
 #include "OgreCamera.h"
+#include "OgreMaterialManager.h"
 //#include <windows.h>
 
@@ -13,4 +14,6 @@
 		:WireBoundingBox(), mIsFirstHalf(isFirstHalf)
     {
+		setOcclusionQueryMaterial();
+		
 		mRenderOp.vertexData->vertexCount = 8;
         mRenderOp.operationType = RenderOperation::OT_TRIANGLE_FAN; 
@@ -95,4 +98,21 @@
         *xform = Matrix4::IDENTITY;
     }
+
+	void SolidHalfBoundingBox::setOcclusionQueryMaterial( void )
+	{
+		m_pMaterial = MaterialManager::getSingleton().getByName("OcclusionQuery");
+
+		if(m_pMaterial.isNull())
+		{
+			m_pMaterial = MaterialManager::getSingleton().
+				create("OcclusionQuery", ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME);
+		}
+
+		m_pMaterial->setColourWriteEnabled(false);
+		m_pMaterial->setDepthWriteEnabled(false);
+		m_pMaterial->setLightingEnabled(false);
+
+		setMaterial("OcclusionQuery");
+	}
 }
 
Index: trunk/VUT/OcclusionCullingSceneManager/src/OgreOcclusionCullingSceneTraverser.cpp
===================================================================
--- trunk/VUT/OcclusionCullingSceneManager/src/OgreOcclusionCullingSceneTraverser.cpp	(revision 52)
+++ trunk/VUT/OcclusionCullingSceneManager/src/OgreOcclusionCullingSceneTraverser.cpp	(revision 54)
@@ -44,11 +44,4 @@
 
 		initDistanceQueue(cam);
-
-		//deleteQueries();
-		//char *msg = "deleting queries\n"; OutputDebugString(msg);
-        //for(unsigned int i=0; i < 1000; i++)
-		//mOcclusionQueries.push_back(mRenderSystem->createHardwareOcclusionQuery());
-
-	    //mCurrentAlgorithm = RENDER_CULL_FRUSTUM;
 
 		switch(mCurrentAlgorithm)
@@ -235,6 +228,6 @@
 		// TODO: in rendervisibleobjects, the rendermode is changed by ogre itself => change this!!
 		
-		setRenderingMode(MODE_QUERY);
-		//mRenderSystem->_setRasterisationMode(SDL_SOLID);setRenderingMode(MODE_RENDER);
+		//setRenderingMode(MODE_QUERY);
+		//mRenderSystem->_setRasterisationMode(SDL_SOLID); setRenderingMode(MODE_RENDER);
 
 		// get next available test id
@@ -247,10 +240,9 @@
 
 		query->endOcclusionQuery();
-
-		
-		//mRenderSystem->_setRasterisationMode(SDL_WIREFRAME);
+	
+		/*mRenderSystem->_setRasterisationMode(SDL_WIREFRAME);
 		setRenderingMode(MODE_RENDER);
 		renderBoundingBox(box);
-		//mRenderSystem->_setRasterisationMode(SDL_SOLID);
+		mRenderSystem->_setRasterisationMode(SDL_SOLID);*/
 		
 		return query;
@@ -278,5 +270,5 @@
           	mRenderSystem->_setColourBufferWriteEnabled(enabled, enabled, enabled, enabled);
 			mRenderSystem->_setDepthBufferWriteEnabled(enabled);
-			mRenderSystem->setLightingEnabled(enabled);
+			//mRenderSystem->setLightingEnabled(enabled);
 		}
 	}
@@ -304,5 +296,5 @@
 	{
 		//TODO: does not do any changes
-		setRenderingMode(MODE_RENDER);
+		//setRenderingMode(MODE_RENDER);
 		
 		if(node->lastRendered() != node->lastVisited())
@@ -383,8 +375,7 @@
 			halfbox->setupBoundingBox(*box);
 			
-			mRenderSystem->_setWorldMatrix(Matrix4::IDENTITY);
-
-			// Set world transformation
-			/*halfbox->getWorldTransforms(xform);
+			/*mRenderSystem->_setWorldMatrix(Matrix4::IDENTITY);
+
+			halfbox->getWorldTransforms(xform);
 
 			int numMatrices = halfbox->getNumWorldTransforms();
@@ -397,5 +388,5 @@
 				mRenderSystem->_setWorldMatrix(*xform);
 			}
-			mRenderSystem->setClipPlanes(halfbox->getClipPlanes());*/
+			mRenderSystem->setClipPlanes(halfbox->getClipPlanes());
 
 			static RenderOperation ro;
@@ -404,7 +395,8 @@
 			halfbox->getRenderOperation(ro);
 			ro.srcRenderable = halfbox; 
-			mRenderSystem->_render(ro);
-
-			//mSceneManager->myrenderSingleObject(getSolidHalfBoundingBox(half), getSolidHalfBoundingBox(half)->getTechnique()->getPass(0), true);
+			mRenderSystem->_render(ro);*/
+			
+			mSceneManager->myrenderSingleObject(getSolidHalfBoundingBox(half), 
+				getSolidHalfBoundingBox(half)->getTechnique()->getPass(0), true);
 		}
 	}
@@ -444,5 +436,4 @@
 		{
 			mOcclusionQueries.push_back(mRenderSystem->createHardwareOcclusionQuery());
-			//char *msg = "creating query!!\n"; OutputDebugString(msg);
 		}
 		
Index: trunk/VUT/OcclusionCullingSceneManager/src/OgreOcclusionCullingOctreeSceneTraverser.cpp
===================================================================
--- trunk/VUT/OcclusionCullingSceneManager/src/OgreOcclusionCullingOctreeSceneTraverser.cpp	(revision 52)
+++ trunk/VUT/OcclusionCullingSceneManager/src/OgreOcclusionCullingOctreeSceneTraverser.cpp	(revision 54)
@@ -28,8 +28,4 @@
 		{
 			Octree *nextChild = octant->mChildren[(i & 4) >> 2][(i & 2) >> 1][i & 1];
-
-			/*char msg[100];
-			sprintf(msg, "node number: %d %d %d\n", (i & 4) >> 2, (i & 2) >> 1, i & 1);
-			OutputDebugString(msg);*/
 
 			if(nextChild)
@@ -59,4 +55,7 @@
 			}
 
+			mRenderSystem->_setRasterisationMode(SDL_WIREFRAME);
+			renderBoundingBox(&box);
+			mRenderSystem->_setRasterisationMode(SDL_SOLID);
 			// update node's visited flag 
 			octant->setLastVisited(mFrameId);
@@ -86,11 +85,4 @@
 			bool intersects = false;
 
-			/*char msg2[100];
-			Vector3 min = box.getMinimum();
-			Vector3 max = box.getMaximum();
-
-			sprintf(msg2, "culling box: %3.3f %3.3f %3.3f %3.3f %3.3f %3.3f\n", min.x, min.y, min.z, max.x, max.y, max.z);
-			OutputDebugString(msg2);*/
-
 			if(!cam->isVisible(box, intersects))
 			{
@@ -102,6 +94,4 @@
 			{
 				octant->setOctreeVisible(true);
-			//	char msg[100]; sprintf(msg, "intersecting\n");
-			//	OutputDebugString(msg);
 				traverseOctant(cam, octant);
 				continue;
@@ -114,6 +104,6 @@
 			query->pullOcclusionQuery(&visiblePixels);
 
-			char msg[100]; sprintf(msg, "visible pixels: %d\n", visiblePixels, intersects);
-			OutputDebugString(msg);
+			//char msg[100]; sprintf(msg, "visible pixels: %d\n", visiblePixels);
+			//OutputDebugString(msg);
 
 			// node visible
@@ -124,4 +114,13 @@
 			else
 			{
+				/*
+				char msg2[100];
+				Vector3 min = box.getMinimum();
+				Vector3 max = box.getMaximum();
+
+				sprintf(msg2, "culling box: %3.3f %3.3f %3.3f %3.3f %3.3f %3.3f\n", min.x, min.y, min.z, max.x, max.y, max.z);
+				OutputDebugString(msg2);
+				*/
+
 				mNumQueryCulledNodes ++;
 			}
@@ -192,11 +191,4 @@
 				bool wasVisible = octant->isOctreeVisible() && (octant->lastVisited() == mFrameId - 1);
 				
-				/* 
-				char msg[100];
-				if(wasVisible) sprintf(msg, "yes, was visible, %d\n", mFrameId);
-				else sprintf(msg, "no was invisible, %d\n", mFrameId);
-				OutputDebugString(msg);
-				*/
-
 				// identify nodes that we cannot skip queries for
 				bool mustQuery = !wasVisible || (octant->numNodes() > 0) || isLeaf(octant);
@@ -242,5 +234,5 @@
 
 			//TODO: does nothing useful
-			setRenderingMode(MODE_RENDER);
+			//setRenderingMode(MODE_RENDER);
 
 			((OctreeSceneManager *)mSceneManager)->_renderOctant(cam, octant);
Index: trunk/VUT/OcclusionCullingSceneManager/src/OgreOcclusionCullingTerrainSceneManager.cpp
===================================================================
--- trunk/VUT/OcclusionCullingSceneManager/src/OgreOcclusionCullingTerrainSceneManager.cpp	(revision 52)
+++ trunk/VUT/OcclusionCullingSceneManager/src/OgreOcclusionCullingTerrainSceneManager.cpp	(revision 54)
@@ -18,6 +18,6 @@
 		mShowBoxes = true;
 		//mDisplayNodes = true;
-		//mShowBoundingBoxes = true;
-		//mMaxDepth = 20;
+		mShowBoundingBoxes = true;
+		mMaxDepth = 20;
 	}
 	//-----------------------------------------------------------------------
