Index: GTP/trunk/App/Demos/Vis/FriendlyCulling/src/Environment.h
===================================================================
--- GTP/trunk/App/Demos/Vis/FriendlyCulling/src/Environment.h	(revision 2825)
+++ GTP/trunk/App/Demos/Vis/FriendlyCulling/src/Environment.h	(revision 2826)
@@ -23,4 +23,8 @@
 	*/
 	bool Read(const std::string &filename);
+	/** Initialises the environment file with default values.
+	*/
+	void Init();
+
 
 	//////////
@@ -40,6 +44,7 @@
 
 	Vector3 mPosition;
-	Vector3 mPitch;
-	Vector3 mYaw;
+	Vector3 mDirection;
+
+	bool mUseFullScreen;
 };
 
Index: GTP/trunk/App/Demos/Vis/FriendlyCulling/src/glfont2.cpp
===================================================================
--- GTP/trunk/App/Demos/Vis/FriendlyCulling/src/glfont2.cpp	(revision 2826)
+++ GTP/trunk/App/Demos/Vis/FriendlyCulling/src/glfont2.cpp	(revision 2826)
@@ -0,0 +1,207 @@
+//*******************************************************************
+//glfont2.cpp -- glFont Version 2.0 implementation
+//Copyright (c) 1998-2002 Brad Fish
+//See glfont.html for terms of use
+//May 14, 2002
+//*******************************************************************
+
+//STL headers
+#include <string>
+#include <utility>
+#include <iostream>
+#include <fstream>
+using namespace std;
+
+//OpenGL headers
+#include "glInterface.h"
+
+//glFont header
+#include "glfont2.h"
+using namespace glfont;
+
+//*******************************************************************
+//GLFont Class Implementation
+//*******************************************************************
+GLFont::GLFont ()
+{
+	//Initialize header to safe state
+	header.tex = -1;
+	header.tex_width = 0;
+	header.tex_height = 0;
+	header.start_char = 0;
+	header.end_char = 0;
+	header.chars = NULL;
+}
+//*******************************************************************
+GLFont::~GLFont ()
+{
+	//Destroy the font
+	Destroy();
+}
+//*******************************************************************
+bool GLFont::Create (const char *file_name, int tex)
+{
+	ifstream input;
+	int num_chars, num_tex_bytes;
+	char *tex_bytes;
+
+	//Destroy the old font if there was one, just to be safe
+	Destroy();
+
+	//Open input file
+	input.open(file_name, ios::in | ios::binary);
+	if (!input)
+		return false;
+
+	//Read the header from file
+	input.read((char *)&header, sizeof(header));
+	header.tex = tex;
+
+	//Allocate space for character array
+	num_chars = header.end_char - header.start_char + 1;
+	if ((header.chars = new GLFontChar[num_chars]) == NULL)
+		return false;
+
+	//Read character array
+	input.read((char *)header.chars, sizeof(GLFontChar) *
+		num_chars);
+
+	//Read texture pixel data
+	num_tex_bytes = header.tex_width * header.tex_height * 2;
+	tex_bytes = new char[num_tex_bytes];
+	input.read(tex_bytes, num_tex_bytes);
+
+	//Create OpenGL texture
+	glBindTexture(GL_TEXTURE_2D, tex);  
+	glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP);
+	glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP);
+	glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
+	glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
+	glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
+	glTexImage2D(GL_TEXTURE_2D, 0, 2, header.tex_width,
+		header.tex_height, 0, GL_LUMINANCE_ALPHA, GL_UNSIGNED_BYTE,
+		(void *)tex_bytes);
+
+	//Free texture pixels memory
+	delete[] tex_bytes;
+
+	//Close input file
+	input.close();
+
+	//Return successfully
+	return true;
+}
+//*******************************************************************
+bool GLFont::Create (const std::string &file_name, int tex)
+{
+	return Create(file_name.c_str(), tex);
+}
+//*******************************************************************
+void GLFont::Destroy (void)
+{
+	//Delete the character array if necessary
+	if (header.chars)
+	{
+		delete[] header.chars;
+		header.chars = NULL;
+	}
+}
+//*******************************************************************
+void GLFont::GetTexSize (std::pair<int, int> *size)
+{
+	//Retrieve texture size
+	size->first = header.tex_width;
+	size->second = header.tex_height;
+}
+//*******************************************************************
+int GLFont::GetTexWidth (void)
+{
+	//Return texture width
+	return header.tex_width;
+}
+//*******************************************************************
+int GLFont::GetTexHeight (void)
+{
+	//Return texture height
+	return header.tex_height;
+}
+//*******************************************************************
+void GLFont::GetCharInterval (std::pair<int, int> *interval)
+{
+	//Retrieve character interval
+	interval->first = header.start_char;
+	interval->second = header.end_char;
+}
+//*******************************************************************
+int GLFont::GetStartChar (void)
+{
+	//Return start character
+	return header.start_char;
+}
+//*******************************************************************
+int GLFont::GetEndChar (void)
+{
+	//Return end character
+	return header.end_char;
+}
+//*******************************************************************
+void GLFont::GetCharSize (int c, std::pair<int, int> *size)
+{
+	//Make sure character is in range
+	if (c < header.start_char || c > header.end_char)
+	{
+		//Not a valid character, so it obviously has no size
+		size->first = 0;
+		size->second = 0;
+	}
+	else
+	{
+		GLFontChar *glfont_char;
+
+		//Retrieve character size
+		glfont_char = &header.chars[c - header.start_char];
+		size->first = (int)(glfont_char->dx * header.tex_width);
+		size->second = (int)(glfont_char->dy *
+			header.tex_height);
+	}
+}
+//*******************************************************************
+int GLFont::GetCharWidth (int c)
+{
+	//Make sure in range
+	if (c < header.start_char || c > header.end_char)
+		return 0;
+	else
+	{
+		GLFontChar *glfont_char;
+		
+		//Retrieve character width
+		glfont_char = &header.chars[c - header.start_char];
+		return (int)(glfont_char->dx * header.tex_width);
+	}
+}
+//*******************************************************************
+int GLFont::GetCharHeight (int c)
+{
+	//Make sure in range
+	if (c < header.start_char || c > header.end_char)
+		return 0;
+	else
+	{
+		GLFontChar *glfont_char;
+
+		//Retrieve character height
+		glfont_char = &header.chars[c - header.start_char];
+		return (int)(glfont_char->dy * header.tex_height);
+	}
+}
+//*******************************************************************
+void GLFont::Begin (void)
+{
+	//Bind to font texture
+	glBindTexture(GL_TEXTURE_2D, header.tex);
+}
+//*******************************************************************
+
+//End of file
+
Index: GTP/trunk/App/Demos/Vis/FriendlyCulling/src/Camera.h
===================================================================
--- GTP/trunk/App/Demos/Vis/FriendlyCulling/src/Camera.h	(revision 2806)
+++ GTP/trunk/App/Demos/Vis/FriendlyCulling/src/Camera.h	(revision 2826)
@@ -38,11 +38,16 @@
 
 	inline float GetFov() const { return mFovy; }
