Index: /GTP/trunk/App/Demos/Vis/FriendlyCulling/src/PerformanceGraph.h
===================================================================
--- /GTP/trunk/App/Demos/Vis/FriendlyCulling/src/PerformanceGraph.h	(revision 2827)
+++ /GTP/trunk/App/Demos/Vis/FriendlyCulling/src/PerformanceGraph.h	(revision 2827)
@@ -0,0 +1,33 @@
+#ifndef _PERFORMANCEGRAPH_H
+#define _PERFORMANCEGRAPH_H
+
+#include <vector>
+
+/** Class for drawing a performance graph into the render window
+*/
+class PerformanceGraph
+{
+public:
+	
+	PerformanceGraph(const int maxData);
+
+	void Draw();
+
+	void AddData(float data);
+
+	void Reset();
+
+
+protected:
+
+	void DrawGrid();
+	void DrawBackGround();
+	void DrawCurve();
+
+	std::vector<float> mData;
+
+	int mMaxData;
+	int mCurrentIdx;
+};
+
+#endif
Index: /GTP/trunk/App/Demos/Vis/FriendlyCulling/src/chcdemo.cpp
===================================================================
--- /GTP/trunk/App/Demos/Vis/FriendlyCulling/src/chcdemo.cpp	(revision 2826)
+++ /GTP/trunk/App/Demos/Vis/FriendlyCulling/src/chcdemo.cpp	(revision 2827)
@@ -27,5 +27,5 @@
 #include <Cg/cgGL.h>
 #include "glfont2.h"
-
+#include "PerformanceGraph.h"
 
 
@@ -157,4 +157,6 @@
 int renderType = RenderState::FIXED;
 
+PerformanceGraph *perfGraph = NULL;
+
 
 #define NUM_SAMPLES 8
@@ -318,4 +320,5 @@
 	MiddleMotion(0, 0);
 
+	perfGraph = new PerformanceGraph(500);
 
 	loader = new ResourceManager();
@@ -653,20 +656,15 @@
 
 
-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);	
+bool InitFont(void)
+{
 	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))
+	if (!myfont.Create("data/fonts/myfont.glf", fontTex))
 		return false;
 
 	glDisable(GL_TEXTURE_2D);
-	//Return successfully
+	
 	return true;
 }
@@ -711,5 +709,5 @@
 	glDepthFunc(GL_LESS);
 
-	if (!Initfont())
+	if (!InitFont())
 		cerr << "font creation failed" << endl;
 	else
