Index: GTP/trunk/App/Demos/Vis/FriendlyCulling/src/chcdemo.cpp
===================================================================
--- GTP/trunk/App/Demos/Vis/FriendlyCulling/src/chcdemo.cpp	(revision 2817)
+++ GTP/trunk/App/Demos/Vis/FriendlyCulling/src/chcdemo.cpp	(revision 2818)
@@ -1,8 +1,8 @@
 // occquery.cpp : Defines the entry point for the console application.
 //
+#include "glInterface.h"
 #include <math.h>
 #include <time.h>
 #include "common.h"
-#include "glInterface.h"
 #include "RenderTraverser.h"
 #include "SceneEntity.h"
@@ -209,7 +209,4 @@
 static CGprogram sCgMrtFragmentProgram = NULL;
 
-static CGprofile sCgFragmentProfile;
-static CGprofile sCgVertexProfile; 
-
 static CGparameter sColorsTexParam;
 static CGparameter sPositionsTexParam;
@@ -217,11 +214,6 @@
 static CGparameter sNoiseTexParam;
 
-/*static CGparameter sTexSizeParam; 
-static CGparameter sSamplesParam; 
-static CGparameter sEyeVecParam; 
-static CGparameter sRadiusParam; 
-*/
-static CGparameter sProjectionMatrixParam;
-static CGparameter sModelViewMatrixParam;	
+static CGparameter sModelViewProjMatrixParam;
+//static CGparameter sModelMatrixParam;
 static CGparameter sMaxDepthParam;
 
@@ -276,4 +268,7 @@
 
 	glutCreateWindow("FriendlyCulling");
+
+	//glutGameModeString( "1024x768:32@75" ); //the settings for fullscreen mode
+	//glutEnterGameMode(); //set glut to fullscreen using the settings in the line above
 
 	glutDisplayFunc(Display);
@@ -333,5 +328,5 @@
 	//bvh = bvhLoader.Load("data/city/model/city.bvh", sceneEntities);
 
-	myfar = 1.0f * Magnitude(bvh->GetBox().Diagonal());
+	myfar = 10.0f * Magnitude(bvh->GetBox().Diagonal());
 
 	if (!bvh)
@@ -353,5 +348,5 @@
 	visualization = new Visualization(bvh, camera, NULL, &state);
 
-	sceneQuery = new SceneQuery(bvh->GetBox(), traverser);
+	//sceneQuery = new SceneQuery(bvh->GetBox(), traverser);
 
 
@@ -376,10 +371,10 @@
 
 	// get the best profile for this hardware
-	sCgFragmentProfile = cgGLGetLatestProfile(CG_GL_FRAGMENT);
+	RenderState::sCgFragmentProfile = cgGLGetLatestProfile(CG_GL_FRAGMENT);
 	//assert(sCgFragmentProfile != CG_PROFILE_UNKNOWN);
-	cgGLSetOptimalOptions(sCgFragmentProfile);
-
-	sCgVertexProfile = cgGLGetLatestProfile(CG_GL_VERTEX);
-	cgGLSetOptimalOptions(sCgVertexProfile);
+	cgGLSetOptimalOptions(RenderState::sCgFragmentProfile);
+
+	RenderState::sCgVertexProfile = cgGLGetLatestProfile(CG_GL_VERTEX);
+	cgGLSetOptimalOptions(RenderState::sCgVertexProfile);
 
 	sCgMrtVertexProgram = 
@@ -387,5 +382,5 @@
 								CG_SOURCE,
 								"src/shaders/mrt.cg", 
-								sCgVertexProfile,
+								RenderState::sCgVertexProfile,
 								"vtx",
 								NULL);
@@ -394,6 +389,7 @@
 	{
 		cgGLLoadProgram(sCgMrtVertexProgram);
-	
-		sModelViewMatrixParam = cgGetNamedParameter(sCgMrtVertexProgram, "ModelViewProj");
+
+		SceneEntity::sModelMatrixParam = cgGetNamedParameter(sCgMrtVertexProgram, "ModelMatrix");
+		sModelViewProjMatrixParam = cgGetNamedParameter(sCgMrtVertexProgram, "ModelViewProj");
 	}
 
@@ -402,5 +398,5 @@
 								CG_SOURCE,
 								"src/shaders/mrt.cg", 