-	inline void GetSize(int &width, int &height) const { width = mWidth; height = mHeight; }
 	inline float GetAspect() const { return (float) mWidth / mHeight; }
+	inline int GetWidth() const { return mWidth; }
+	inline int GetHeight() const { return mHeight; }
 
 	/** Sets up viewing in gl
 	*/
 	void SetupCameraView();
+	/** Returns the current projection matrix.
+	*/
 	void GetProjectionMatrix(Matrix4x4 &mat);
+	/** Returns the current model view matrix.
+	*/
 	void GetModelViewMatrix(Matrix4x4 &mat);
 
Index: GTP/trunk/App/Demos/Vis/FriendlyCulling/src/chcdemo.cpp
===================================================================
--- GTP/trunk/App/Demos/Vis/FriendlyCulling/src/chcdemo.cpp	(revision 2825)
+++ GTP/trunk/App/Demos/Vis/FriendlyCulling/src/chcdemo.cpp	(revision 2826)
@@ -26,4 +26,5 @@
 #include <Cg/cg.h>
 #include <Cg/cgGL.h>
+#include "glfont2.h"
 
 
@@ -47,4 +48,5 @@
 GLuint noiseTex;
 
+GLuint fontTex;
 
 /// the renderable scene geometry
@@ -85,7 +87,7 @@
 const static float keyRotation = 1.5f;
 
-/// elapsed time in seconds
-double elapsedTime = 1.0f;
-double algTime = 1.0f;
+/// elapsed time in milliseconds
+double elapsedTime = 1000.0f;
+double algTime = 1000.0f;
 
 static int winWidth = 1024;
@@ -97,4 +99,6 @@
 
 float myfar = 0;
+
+glfont::GLFont myfont;
 
 // rendertexture
@@ -116,6 +120,6 @@
 
 bool showHelp = false;
-bool showStatistics = true;
-bool showOptions = true;
+bool showStatistics = false;
+bool showOptions = false;
 bool showBoundingVolumes = false;
 bool visMode = false;
@@ -145,4 +149,6 @@
 bool useSsao = false;
 
+bool showAlgorithmTime = false;
+
 GLubyte *randomNormals = NULL;
 
@@ -152,5 +158,5 @@
 
 
-#define NUM_SAMPLES 12
+#define NUM_SAMPLES 8
 
 static float samples[NUM_SAMPLES * 2];
@@ -196,6 +202,6 @@
 
 
-inline float KeyRotationAngle() { return keyRotation * elapsedTime; }
-inline float KeyShift() { return keyForwardMotion * elapsedTime; }
+inline float KeyRotationAngle() { return keyRotation * elapsedTime * 1e-3f; }
+inline float KeyShift() { return keyForwardMotion * elapsedTime * 1e-3f; }
 
 void InitFBO();