@@ -718,44 +716,5 @@
 
 
-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);
-}
-
-
-void DrawHelpMessage(void) 
+void DrawHelpMessage() 
 {
 	const char *message[] = 
@@ -766,7 +725,7 @@
 		"'F2'           - shows/hides bird eye view",
 		"'F3'           - shows/hides bounds (boxes or tight bounds)",
-		"'F4'           - shows/hides statistics",
-		"'F5',          - shows/hides parameters",
-		"'F6',          - toggles between fly / walkmode",
+		"'F4',          - shows/hides parameters",
+		"'F5'           - shows/hides statistics",
+		"'F6',          - toggles between fly/walkmode",
 		"'F7',          - cycles throw render modes",
 		"'F8',          - enables/disables ambient occlusion (only deferred)",
@@ -774,20 +733,14 @@
 		"'SPACE'        - cycles through occlusion culling algorithms",
 		"",
-		"'MOUSE-LEFT'   - turn left/right, move forward/backward",
-		"'MOUSE-RIGHT'  - turn left/right, move forward/backward",
-		"'MOUSE-MIDDLE' - move up/down, left/right",
-		"'CURSOR UP'    - move forward",
-		"'CURSOR BACK'  - move backward",
-		"'CURSOR RIGHT' - turn right",
-		"'CURSOR LEFT'  - turn left",
+		"'MOUSE LEFT'        - turn left/right, move forward/backward",
+		"'MOUSE RIGHT'       - turn left/right, move forward/backward",
+		"'MOUSE MIDDLE'      - move up/down, left/right",
+		"'CURSOR UP/DOWN'    - move forward/backward",
+		"'CURSOR LEFT/RIGHT' - turn left/right",
 		"",
-		"'-'            - decreases max batch size",
-		"'+'            - increases max batch size",
-		"'4'            - decrease triangles per virtual leaf (sets depth of bvh)",
-		"'5'            - increase triangles per virtual leaf (sets depth of bvh)",
-		"'6'            - decrease assumed visible frames",
-		"'7'            - increase assumed visible frames",
-		"'8'            - downward motion",
-		"'9'            - upward motion",
+		"'-'/'+'        - decreases/increases max batch size",
+		"'4'/'5'        - decreases/increases triangles per virtual bvh leaf (sets bvh depth)",
+		"'6'/'7'        - decreases/increases assumed visible frames",
+		"'8'/'9'        - downward/upward motion",
 		"",
 		"'R'            - use render queue",
@@ -799,18 +752,17 @@
 	
 	
-	int x = 40, y = 60;
-
-	glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
-	glEnable(GL_BLEND);
-	glColor4f(0.0f, 1.0f , 0.0f, 0.2f);  // 20% green. 
-
-	// Drawn clockwise because the flipped Y axis flips CCW and CW. 
-	glRecti(winWidth - 30, 30, 30, winHeight - 30);
-	
-	glDisable(GL_BLEND);
-	
+	glColor4f(0.0f, 1.0f , 0.0f, 0.2f); // 20% green. 
+
+	glRecti(30, 30, winWidth - 30, winHeight - 30);
+
+	glEnd();
+
 	glColor3f(1.0f, 1.0f, 1.0f);
 	
-	for(int i = 0; message[i] != 0; i++) 
+	myfont.Begin();
+
+	int x = 40, y = 30;
+
+	for(int i = 0; message[i] != 0; ++ i) 
 	{
 		if(message[i][0] == '\0') 
@@ -820,6 +772,6 @@
 		else 
 		{
-			Output(x, y, message[i]);
-			y += 20;
+			myfont.DrawString(message[i], x, winHeight - y);
+			y += 25;
 		}
 	}
@@ -874,10 +826,8 @@
 	glEnable(GL_LIGHT1);
 	
-	//GLfloat ambient[] = {0.5, 0.5, 0.5, 1.0};
 	GLfloat ambient[] = {0.2, 0.2, 0.2, 1.0};
 	GLfloat diffuse[] = {1.0, 1.0, 1.0, 1.0};
 	GLfloat specular[] = {1.0, 1.0, 1.0, 1.0};
 	    
-	//GLfloat lmodel_ambient[] = {0.5f, 0.5f, 0.5f, 1.0f};
 	GLfloat lmodel_ambient[] = {0.3f, 0.3f, 0.3f, 1.0f};
 
@@ -1103,15 +1053,21 @@
 	}
 
+	
+	///////////
+
+	state.SetRenderType(RenderState::FIXED);
+
 	if (showAlgorithmTime)
 	{
 		glFinish();
+
 		algTime = algTimer.Elapsedms();
-	}
-
-	///////////
-
-	state.SetRenderType(RenderState::FIXED);
-
-	if (visMode) DisplayVisualization();
+		perfGraph->AddData(algTime);
+		perfGraph->Draw();
+	}
+	else
+	{
+		if (visMode) DisplayVisualization();
+	}
 
 	DisplayStats();
@@ -1293,8 +1249,8 @@
 		break;
 	case GLUT_KEY_F4:
+		showOptions = !showOptions;
+		break;
+	case GLUT_KEY_F5:
 		showStatistics = !showStatistics;
-		break;
-	case GLUT_KEY_F5:
-		showOptions = !showOptions;
 		break;
 	case GLUT_KEY_F6:
@@ -1491,4 +1447,9 @@
 	gluOrtho2D(0, winWidth, 0, winHeight);
 
+	int w = winWidth / 2;
+	int h = winHeight / 2;
+	
+	//glOrtho(-w, w, -h, h, 0, 10);
+
 	glMatrixMode(GL_MODELVIEW);
 	glPushMatrix();
@@ -1508,20 +1469,4 @@
 
 
-void Output(int x, int y, const char *string) 
-{
-	if (string != 0) 
-	{
-		size_t len, i;
-		glRasterPos2f(x, y);
-		len = strlen(string);
-		
-		for (i = 0; i < len; ++ i) 
-		{
-			glutBitmapCharacter(GLUT_BITMAP_HELVETICA_18, string[i]);
-		}
-	}
-}
-
-
 // displays the visualisation of culling algorithm
 void DisplayVisualization()