-								sCgFragmentProfile,
+								RenderState::sCgFragmentProfile,
 								"frag",
 								NULL);
@@ -411,5 +407,6 @@
 
 		sMaxDepthParam = cgGetNamedParameter(sCgMrtFragmentProgram, "maxDepth");
-		cgGLSetParameter1f(sMaxDepthParam, 1.0f / myfar);
+
+		cgGLSetParameter1f(sMaxDepthParam, 10.0f / myfar);
 	}
 	else
@@ -426,5 +423,5 @@
 								"src/shaders/deferred.cg", 
 								//"src/test.cg", 
-								sCgFragmentProfile,
+								RenderState::sCgFragmentProfile,
 								NULL,
 								NULL);
@@ -438,16 +435,5 @@
 		sColorsTexParam = cgGetNamedParameter(sCgSSAOProgram, "colors");  
 		sNormalsTexParam = cgGetNamedParameter(sCgSSAOProgram, "normals");  
-		sNoiseTexParam = cgGetNamedParameter(sCgSSAOProgram, "noiseTexture");  
-
-		sProjectionMatrixParam = cgGetNamedParameter(sCgSSAOProgram, "ProjTrafo");
-
-		/*sTexSizeParam = cgGetNamedParameter(sCgSSAOProgram, "invTexSize");
-		sRadiusParam = cgGetNamedParameter(sCgSSAOProgram, "radius");
-		sEyeVecParam = cgGetNamedParameter(sCgSSAOProgram, "eyevec");
-		sSamplesParam = cgGetNamedParameter(sCgSSAOProgram, "samples");
-
-		cgGLSetParameter1f(sTexSizeParam, 1.0f / (float)texWidth);
-		cgGLSetParameter1f(sRadiusParam, radius);
-		cgGLSetParameterArray3f(sSamplesParam, 0, 32, (const float *)samples);*/
+		sNoiseTexParam = cgGetNamedParameter(sCgSSAOProgram, "noiseTexture");
 	}
 	else
@@ -455,4 +441,6 @@
 
 	PrintGLerror("init");
+
+	cout << "cg initialised" << endl;
 }
 
@@ -584,27 +572,4 @@
 	glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0);
 
-
-	////////////////
-	//-- second fbo
-
-	/*glGenFramebuffersEXT(1, &fbo2);
-	glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, fbo2);
-
-	// create color buffer
-	glGenRenderbuffersEXT(1, &occlusionbuffer);
-	//glRenderbufferStorageEXT(GL_RENDERBUFFER_EXT, GL_RGBA32F_ARB, texWidth, texHeight);
-	glRenderbufferStorageMultisampleEXT(GL_RENDERBUFFER_EXT, samples, GL_FLOAT_RGBA_NV, texWidth2, texHeight2);
-	glBindRenderbufferEXT(GL_RENDERBUFFER_EXT, occlusionbuffer);
-	glFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT, GL_RENDERBUFFER_EXT, occlusionbuffer);
-
-	glGenTextures(1, &occlusionTex);
-	glBindTexture(GL_TEXTURE_2D, occlusionTex);
-	glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA32F_ARB,  texWidth2, texHeight2, 0, GL_RGBA, GL_FLOAT, NULL);
-	glGenerateMipmapEXT(GL_TEXTURE_2D);
-	glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT, GL_TEXTURE_2D, colorTex, 0);
-
-	PrintFBOStatus(glCheckFramebufferStatusEXT(GL_FRAMEBUFFER_EXT));
-
-	glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0);*/
 	PrintGLerror("fbo");
 }
@@ -882,8 +847,8 @@
 	glViewport(0, 0, texWidth, texHeight);
 
-	cgGLEnableProfile(sCgFragmentProfile);
+	cgGLEnableProfile(RenderState::sCgFragmentProfile);
 	cgGLBindProgram(sCgMrtFragmentProgram);
 
-	cgGLEnableProfile(sCgVertexProfile);
+	cgGLEnableProfile(RenderState::sCgVertexProfile);
 	cgGLBindProgram(sCgMrtVertexProgram);
 
@@ -896,4 +861,7 @@
 	glDisableClientState(GL_TEXTURE_COORD_ARRAY);
 
+	// set modelview matrix for shaders
+	cgGLSetStateMatrixParameter(sModelViewProjMatrixParam, CG_GL_MODELVIEW_PROJECTION_MATRIX, CG_GL_MATRIX_IDENTITY);
+
 	// render without shading
 	if (depthPass) 