@@ -647,5 +653,25 @@
 
 
-void InitGLstate(void) 
+bool Initfont(void)
+{
+	//Initialize OpenGL
+	//Texture mapping and blending must be enabled for glFont to work
+	glClearColor(0.0, 0.0, 0.0, 1.0);	
+	glEnable(GL_TEXTURE_2D);
+	glEnable(GL_BLEND);
+	glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
+
+	glGenTextures(1, &fontTex);
+	glBindTexture(GL_TEXTURE_2D, fontTex);
+	if (!myfont.Create("myfont.glf", fontTex))
+		return false;
+
+	glDisable(GL_TEXTURE_2D);
+	//Return successfully
+	return true;
+}
+
+
+void InitGLstate() 
 {
 	glClearColor(0.5f, 0.5f, 0.8f, 0.0f);
@@ -684,4 +710,48 @@
 
 	glDepthFunc(GL_LESS);
+
+	if (!Initfont())
+		cerr << "font creation failed" << endl;
+	else
+		cout << "successfully created font" << endl;
+}
+
+
+void DrawFont()
+{
+	float top_color[3] = {1.0F, 1.0F, 1.0F};
+	float bottom_color[3] = {0.0F, 0.0F, 1.0F};
+
+	glEnable(GL_TEXTURE_2D);
+	glEnable(GL_BLEND);
+	glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
+
+
+	//Clear back buffer
+	glClear(GL_DEPTH_BUFFER_BIT);
+
+	//Draw some stuff
+	glMatrixMode(GL_MODELVIEW);
+	glPushMatrix();
+	glLoadIdentity();
+
+	//Draw a string
+	glColor3f(1.0F, 1.0F, 1.0F);
+	myfont.Begin();
+	myfont.DrawString("Hello World!", 1.0F, 0.0F, 480.0F);
+	/*myfont.DrawString(L"Hello World!", 2.0F, 0.0F,
+		400.0F, top_color, bottom_color);
+	myfont.DrawString(std::string("Hello World!"), 0.0F, 320.0F);
+	myfont.DrawString(std::wstring(L"Hello World!"), 0.0F, 280.F,
+		top_color, bottom_color);
+	glTranslatef(0.0F, 200.F, 0.0F);
+	glRotatef(15.0F, 0.0F, 0.0F, 1.0F);
+	myfont.DrawString("Hello World!", 2.0F, 0.0F, 0.F,
+		top_color, bottom_color);
+*/
+	glPopMatrix();
+
+	glDisable(GL_BLEND);
+	glDisable(GL_TEXTURE_2D);
 }
 
@@ -699,7 +769,7 @@
 		"'F5',          - shows/hides parameters",
 		"'F6',          - toggles between fly / walkmode",
-		"'F7',          - depth pass",
-		"'F8',          - enable/disable glFinish for more accurate timings",
-		"'F9',          - enables/disables ambient occlusion",
+		"'F7',          - cycles throw render modes",
+		"'F8',          - enables/disables ambient occlusion (only deferred)",
+		"'F9',          - shows pure algorithm render time (using glFinish)",
 		"'SPACE'        - cycles through occlusion culling algorithms",
 		"",
@@ -900,6 +970,8 @@
 void Display() 
 {	
+	glFlush();
+	elapsedTime = frameTimer.Elapsedms();
+
 	// take time from last frame
-	elapsedTime = frameTimer.Elapsed();
 	frameTimer.Start();
 
@@ -922,6 +994,9 @@
 	if (!flyMode) PlaceViewer(oldPos);
 
-	algTimer.Start();
-
+	if (showAlgorithmTime)
+	{
+		glFinish();
+		algTimer.Start();
+	}
 	
 	// render without shading
@@ -990,4 +1065,5 @@
 
 
+
 	/////////
 	//-- do the rest of the rendering
@@ -1013,5 +1089,4 @@
 	glDisableClientState(GL_VERTEX_ARRAY);
 	glDisableClientState(GL_NORMAL_ARRAY);
-	
 
 	if (renderType == RenderState::DEFERRED) 
@@ -1028,7 +1103,9 @@
 	}
 
-
-	algTime = algTimer.Elapsedms();
-
+	if (showAlgorithmTime)
+	{
+		glFinish();
+		algTime = algTimer.Elapsedms();
+	}
 
 	///////////
@@ -1037,5 +1114,5 @@
 
 	if (visMode) DisplayVisualization();
-	
+
 	DisplayStats();
 
@@ -1233,4 +1310,8 @@
 		useSsao = !useSsao;
 		break;