@@ -1532,7 +1477,7 @@
 	glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
 	glEnable(GL_BLEND);
-	glColor4f(0.0,0.0,0.0,0.5); 
-
-	glRecti(winWidth, 0, winWidth - winWidth / 3, winHeight / 3);
+	glColor4f(0.0f ,0.0f, 0.0f, 0.5f); 
+
+	glRecti(winWidth - winWidth / 3, winHeight - winHeight / 3, winWidth, winHeight);
 	glDisable(GL_BLEND);
 	End2D();
@@ -1599,7 +1544,12 @@
 	DEL_PTR(loader);
 	DEL_PTR(renderQueue);
+	DEL_PTR(perfGraph);
 
 	if (sCgMrtVertexProgram)
 		cgDestroyProgram(sCgMrtVertexProgram);
+	if (RenderState::sCgMrtFragmentProgram)
+		cgDestroyProgram(RenderState::sCgMrtFragmentProgram);
+	if (RenderState::sCgMrtFragmentTexProgram)
+		cgDestroyProgram(RenderState::sCgMrtFragmentTexProgram);
 	if (sCgSsaoProgram)
 		cgDestroyProgram(sCgSsaoProgram);
@@ -1619,4 +1569,5 @@
 	glDeleteTextures(1, &positionsTex);
 	glDeleteTextures(1, &noiseTex);
+	glDeleteTextures(1, &fontTex);
 }
 
@@ -1625,5 +1576,7 @@
 void CalcDecimalPoint(string &str, int d)
 {
-	vector<int> numbers;
+	static vector<int> numbers;
+	numbers.clear();
+
 	char hstr[100];
 
@@ -1700,10 +1653,4 @@
 
 
-
-	glClear(GL_DEPTH_BUFFER_BIT);
-	//Draw a string
-	glColor3f(1.0f, 1.0f, 1.0f);
-	myfont.Begin();
-
 	//DrawFont();
 	if (showHelp)
@@ -1713,5 +1660,7 @@
 	else
 	{
-		glColor3f(1.0f, 0.5f, 0.5f);
+		myfont.Begin();
+
+		glColor3f(0.0f, 1.0f, 0.0f);
 
 		if (showOptions)
@@ -1732,8 +1681,8 @@
 
 			for (int j = 0; j < 4; ++ j)
-				myfont.DrawString(msg[j], 1.0F, 20.0f, 760 - j * 30);
+				myfont.DrawString(msg[j], 20.0f, 760 - j * 30);
 		}
 
-		glColor3f(0.5f, 1.0f, 0.5f);
+		glColor3f(0.0f, 1.0f, 1.0f);
 
 		if (showStatistics)
@@ -1757,24 +1706,23 @@
 
 			for (int j = 4; j < 7; ++ j)
-				myfont.DrawString(msg[j], 1.0F, 20.0f, 760 - j * 30);
+				myfont.DrawString(msg[j], 20.0f, 760 - j * 30);
 		}
-
-		//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]);
-		}		
+		
+		if (!showAlgorithmTime)
+		{
+			sprintf(msg[7], "%s:  %6.1f fps", alg_str[renderMode], fps);
+		}
+		else
+		{
+			sprintf(msg[7], "%s:  %6.1f ms", alg_str[renderMode], rTime);
+		}
+
+		myfont.DrawString(msg[7], 720.0f, 760.0f);//, top_color, bottom_color);
+		
+		//sprintf(msg[8], "algorithm time: %6.1f ms", rTime);
+		//myfont.DrawString(msg[8], 720.0f, 730.0f);		
 	}
 
