Index: GTP/trunk/App/Demos/Vis/FriendlyCulling/src/Camera.h
===================================================================
--- GTP/trunk/App/Demos/Vis/FriendlyCulling/src/Camera.h	(revision 3062)
+++ GTP/trunk/App/Demos/Vis/FriendlyCulling/src/Camera.h	(revision 3063)
@@ -72,5 +72,5 @@
 	/** Returns the current projection matrix.
 	*/
-	virtual void GetProjectionMatrix(Matrix4x4 &mat) const = 0;
+	void GetProjectionMatrix(Matrix4x4 &mat) const;
 	/** Returns the current model view matrix.
 	*/
@@ -121,4 +121,6 @@
 protected:
 
+	virtual void UpdateProjectionMatrix() = 0;
+
 	void Precompute(const Vector3 &direction);
 
@@ -134,4 +136,6 @@
 	Matrix4x4 mBaseOrientation;
 	Matrix4x4 mViewOrientation;
+
+	Matrix4x4 mProjection;
 
 	float mPitch;
@@ -161,7 +165,4 @@
 	*/
 	inline float GetAspect() const { return mAspect; }
-	/** Returns the current projection matrix.
-	*/
-	virtual void GetProjectionMatrix(Matrix4x4 &mat) const;
 	/** Computes the extremal points of this frustum.
 		If farthestVisibleDistance is nearer than the far plane, 
@@ -177,4 +178,7 @@
 
 protected:
+	/** Calculates the current projection matrix.
+	*/
+	virtual void UpdateProjectionMatrix();
 
 	void ComputePointsInternal(Vector3 &ftl, Vector3 &ftr, Vector3 &fbl, Vector3 &fbr,
Index: GTP/trunk/App/Demos/Vis/FriendlyCulling/src/Visualization.h
===================================================================
--- GTP/trunk/App/Demos/Vis/FriendlyCulling/src/Visualization.h	(revision 3062)
+++ GTP/trunk/App/Demos/Vis/FriendlyCulling/src/Visualization.h	(revision 3063)
@@ -27,8 +27,7 @@
 
 	~Visualization();
-
 	/** Renders the visualizatioin
 	*/
-	void Render();
+	void Render(bool showShadowFrustra);
 	/** Sets the scene hierarchy.
 	*/
@@ -36,8 +35,8 @@
 	/** Sets the visualization camera.
 	*/
-	void SetVizCamera(Camera *cam)  {mVizCamera = cam;}
+	void SetVizCamera(Camera *cam) { mVizCamera = cam; }
 	/** Sets the currently used scene camera.
 	*/
-	void SetCamera(PerspectiveCamera *cam)  {mCamera = cam;}
+	void SetCamera(PerspectiveCamera *cam) {mCamera = cam; }
 	/** Sets the current render state
 	*/
@@ -49,4 +48,5 @@
 	*/
 	void RenderFrustum();
+
 
 protected:
Index: GTP/trunk/App/Demos/Vis/FriendlyCulling/src/Visualization.cpp
===================================================================
--- GTP/trunk/App/Demos/Vis/FriendlyCulling/src/Visualization.cpp	(revision 3062)
+++ GTP/trunk/App/Demos/Vis/FriendlyCulling/src/Visualization.cpp	(revision 3063)
@@ -104,5 +104,5 @@
 
 
-void Visualization::Render()
+void Visualization::Render(bool showShadowFrustra)
 {
 	stack<BvhNode *> tStack;
@@ -153,5 +153,6 @@
 	RenderFrustum();
 
-	ShadowMap::VisualizeFrustra();
+	if (showShadowFrustra)
+		ShadowMap::VisualizeFrustra();
 
 	Vector3 pos = mCamera->GetPosition();
Index: GTP/trunk/App/Demos/Vis/FriendlyCulling/src/ShadowMapping.cpp
===================================================================
--- GTP/trunk/App/Demos/Vis/FriendlyCulling/src/ShadowMapping.cpp	(revision 3062)
+++ GTP/trunk/App/Demos/Vis/FriendlyCulling/src/ShadowMapping.cpp	(revision 3063)
@@ -335,4 +335,5 @@
 
 #if 0
+
 Vector3 ShadowMap::GetNearCameraPointE(const VertexArray &pts) const
 {
@@ -545,4 +546,5 @@
 }
 
+
 unsigned int ShadowMap::GetShadowColorTexture() const
 {
@@ -562,5 +564,5 @@
 	polyhedron.CollectVertices(vertices);
 
-	// we 'look' at each point and calculate intersections of rays with scene bounding box
+	// we 'look' at each point and intect rays with the scene bounding box
 	VertexArray::const_iterator it, it_end = vertices.end();
 
@@ -570,5 +572,4 @@
 
 		frustumPoints.push_back(v);
-		
 		// hack: start at point which is guaranteed to be outside of box
 		v -= Magnitude(mSceneBox.Diagonal()) * lightDir;
@@ -587,5 +588,6 @@
 
 
-void ShadowMap::ComputeShadowMap(RenderTraverser *renderer, const Matrix4x4 &projView)
+void ShadowMap::ComputeShadowMap(RenderTraverser *renderer, 
+								 const Matrix4x4 &projView)
 {
 	mFbo->Bind();
@@ -607,4 +609,21 @@
 	_Render(renderer);
 
+	glPopAttrib();
+	
+	glShadeModel(GL_SMOOTH);
+	glEnable(GL_LIGHTING);
+	glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE);
+
+#if 0
+	float *data = new float[mSize * mSize];
+
+	GrabDepthBuffer(data, mFbo->GetDepthTex());
+	ExportDepthBuffer(data, mSize);
+
+	delete [] data;
+	
+	PrintGLerror("shadow map");
+#endif
+	
 
 	//////////////
@@ -618,26 +637,10 @@
 	mTextureMatrix = mLightProjView * biasMatrix; 
 
-	glPopAttrib();
-	
-	glShadeModel(GL_SMOOTH);
-	glEnable(GL_LIGHTING);
-	glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE);
-
-#if 0
-	float *data = new float[mSize * mSize];
-
-	GrabDepthBuffer(data, mFbo->GetDepthTex());
-	ExportDepthBuffer(data, mSize);
-
-	delete [] data;
-	
-	PrintGLerror("shadow map");
-#endif
-	
 	FrameBufferObject::Release();
 }
 
 
-void ShadowMap::RenderShadowView(RenderTraverser *renderer, const Matrix4x4 &projView)
+void ShadowMap::RenderShadowView(RenderTraverser *renderer, 
+								 const Matrix4x4 &projView)
 {
 	glEnable(GL_LIGHTING);
@@ -671,6 +674,6 @@
 	mShadowCam->SetPosition(mCamera->GetPosition());
 
-	Vector3 upVec = CalcUpVec(mCamera->GetDirection(), dir);
-	Matrix4x4 lightView = LookAt(mShadowCam->GetPosition(), dir, upVec);
+	const Vector3 upVec = CalcUpVec(mCamera->GetDirection(), dir);
+	const Matrix4x4 lightView = LookAt(mShadowCam->GetPosition(), dir, upVec);
 
 	mShadowCam->mViewOrientation = lightView;
@@ -684,17 +687,20 @@
 	CalcLightProjection(lightProj);
 
+	mLightProjView = lightView * lightProj;
+
+	DEL_PTR(lightPoly);
+	lightPoly = CreatePolyhedron(mLightProjView, mSceneBox);
+
 	glMatrixMode(GL_PROJECTION);
 	glPushMatrix();
-	glLoadMatrixf((float *)lightProj.x);
-
-	mLightProjView = lightView * lightProj;
-
-	DEL_PTR(lightPoly);
-	lightPoly = CreatePolyhedron(mLightProjView, mSceneBox);
 
 	glMatrixMode(GL_MODELVIEW);
 	glPushMatrix();
 	
-	mShadowCam->SetupCameraView();
+	// set projection matrix manually
+	mShadowCam->mProjection = lightProj;
+	
+	// load gl view projection
+	mShadowCam->SetupViewProjection();
 
 	
Index: GTP/trunk/App/Demos/Vis/FriendlyCulling/src/chcdemo.cpp
===================================================================
--- GTP/trunk/App/Demos/Vis/FriendlyCulling/src/chcdemo.cpp	(revision 3062)
+++ GTP/trunk/App/Demos/Vis/FriendlyCulling/src/chcdemo.cpp	(revision 3063)
@@ -880,6 +880,5 @@
 	int oldRenderMethod = renderMethod;
 	// for rendering the light view, we use forward rendering
-	if (renderLightView)
-		renderMethod = RenderState::FORWARD;
+	if (renderLightView) renderMethod = RenderState::FORWARD;
 
 	/// enable vbo vertex array
@@ -1601,5 +1600,5 @@
 	//-- visualization of the occlusion culling
 
-	visualization->Render();
+	visualization->Render(showShadowMap);
 
 	
@@ -1948,5 +1947,5 @@
 	glDisable(GL_CULL_FACE);
 	state.LockCullFaceEnabled(true);
-
+	/// don't use alphatocoverage
 	state.SetUseAlphaToCoverage(false);
 
@@ -1967,5 +1966,4 @@
 
 	glEnableClientState(GL_NORMAL_ARRAY);
-
 	// change back state
 	BvhNode::SetCurrentState(CAMERA_PASS);
Index: GTP/trunk/App/Demos/Vis/FriendlyCulling/src/DeferredRenderer.cpp
===================================================================
--- GTP/trunk/App/Demos/Vis/FriendlyCulling/src/DeferredRenderer.cpp	(revision 3062)
+++ GTP/trunk/App/Demos/Vis/FriendlyCulling/src/DeferredRenderer.cpp	(revision 3063)
@@ -527,6 +527,6 @@
 	sCgSsaoProgram->SetValue3f(10, tr.x, tr.y, tr.z);
 
-	cout << "new projview:\n" << projViewMatrix << endl;
-	cout << "old projview:\n" << oldProjViewMatrix << endl;
+	//cout << "new projview:\n" << projViewMatrix << endl;
+	//cout << "old projview:\n" << oldProjViewMatrix << endl;
 
 	sCgSsaoProgram->SetMatrix(11, projViewMatrix);
Index: GTP/trunk/App/Demos/Vis/FriendlyCulling/src/Camera.cpp
===================================================================
--- GTP/trunk/App/Demos/Vis/FriendlyCulling/src/Camera.cpp	(revision 3062)
+++ GTP/trunk/App/Demos/Vis/FriendlyCulling/src/Camera.cpp	(revision 3063)
@@ -116,4 +116,5 @@
 {
 	mNear = nearDist;
+	UpdateProjectionMatrix();
 }
 
@@ -122,4 +123,5 @@
 { 
 	mFar = farDist; 
+	UpdateProjectionMatrix();
 }
 
@@ -272,4 +274,10 @@
 
 
+void Camera::GetProjectionMatrix(Matrix4x4 &m)const
+{
+	m = mProjection;
+}
+
+
 /*********************************************************/
 /*       Class PerspectiveCamera implementation           */
@@ -280,4 +288,7 @@
 {
 	mFOVy = 60.0f * M_PI / 180.0f;
+	mAspect = 1.0f;
+
+	UpdateProjectionMatrix();
 }
 
@@ -287,4 +298,6 @@
 	mFOVy = fieldOfView * M_PI / 180.0f;
 	mAspect = aspect;
+
+	UpdateProjectionMatrix();
 }
 
@@ -384,15 +397,9 @@
 
 
-void PerspectiveCamera::GetProjectionMatrix(Matrix4x4 &mat) const
-{
-	mat = GetPerspective(mFOVy, 1.0f / mAspect, mNear, mFar);
-
-	Matrix4x4 mat2;
-	glGetFloatv(GL_PROJECTION_MATRIX, (float *)mat2.x);
-
-	cout << "my projview:\n" << mat  << endl;
-	cout << "gl projview:\n" << mat2 << endl;
-}
-
-
-}
+void PerspectiveCamera::UpdateProjectionMatrix()
+{
+	mProjection = GetPerspective(mFOVy, 1.0f / mAspect, mNear, mFar);
+}
+
+
+}