+	case GLUT_KEY_F9:
+		showAlgorithmTime = !showAlgorithmTime;
+		break;
+
 	case GLUT_KEY_LEFT:
 		{
@@ -1400,20 +1481,21 @@
 
 
-void Begin2D(void) 
+void Begin2D() 
 {
 	glDisable(GL_LIGHTING);
 	glDisable(GL_DEPTH_TEST);
-
-	glPushMatrix();
-	glLoadIdentity();
 
 	glMatrixMode(GL_PROJECTION);
 	glPushMatrix();
 	glLoadIdentity();
-	gluOrtho2D(0, winWidth, winHeight, 0);
-}
-
-
-void End2D(void) 
+	gluOrtho2D(0, winWidth, 0, winHeight);
+
+	glMatrixMode(GL_MODELVIEW);
+	glPushMatrix();
+	glLoadIdentity();
+}
+
+
+void End2D() 
 {
 	glPopMatrix();
@@ -1569,19 +1651,30 @@
 void DisplayStats()
 {
-	static char msg[7][300];
-
-	static double renderTime = elapsedTime;//algTime;
+	static char msg[9][300];
+
+	static double frameTime = elapsedTime;
+	static double renderTime = algTime;
+
 	const float expFactor = 0.1f;
 
 	// if some strange render time spike happened in this frame => don't count
-	if (algTime < 500) renderTime = algTime * expFactor + (1.0f - expFactor) * algTime;
-
-	accumulatedTime += elapsedTime * 1e3f;
+	if (elapsedTime < 500) frameTime = elapsedTime * expFactor + (1.0f - expFactor) * elapsedTime;
+	
+	static float rTime = 1000.0f;
+
+	if (showAlgorithmTime)
+	{
+		if (algTime < 500) renderTime = algTime * expFactor + (1.0f - expFactor) * renderTime;
+	}
+
+	accumulatedTime += elapsedTime;
 
 	if (accumulatedTime > 500) // update every fraction of a second
 	{	
 		accumulatedTime = 0;
-		if (renderTime) fps = 1e3f / (float)renderTime;
-
+
+		if (frameTime) fps = 1e3f / (float)frameTime;
+
+		rTime = renderTime;
 		renderedObjects = traverser->GetStats().mNumRenderedGeometry;
 		renderedNodes = traverser->GetStats().mNumRenderedNodes;
@@ -1596,38 +1689,23 @@
 	}
 
-	string str;
-	string str2;
-
-	int i = 0;
-
-	CalcDecimalPoint(str, renderedTriangles);
-	CalcDecimalPoint(str2, bvh->GetBvhStats().mTriangles);
-
-	sprintf(msg[i ++], "rendered nodes: %6d (of %6d), rendered triangles: %s (of %s)", 
-			renderedNodes, bvh->GetNumVirtualNodes(), str.c_str(), str2.c_str()); 
-
-	sprintf(msg[i ++], "traversed: %5d, frustum culled: %5d, query culled: %5d",
-			traversedNodes, frustumCulledNodes, queryCulledNodes);
-
-	sprintf(msg[i ++], "issued queries: %5d, state changes: %5d, render batches: %5d", 
-		    issuedQueries, stateChanges, numBatches);
-
-	sprintf(msg[i ++], "fps: %6.1f", fps);
-
-
-	sprintf(msg[i ++], "assumed visible frames: %4d, max batch size: %4d", 
-		    assumedVisibleFrames, maxBatchSize);
-	
-	static char *renderTypeStr[] = {"fixed function", "fixed function + depth pass", "deferred shading"};
-
-	sprintf(msg[i ++], "multiqueries: %d, tight bounds: %d, render queue: %d, render technique: %s", 
-		    useMultiQueries, useTightBounds, useRenderQueue, renderTypeStr[renderType]);
-
-	sprintf(msg[i ++], "triangles per virtual leaf: %5d", trianglesPerVirtualLeaf);
-
 
 	Begin2D();
-	
-	if(showHelp)
+
+	float top_color[3] = {1.0F, 1.0F, 1.0F};
+	float bottom_color[3] = {0.0F, 0.0F, 1.0F};
+
+	glEnable(GL_TEXTURE_2D);
+	glEnable(GL_BLEND);
+	glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
+
+
+
+	glClear(GL_DEPTH_BUFFER_BIT);
+	//Draw a string
+	glColor3f(1.0f, 1.0f, 1.0f);
+	myfont.Begin();
+
+	//DrawFont();
+	if (showHelp)
 	{	
 		DrawHelpMessage();
@@ -1635,21 +1713,72 @@
 	else
 	{
-		static char *alg_str[] = {"Frustum Culling", "Stop and Wait", "CHC", "CHC ++"};
-
-		glColor3f(1.0f, 1.0f, 1.0f);
-		Output(850, 30, alg_str[renderMode]);
+		glColor3f(1.0f, 0.5f, 0.5f);
+
+		if (showOptions)
+		{
+			int i = 0;
+
+			static char *renderTypeStr[] = {"fixed function", "fixed function + depth pass", "deferred shading"};
+	
+			sprintf(msg[i ++], "multiqueries: %d, tight bounds: %d, render queue: %d", 
+							useMultiQueries, useTightBounds, useRenderQueue);
+
+			sprintf(msg[i ++], "render technique: %s, SSAO: %d", renderTypeStr[renderType], useSsao);
+
+			sprintf(msg[i ++], "triangles per virtual leaf: %5d", trianglesPerVirtualLeaf);
+
+			sprintf(msg[i ++], "assumed visible frames: %4d, max batch size: %4d", 
+				assumedVisibleFrames, maxBatchSize);
+
+			for (int j = 0; j < 4; ++ j)
+				myfont.DrawString(msg[j], 1.0F, 20.0f, 760 - j * 30);
+		}
+
+		glColor3f(0.5f, 1.0f, 0.5f);
 
 		if (showStatistics)
 		{
-			for (int i = 0; i < 4; ++ i)
-				Output(20, (i + 1) * 30, msg[i]);
+			string str;
+			string str2;
+
+			CalcDecimalPoint(str, renderedTriangles);
+			CalcDecimalPoint(str2, bvh->GetBvhStats().mTriangles);
+
+			int i = 4;
+
+			sprintf(msg[i ++], "rendered: %6d nodes (of %6d), %s triangles (of %s)", 
+				renderedNodes, bvh->GetNumVirtualNodes(), str.c_str(), str2.c_str()); 
+
+			sprintf(msg[i ++], "traversed: %5d, frustum culled: %5d, query culled: %5d",
+				traversedNodes, frustumCulledNodes, queryCulledNodes);
+
+			sprintf(msg[i ++], "issued queries: %5d, state changes: %5d, render batches: %5d", 
+				issuedQueries, stateChanges, numBatches);
+
+			for (int j = 4; j < 7; ++ j)
+				myfont.DrawString(msg[j], 1.0F, 20.0f, 760 - j * 30);
 		}
 
-		if (showOptions)
-		{
-			for (int i = 4; i < 8; ++ i)
-				Output(20, (i + 1) * 30, msg[i]);
-		}
-	}
+		//glTranslatef(200, 200, 0);
+		//glScalef(1, -1, 1);
+
+		glColor3f(1.0f, 1.0f, 1.0f);
+		static char *alg_str[] = {"Frustum Cull", "Stop and Wait", "CHC", "CHC ++"};
+		sprintf(msg[7], "%s:  %6.1f fps", alg_str[renderMode], fps);
+
+		myfont.DrawString(msg[7], 1.0F, 720.0F, 760.0F);//, top_color, bottom_color);
+
+		//glDisable(GL_CULL_FACE);
+		//Output(780, 30, msg[7]);
+
+		if (showAlgorithmTime)
+		{	
+			//sprintf(msg[8], "algorithm time: %6.1f ms", rTime);
+			//Output(780, 60, msg[8]);
+		}		
+	}
+
+	glDisable(GL_BLEND);
+	glDisable(GL_TEXTURE_2D);
 
 	End2D();
@@ -1814,4 +1943,31 @@
 		// create stratified samples over sphere
 		const float rx = ((float)i + RandomValue(0, 1)) * scale;
+		const float ry = ((float)i + RandomValue(0, 1)) * scale;
+
+		const float theta = 2.0f * acos(sqrt(1.0f - rx));
+		const float phi = 2.0f * M_PI * ry;
+
+		Vector3 unit = Vector3(sin(theta) * cos(phi), sin(theta) * sin(phi), cos(theta));
+
+		// project
+		Vector3 proj = unit / (1.0f + fabs(unit.z));
+
+		samples[i + 0] = proj.x;
+		samples[i + 1] = proj.y;
+
+		cout << samples[i] << " " << samples[i + 1] << endl;
+	}
+}
+
+
+/*void GenerateSamples()
+{
+	float scale = 1.0f / (float)NUM_SAMPLES;
+
+	// fill an array with uniformly distributed spherical samples
+	for (int i = 0; i < NUM_SAMPLES; ++ i)
+	{
+		// create stratified samples over sphere
+		const float rx = ((float)i + RandomValue(0, 1)) * scale;
 
 		const float theta = 2.0f * acos(sqrt(1.0f - rx));
@@ -1823,5 +1979,5 @@
 	}
 }
-
+*/
 
 void ComputeViewVectors(Vector3 &tl, Vector3 &tr, Vector3 &bl, Vector3 &br)