Index: /GTP/trunk/App/Demos/Vis/FriendlyCulling/src/PerformanceGraph.cpp
===================================================================
--- /GTP/trunk/App/Demos/Vis/FriendlyCulling/src/PerformanceGraph.cpp	(revision 2827)
+++ /GTP/trunk/App/Demos/Vis/FriendlyCulling/src/PerformanceGraph.cpp	(revision 2827)
@@ -0,0 +1,129 @@
+#include "PerformanceGraph.h"
+#include "glInterface.h"
+
+
+PerformanceGraph::PerformanceGraph(int maxData): 
+mMaxData(maxData), mCurrentIdx(0)
+{
+}
+
+	
+void PerformanceGraph::DrawBackGround()
+{
+	glEnable(GL_BLEND);
+	glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
+
+	glColor4f(0.0f, 0.0f, 0.0f, 0.5f);
+
+	// show a grid
+	glBegin(GL_QUADS);
+	glVertex3f(0, 0, 0.0f);
+	glVertex3f(1, 0, 0.0f);
+	glVertex3f(1, 1, 0.0f);
+	glVertex3f(0, 1, 0.0f);
+	glEnd();
+
+	glDisable(GL_BLEND);
+}
+
+
+void PerformanceGraph::DrawGrid()
+{
+	glColor4f(0.0f, 1.0f, 0.0f, 1.0f);
+
+	// show a grid
+	glBegin(GL_LINE_LOOP);
+	glVertex3f(0, 0, 0.0f);
+	glVertex3f(1, 0, 0.0f);
+	glVertex3f(1, 1, 0.0f);
+	glVertex3f(0, 1, 0.0f);
+	glEnd();
+}
+
+
+void PerformanceGraph::Draw()
+{
+	glPushAttrib(GL_ALL_ATTRIB_BITS);
+
+	glLineWidth(2);
+	glDisable(GL_DEPTH_TEST);
+	//glDepthMask(true);
+
+	glDisable(GL_LIGHTING);
+	glDisable(GL_TEXTURE_2D);
+
+	// init ortographic projection
+	glMatrixMode(GL_PROJECTION);
+	glPushMatrix();
+	glLoadIdentity();
+
+	gluOrtho2D(0, 1.0f, 0, 1.0f);
+
+	glMatrixMode(GL_MODELVIEW);
+	glPushMatrix();
+	glLoadIdentity();
+	
+	glTranslatef(0.68f, 0.68f, 0.0f);
+	glScalef(0.3f, 0.3f, 1.0f);
+
+	DrawBackGround();
+	DrawCurve();
+	DrawGrid();
+
+	glPopMatrix();
+	
+	// restore the projection matrix
+	glMatrixMode(GL_PROJECTION);
+	glPopMatrix();
+
+	glMatrixMode(GL_MODELVIEW);
+
+	glPopAttrib();
+}
+
+
+void PerformanceGraph::DrawCurve()
+{
+	const float scalex = 1.0f / mMaxData;
+	const float scaley = 1.0f / 50.0f;
+
+	glColor4f(1.0f, 0, 0, 1.0f);
+
+	glBegin(GL_LINE_STRIP);
+
+	//OUT1("data: " << mData.size());
+
+	for (size_t i = 0; i < mData.size(); ++ i)
+	{
+		const float x = i * scalex;
+		const float y = mData[i] * scaley;
+
+		glVertex3f(x, y, 0.0f);
+	}
+
+	glEnd();
+
+	// show a grid
+	glBegin(GL_LINES);
+	glVertex3f(mCurrentIdx * scalex, 0, 0.0f);
+	glVertex3f(mCurrentIdx * scalex, 1, 0.0f);
+	glEnd();
+}
+
+
+void PerformanceGraph::AddData(float data)
+{
+	if ((int)mData.size() < mMaxData)
+		mData.push_back(data);
+	else
+		mData[mCurrentIdx]= data;
+
+	mCurrentIdx = (mCurrentIdx + 1) % mMaxData;
+}
+
+
+void PerformanceGraph::Reset()
+{
+	mCurrentIdx = 0;
+	mData.clear();
+}
Index: /GTP/trunk/App/Demos/Vis/FriendlyCulling/FriendlyCulling.vcproj
===================================================================
--- /GTP/trunk/App/Demos/Vis/FriendlyCulling/FriendlyCulling.vcproj	(revision 2826)
+++ /GTP/trunk/App/Demos/Vis/FriendlyCulling/FriendlyCulling.vcproj	(revision 2827)
@@ -252,4 +252,12 @@
 			</File>
 			<File
+				RelativePath=".\src\PerformanceGraph.cpp"
+				>
+			</File>
+			<File
+				RelativePath=".\src\PerformanceGraph.h"
+				>
+			</File>
+			<File
 				RelativePath=".\src\Plane3.cpp"
 				>