@@ -907,15 +875,11 @@
 		glEnable(GL_LIGHTING);
 	}
-
+	
+	static Matrix4x4 identity = IdentityMatrix();
+
+	cgGLSetMatrixParameterfc(SceneEntity::sModelMatrixParam, (const float *)identity.x);
 	// bring eye modelview matrix up-to-date
 	SetupEyeView();
 
-	Vector3 dir = camera->GetDirection();
-	//cgGLSetParameter3f(sEyeVecParam, dir.x, dir.y, dir.z);
-
-	// set modelview matrix for shaders
-	cgGLSetStateMatrixParameter(sModelViewMatrixParam, CG_GL_MODELVIEW_PROJECTION_MATRIX, CG_GL_MATRIX_IDENTITY);
-	cgGLEnableProfile(sCgVertexProfile);
-
 	// actually render the scene geometry using one of the specified algorithms
 	traverser->RenderScene();
@@ -947,11 +911,9 @@
 	
 	
-	cgGLDisableProfile(sCgVertexProfile);
-	cgGLDisableProfile(sCgFragmentProfile);
+	cgGLDisableProfile(RenderState::sCgVertexProfile);
+	cgGLDisableProfile(RenderState::sCgFragmentProfile);
 
 	glPopAttrib();
 
-	cgGLSetStateMatrixParameter(sProjectionMatrixParam, CG_GL_PROJECTION_MATRIX, CG_GL_MATRIX_IDENTITY);
-	
 	glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0);
 
@@ -1497,6 +1459,6 @@
 	static char msg[7][300];
 
-	static double renderTime = algTime;
-	const float expFactor = 0.5f;
+	static double renderTime = elapsedTime;//algTime;
+	const float expFactor = 0.1f;
 
 	// if some strange render time spike happened in this frame => don't count
@@ -1629,7 +1591,7 @@
 {
 	glDisable(GL_TEXTURE_2D);
-	//glEnable(GL_TEXTURE_2D);
+	
 	glDisable(GL_LIGHTING);
-	//glBindTexture(GL_TEXTURE_2D, noiseTex);
+	
 	glMatrixMode(GL_PROJECTION);
 	glPushMatrix();
@@ -1641,11 +1603,10 @@
 
 	const float offs = 0.5f;
-	//glPushAttrib(GL_VIEWPORT_BIT);
-	//glViewport(-offs, texHeight);
+	
 	glOrtho(-offs, offs, -offs, offs, 0, 1);
 	
 	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
 
-	cgGLEnableProfile(sCgFragmentProfile);
+	cgGLEnableProfile(RenderState::sCgFragmentProfile);
 	cgGLBindProgram(sCgSSAOProgram);
 
@@ -1668,8 +1629,8 @@
 
 	glBegin(GL_QUADS);
-#if 1
+
 	// slightly larger than screen size in order to hide ambient occlusion errors
-	float offs2 = 0.55f;
-	//float offs2 = 0.5f;
+	//float offs2 = 0.55f;
+	float offs2 = 0.5f;
 
 	glColor3f(bl.x, bl.y, bl.z); glTexCoord2f(0, 0); glVertex3f(-offs2, -offs2, -0.5f);
@@ -1677,10 +1638,5 @@
 	glColor3f(tr.x, tr.y, tr.z); glTexCoord2f(1, 1); glVertex3f( offs2,  offs2, -0.5f);
 	glColor3f(tl.x, tl.y, tl.z); glTexCoord2f(0, 1); glVertex3f(-offs2,  offs2, -0.5f);
-#else
-	glTexCoord2f(0, 0); glVertex3f(-1, -1, -0.5f);
-	glTexCoord2f(1, 0); glVertex3f( 1, -1, -0.5f);
-	glTexCoord2f(1, 1); glVertex3f( 1,  1, -0.5f);
-	glTexCoord2f(0, 1); glVertex3f(-1,  1, -0.5f);
-#endif
+
 	glEnd();
 
@@ -1690,5 +1646,5 @@
 	cgGLDisableTextureParameter(sNoiseTexParam);
 
-	cgGLDisableProfile(sCgFragmentProfile);
+	cgGLDisableProfile(RenderState::sCgFragmentProfile);
 	
 	glEnable(GL_LIGHTING);