Index: GTP/trunk/App/Demos/Vis/FriendlyCulling/src/Environment.cpp
===================================================================
--- GTP/trunk/App/Demos/Vis/FriendlyCulling/src/Environment.cpp	(revision 2825)
+++ GTP/trunk/App/Demos/Vis/FriendlyCulling/src/Environment.cpp	(revision 2826)
@@ -13,3 +13,23 @@
 }
 
+
+void Environment::Init()
+{
+	/*mAssumedVisibleFrames;
+	mMaxBatchSize;
+
+	mTrianglesPerVirtualLeaf;
+
+	mKeyForwardMotion;
+	mKeyRotation;
+
+	mWinWidth;
+	mWinHeight;
+
+	mPosition;
+*/
+	mUseFullScreen = false;
 }
+
+
+}
Index: GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/deferred.cg
===================================================================
--- GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/deferred.cg	(revision 2825)
+++ GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/deferred.cg	(revision 2826)
@@ -1,4 +1,4 @@
-#define NUM_SAMPLES 12
-#define SAMPLE_INTENSITY 1.2f
+#define NUM_SAMPLES 8
+#define SAMPLE_INTENSITY 0.5f
 //#define SAMPLE_INTENSITY 0.7f
 #define AREA_SIZE 5e-1f
@@ -88,5 +88,5 @@
   float total_ao = 0.0;
 
-  //const float areaSize = 5e-1f;
+  const float areaSize = 5e-1f;
   //const float areaSize = 3e-1f;
   //const float sampleIntensity = 0.2f;
@@ -118,14 +118,14 @@
 
     // distance between current position and sample position controls AO intensity.
-    //const float maxdist = 4e-1f;
-    const float maxdist = 5e-1f;
-    
-    float distance_intensity = maxdist - length_to_sample;
-    //float distance_intensity = 0.5f / (1.0f + length_to_sample * length_to_sample);
-    distance_intensity = max(distance_intensity, 0.0f);
+    //const float maxdist = 2e-1f;
+    //const float maxdist = 5e-1f;
+    const float distanceScale = 1e-6f;
+    //float distance_intensity = maxdist - length_to_sample;
+    float distance_intensity = (SAMPLE_INTENSITY * distanceScale) / (distanceScale + length_to_sample * length_to_sample);
+    //distance_intensity = max(distance_intensity, 0.0f);
     // quadratic influence
-    distance_intensity *= distance_intensity;
-    
-    total_ao += cos_angle * SAMPLE_INTENSITY * distance_intensity;
+    //distance_intensity *= distance_intensity;
+    
+    total_ao += cos_angle * distance_intensity;
   }
 	
Index: GTP/trunk/App/Demos/Vis/FriendlyCulling/src/glfont2.h
===================================================================
--- GTP/trunk/App/Demos/Vis/FriendlyCulling/src/glfont2.h	(revision 2826)
+++ GTP/trunk/App/Demos/Vis/FriendlyCulling/src/glfont2.h	(revision 2826)
@@ -0,0 +1,513 @@
+//*******************************************************************
+//glfont2.h -- Header for glfont2.cpp
+//Copyright (c) 1998-2002 Brad Fish
+//See glfont.html for terms of use
+//May 14, 2002
+//*******************************************************************
+
+#ifndef GLFONT2_H
+#define GLFONT2_H
+
+//*******************************************************************
+//GLFont Interface
+//*******************************************************************
+
+//glFont namespace
+namespace glfont
+{
+	class GLFont;	
+}
+
+//glFont class
+class glfont::GLFont
+{
+private:
+
+	//glFont character structure
+	typedef struct
+	{
+		float dx, dy;
+		float tx1, ty1;
+		float tx2, ty2;
+	} GLFontChar;
+
+	//glFont header structure
+	struct
+	{
+		int tex;
+		int tex_width, tex_height;
+		int start_char, end_char;
+		GLFontChar *chars;
+	} header;
+
+public:
+
+	//Constructor
+	GLFont ();
+
+	//Destructor
+	~GLFont ();
+
+public:
+
+	//Creates the glFont
+	bool Create (const char *file_name, int tex);
+	bool Create (const std::string &file_name, int tex);
+
+	//Destroys the glFont
+	void Destroy (void);
+
+	//Texture size retrieval methods
+	void GetTexSize (std::pair<int, int> *size);
+	int GetTexWidth (void);
+	int GetTexHeight (void);
+
+	//Character interval retrieval methods
+	void GetCharInterval (std::pair<int, int> *interval);
+	int GetStartChar (void);
+	int GetEndChar (void);
+
+	//Character size retrieval methods
+	void GetCharSize (int c, std::pair<int, int> *size);
+	int GetCharWidth (int c);
+	int GetCharHeight (int c);
+
+	//Calculates the size in pixels of a character array
+	template<class T> void GetStringSize (const T *text,
+		std::pair<int, int> *size)
+	{
+		const T *i;
+		GLFontChar *glfont_char;
+		float width;
+		
+		//Height is the same for now...might change in future
+		size->second = (int)(header.chars[header.start_char]->dy *
+			header.tex_height);
+
+		//Calculate width of string
+		width = 0.0F;
+		for (i = text; *i != (T)'\0'; i++)
+		{
+			//Make sure character is in range
+			if (*i < header.start_char || *i > header.end_char)
+				continue;
+
+			//Get pointer to glFont character
+			glfont_char = &header.chars[*i - header.start_char];
+
+			//Get width and height
+			width += glfont_char->dx * header.tex_width;		
+		}
+
+		//Save width
+		size->first = (int)width;
+	}
+	
+	//Template function to calculate size of a std::basic_string
+	template<class T> void GetStringSize (
+		const std::basic_string<T> &text, std::pair<int, int> *size)
+	{
+		unsigned int i;
+		T *c;
+		GLFontChar *glfont_char;
+		float width;
+		
+		//Height is the same for now...might change in future
+		size->second = (int)(header.chars[header.start_char]->dy *
+			header.tex_height);
+
+		//Calculate width of string
+		width = 0.0F;
+		for (i = 0; i < text.size(); i++)
+		{
+			//Make sure character is in range
+			c = text[i];
+			if (c < header.start_char || c > header.end_char)
+				continue;
+
+			//Get pointer to glFont character
+			glfont_char = &header.chars[c - header.start_char];
+
+			//Get width and height
+			width += glfont_char->dx * header.tex_width;		
+		}
+
+		//Save width
+		size->first = (int)width;
+	}
+
+	//Begins text output with this font
+	void Begin (void);
+
+	//Template function to output a character array
+	template<class T> void DrawString (const T *text, float x,
+		float y)
+	{
+		const T *i;
+		GLFontChar *glfont_char;
+		float width, height;
+		
+		//Begin rendering quads
+		glBegin(GL_QUADS);
+		
+		//Loop through characters
+		for (i = text; *i != (T)'\0'; i++)
+		{
+			//Make sure character is in range
+			if (*i < header.start_char || *i > header.end_char)
+				continue;
+
+			//Get pointer to glFont character
+			glfont_char = &header.chars[*i - header.start_char];
+
+			//Get width and height
+			width = glfont_char->dx * header.tex_width;
+			height = glfont_char->dy * header.tex_height;
+			
+			//Specify vertices and texture coordinates
+			glTexCoord2f(glfont_char->tx1, glfont_char->ty1);
+			glVertex3f(x, y, 0.0F);
+			glTexCoord2f(glfont_char->tx1, glfont_char->ty2);
+			glVertex3f(x, y - height, 0.0F);
+			glTexCoord2f(glfont_char->tx2, glfont_char->ty2);
+			glVertex3f(x + width, y - height, 0.0F);
+			glTexCoord2f(glfont_char->tx2, glfont_char->ty1);
+			glVertex3f(x + width, y, 0.0F);
+		
+			//Move to next character
+			x += width;
+		}
+
+		//Stop rendering quads
+		glEnd();
+	}
+
+	//Template function to draw a std::basic_string
+	template<class T> void DrawString (
+		const std::basic_string<T> &text, float x, float y)
+	{
+		unsigned int i;
+		T c;
+		GLFontChar *glfont_char;
+		float width, height;
+		
+		//Begin rendering quads
+		glBegin(GL_QUADS);
+		
+		//Loop through characters
+		for (i = 0; i < text.size(); i++)
+		{
+			//Make sure character is in range
+			c = text[i];
+			if (c < header.start_char || c > header.end_char)
+				continue;
+
+			//Get pointer to glFont character
+			glfont_char = &header.chars[c - header.start_char];
+
+			//Get width and height
+			width = glfont_char->dx * header.tex_width;
+			height = glfont_char->dy * header.tex_height;
+			
+			//Specify vertices and texture coordinates
+			glTexCoord2f(glfont_char->tx1, glfont_char->ty1);
+			glVertex3f(x, y, 0.0F);
+			glTexCoord2f(glfont_char->tx1, glfont_char->ty2);
+			glVertex3f(x, y - height, 0.0F);
+			glTexCoord2f(glfont_char->tx2, glfont_char->ty2);
+			glVertex3f(x + width, y - height, 0.0F);
+			glTexCoord2f(glfont_char->tx2, glfont_char->ty1);
+			glVertex3f(x + width, y, 0.0F);
+		
+			//Move to next character
+			x += width;
+		}
+
+		//Stop rendering quads
+		glEnd();
+	}
+
+	//Template function to output a scaled character array
+	template<class T> void DrawString (const T *text, float scalar,
+		float x, float y)
+	{
+		const T *i;
+		GLFontChar *glfont_char;
+		float width, height;
+		
+		//Begin rendering quads
+		glBegin(GL_QUADS);
+		
+		//Loop through characters
+		for (i = text; *i != (T)'\0'; i++)
+		{
+			//Make sure character is in range
+			if (*i < header.start_char || *i > header.end_char)
+				continue;
+
+			//Get pointer to glFont character
+			glfont_char = &header.chars[*i - header.start_char];
+
+			//Get width and height
+			width = (glfont_char->dx * header.tex_width) * scalar;
+			height = (glfont_char->dy * header.tex_height) * scalar;
+			
+			//Specify vertices and texture coordinates
+			glTexCoord2f(glfont_char->tx1, glfont_char->ty1);
+			glVertex3f(x, y, 0.0F);
+			glTexCoord2f(glfont_char->tx1, glfont_char->ty2);
+			glVertex3f(x, y - height, 0.0F);
+			glTexCoord2f(glfont_char->tx2, glfont_char->ty2);
+			glVertex3f(x + width, y - height, 0.0F);
+			glTexCoord2f(glfont_char->tx2, glfont_char->ty1);
+			glVertex3f(x + width, y, 0.0F);
+		
+			//Move to next character
+			x += width;
+		}
+
+		//Stop rendering quads
+		glEnd();
+	}
+
+	//Template function to output a scaled std::basic_string
+	template<class T> void DrawString (
+		const std::basic_string<T> &text, float scalar, float x,
+		float y)
+	{
+		unsigned int i;
+		T c;
+		GLFontChar *glfont_char;
+		float width, height;
+		
+		//Begin rendering quads
+		glBegin(GL_QUADS);
+		
+		//Loop through characters
+		for (i = 0; i < text.size(); i++)
+		{
+			//Make sure character is in range
+			c = text[i];
+			if (c < header.start_char || c > header.end_char)
+				continue;
+
+			//Get pointer to glFont character
+			glfont_char = &header.chars[c - header.start_char];
+
+			//Get width and height
+			width = (glfont_char->dx * header.tex_width) * scalar;
+			height = (glfont_char->dy * header.tex_height) * scalar;
+			
+			//Specify vertices and texture coordinates
+			glTexCoord2f(glfont_char->tx1, glfont_char->ty1);
+			glVertex3f(x, y, 0.0F);
+			glTexCoord2f(glfont_char->tx1, glfont_char->ty2);
+			glVertex3f(x, y - height, 0.0F);
+			glTexCoord2f(glfont_char->tx2, glfont_char->ty2);
+			glVertex3f(x + width, y - height, 0.0F);
+			glTexCoord2f(glfont_char->tx2, glfont_char->ty1);
+			glVertex3f(x + width, y, 0.0F);
+		
+			//Move to next character
+			x += width;
+		}
+
+		//Stop rendering quads
+		glEnd();
+	}
+
+	//Template function to output a colored character array
+	template<class T> void DrawString (const T *text, float x,
+		float y, const float *top_color,
+		const float *bottom_color)
+	{
+		const T *i;
+		GLFontChar *glfont_char;
+		float width, height;
+		
+		//Begin rendering quads
+		glBegin(GL_QUADS);
+		
+		//Loop through characters
+		for (i = text; *i != '\0'; i++)
+		{
+			//Make sure character is in range
+			if (*i < header.start_char || *i > header.end_char)
+				continue;
+
+			//Get pointer to glFont character
+			glfont_char = &header.chars[*i - header.start_char];
+
+			//Get width and height
+			width = glfont_char->dx * header.tex_width;
+			height = glfont_char->dy * header.tex_height;
+			
+			//Specify colors, vertices, and texture coordinates
+			glColor3fv(top_color);
+			glTexCoord2f(glfont_char->tx1, glfont_char->ty1);
+			glVertex3f(x, y, 0.0F);
+			glTexCoord2f(glfont_char->tx2, glfont_char->ty1);
+			glVertex3f(x + width, y, 0.0F);
+			glColor3fv(bottom_color);
+			glTexCoord2f(glfont_char->tx2, glfont_char->ty2);
+			glVertex3f(x + width, y - height, 0.0F);
+			glTexCoord2f(glfont_char->tx1, glfont_char->ty2);
+			glVertex3f(x, y - height, 0.0F);		
+		
+			//Move to next character
+			x += width;
+		}
+
+		//Stop rendering quads
+		glEnd();
+	}
+
+	//Template function to output a colored std::basic_string
+	template<class T> void DrawString (
+		const std::basic_string<T> &text, float x, float y,
+		const float *top_color, const float *bottom_color)
+	{
+		unsigned int i;
+		T c;
+		GLFontChar *glfont_char;
+		float width, height;
+		
+		//Begin rendering quads
+		glBegin(GL_QUADS);
+		
+		//Loop through characters
+		for (i = 0; i < text.size(); i++)
+		{
+			//Make sure character is in range
+			c = text[i];
+			if (c < header.start_char || c > header.end_char)
+				continue;
+
+			//Get pointer to glFont character
+			glfont_char = &header.chars[c - header.start_char];
+
+			//Get width and height
+			width = glfont_char->dx * header.tex_width;
+			height = glfont_char->dy * header.tex_height;
+			
+			//Specify colors, vertices, and texture coordinates
+			glColor3fv(top_color);
+			glTexCoord2f(glfont_char->tx1, glfont_char->ty1);
+			glVertex3f(x, y, 0.0F);
+			glTexCoord2f(glfont_char->tx2, glfont_char->ty1);
+			glVertex3f(x + width, y, 0.0F);
+			glColor3fv(bottom_color);
+			glTexCoord2f(glfont_char->tx2, glfont_char->ty2);
+			glVertex3f(x + width, y - height, 0.0F);
+			glTexCoord2f(glfont_char->tx1, glfont_char->ty2);
+			glVertex3f(x, y - height, 0.0F);		
+		
+			//Move to next character
+			x += width;
+		}
+
+		//Stop rendering quads
+		glEnd();
+	}
+
+	//Template function to output a scaled, colored character array
+	template<class T> void DrawString (const T *text, float scalar,
+		float x, float y, const float *top_color,
+		const float *bottom_color)
+	{
+		const T *i;
+		GLFontChar *glfont_char;
+		float width, height;
+		
+		//Begin rendering quads
+		glBegin(GL_QUADS);
+		
+		//Loop through characters
+		for (i = text; *i != '\0'; i++)
+		{
+			//Make sure character is in range
+			if (*i < header.start_char || *i > header.end_char)
+				continue;
+
+			//Get pointer to glFont character
+			glfont_char = &header.chars[*i - header.start_char];
+
+			//Get width and height
+			width = (glfont_char->dx * header.tex_width) * scalar;
+			height = (glfont_char->dy * header.tex_height) * scalar;
+			
+			//Specify colors, vertices, and texture coordinates
+			glColor3fv(top_color);
+			glTexCoord2f(glfont_char->tx1, glfont_char->ty1);
+			glVertex3f(x, y, 0.0F);
+			glTexCoord2f(glfont_char->tx2, glfont_char->ty1);
+			glVertex3f(x + width, y, 0.0F);
+			glColor3fv(bottom_color);
+			glTexCoord2f(glfont_char->tx2, glfont_char->ty2);
+			glVertex3f(x + width, y - height, 0.0F);
+			glTexCoord2f(glfont_char->tx1, glfont_char->ty2);
+			glVertex3f(x, y - height, 0.0F);		
+		
+			//Move to next character
+			x += width;
+		}
+
+		//Stop rendering quads
+		glEnd();
+	}
+
+	//Template function to output a scaled, colored std::basic_string
+	template<class T> void DrawString (
+		const std::basic_string<T> &text, float scalar, float x,
+		float y, const float *top_color, const float *bottom_color)
+	{
+		unsigned int i;
+		T c;
+		GLFontChar *glfont_char;
+		float width, height;
+		
+		//Begin rendering quads
+		glBegin(GL_QUADS);
+		
+		//Loop through characters
+		for (i = 0; i < text.size(); i++)
+		{
+			//Make sure character is in range
+			c = text[i];
+			if (c < header.start_char || c > header.end_char)
+				continue;
+
+			//Get pointer to glFont character
+			glfont_char = &header.chars[c - header.start_char];
+
+			//Get width and height
+			width = (glfont_char->dx * header.tex_width) * scalar;
+			height = (glfont_char->dy * header.tex_height) * scalar;
+			
+			//Specify colors, vertices, and texture coordinates
+			glColor3fv(top_color);
+			glTexCoord2f(glfont_char->tx1, glfont_char->ty1);
+			glVertex3f(x, y, 0.0F);
+			glTexCoord2f(glfont_char->tx2, glfont_char->ty1);
+			glVertex3f(x + width, y, 0.0F);
+			glColor3fv(bottom_color);
+			glTexCoord2f(glfont_char->tx2, glfont_char->ty2);
+			glVertex3f(x + width, y - height, 0.0F);
+			glTexCoord2f(glfont_char->tx1, glfont_char->ty2);
+			glVertex3f(x, y - height, 0.0F);		
+		
+			//Move to next character
+			x += width;
+		}
+
+		//Stop rendering quads
+		glEnd();
+	}
+};
+
+//*******************************************************************
+
+#endif
+
+//End of file
+
Index: GTP/trunk/App/Demos/Vis/FriendlyCulling/src/RenderQueue.cpp
===================================================================
--- GTP/trunk/App/Demos/Vis/FriendlyCulling/src/RenderQueue.cpp	(revision 2819)
+++ GTP/trunk/App/Demos/Vis/FriendlyCulling/src/RenderQueue.cpp	(revision 2826)
@@ -62,6 +62,8 @@
 	Material *mat = ent->GetMaterial();
 
-	// test if entity 
-	//if (mat->IsAlphaTestEnabled() != mBuckets[idx]->mAlphaTestEnabled) return false;
+	// test if entity belongs to this bucket
+	// note: rather slows down the application for some reason!!
+	if (0 && mat->IsAlphaTestEnabled() != mBuckets[idx]->mAlphaTestEnabled)
+		return false;
 
 	const bool hasTexture = (mat->GetTexture() != NULL);
Index: GTP/trunk/App/Demos/Vis/FriendlyCulling/FriendlyCulling.vcproj
===================================================================
--- GTP/trunk/App/Demos/Vis/FriendlyCulling/FriendlyCulling.vcproj	(revision 2825)
+++ GTP/trunk/App/Demos/Vis/FriendlyCulling/FriendlyCulling.vcproj	(revision 2826)
@@ -224,4 +224,12 @@
 			</File>
 			<File
+				RelativePath=".\src\glfont2.cpp"
+				>
+			</File>
+			<File
+				RelativePath=".\src\glfont2.h"
+				>
+			</File>
+			<File
 				RelativePath=".\src\glInterface.h"
 				>
