Index: GTP/trunk/App/Demos/Vis/FriendlyCulling/src/RenderTraverser.cpp
===================================================================
--- GTP/trunk/App/Demos/Vis/FriendlyCulling/src/RenderTraverser.cpp	(revision 2954)
+++ GTP/trunk/App/Demos/Vis/FriendlyCulling/src/RenderTraverser.cpp	(revision 3031)
@@ -97,5 +97,5 @@
 	if (node->GetLastRenderedFrame() != mFrameId)
 	{
-		if (mRenderState->SetState(RenderState::RENDER))
+		if (mRenderState->SetMode(RenderState::RENDER))
 			++ mStats.mNumStateChanges;
 		
@@ -254,5 +254,5 @@
 
 	// change to query mode and render box
-	if (mRenderState->SetState(RenderState::QUERY))
+	if (mRenderState->SetMode(RenderState::QUERY))
 		++ mStats.mNumStateChanges;
 
@@ -265,5 +265,5 @@
 void RenderTraverser::ApplyRenderQueue()
 {
-	if (mRenderState->SetState(RenderState::RENDER))
+	if (mRenderState->SetMode(RenderState::RENDER))
 		++ mStats.mNumStateChanges;
 		 
Index: GTP/trunk/App/Demos/Vis/FriendlyCulling/src/ShaderProgram.cpp
===================================================================
--- GTP/trunk/App/Demos/Vis/FriendlyCulling/src/ShaderProgram.cpp	(revision 3030)
+++ GTP/trunk/App/Demos/Vis/FriendlyCulling/src/ShaderProgram.cpp	(revision 3031)
@@ -92,4 +92,6 @@
 
 	cgGLSetTextureParameter(p, tex);
+	cgGLEnableTextureParameter(p);
+
 	mTextureParams.push_back(p);
 }
@@ -101,8 +103,8 @@
 
 	// enable all texture parameters
-	/*CGParameterArray::const_iterator it, it_end = mTextureParams.end();
+	CGParameterArray::const_iterator it, it_end = mTextureParams.end();
+
 	for (it = mTextureParams.begin(); it != it_end; ++ it) 
 		cgGLEnableTextureParameter(*it);
-	*/
 }
 
Index: GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/mrt.cg
===================================================================
--- GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/mrt.cg	(revision 3018)
+++ GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/mrt.cg	(revision 3031)
@@ -43,6 +43,5 @@
 
 vtxout vtx(vtxin IN, 
-		   const uniform float4x4 ModelViewProj,
-		   uniform float4x4 ModelView)
+		   uniform float4x4 modelView)
 {
 	vtxout OUT;
@@ -52,5 +51,5 @@
 
 	//OUT.worldPos = mul(glstate.matrix.inverse.projection, OUT.position);
-	OUT.worldPos = mul(ModelView, IN.position);
+	OUT.worldPos = mul(modelView, IN.position);
 	// transform the vertex position into eye space
 	OUT.position = mul(glstate.matrix.mvp, IN.position);
@@ -75,5 +74,4 @@
 
 pixel fragtex(fragin IN, 
-			  uniform sampler2D dirtTex,
 			  uniform sampler2D tex,
 			  uniform float3 eyePos,
Index: GTP/trunk/App/Demos/Vis/FriendlyCulling/src/RenderState.cpp
===================================================================
--- GTP/trunk/App/Demos/Vis/FriendlyCulling/src/RenderState.cpp	(revision 3028)
+++ GTP/trunk/App/Demos/Vis/FriendlyCulling/src/RenderState.cpp	(revision 3031)
@@ -15,4 +15,7 @@
 ShaderProgram *RenderState::sCgMrtFragmentProgram = NULL;
 ShaderProgram *RenderState::sCgMrtFragmentTexProgram = NULL;
+ShaderProgram *RenderState::sCgMrtVertexProgram = NULL;
+
+
 int RenderState::sTexParam;
 
@@ -34,5 +37,5 @@
 
 	
-bool RenderState::SetState(Mode mode)
+bool RenderState::SetMode(Mode mode)
 {
 	///////////
@@ -85,6 +88,8 @@
 
 	
-void RenderState::SetState(bool texturing, bool alphaTest, bool cullFace)
-{
+void RenderState::SetState(Texture *tex, bool alphaTest, bool cullFace)
+{
+	const bool texturing = (tex != NULL);
+
 	if (!mLockCullFaceEnabled)
 	{
@@ -146,4 +151,6 @@
 		}
 	}
+
+	SetTexture(tex);
 }
 
@@ -166,5 +173,5 @@
 	glDisableClientState(GL_TEXTURE_COORD_ARRAY);
 
-	SetState(RENDER);
+	SetMode(RENDER);
 }
 
@@ -196,18 +203,14 @@
 void RenderState::SetTexture(Texture *tex)
 {
-	if (tex)
-	{
-		if (GetRenderPassType() == RenderState::DEFERRED)
-		{
-			RenderState::sCgMrtFragmentProgram->SetTexture("tex", tex->GetId());
-		}
-		else
-		{
+	if (GetRenderPassType() == RenderState::DEFERRED)
+	{
+		if (tex)
+			RenderState::sCgMrtFragmentTexProgram->SetTexture("tex", tex->GetId());
+	}
+	else
+	{
+		if (tex)
 			tex->Bind();
-		}
-	}
-	else
-	{
-		if (!GetRenderPassType() == RenderState::DEFERRED)
+		else
 			glBindTexture(GL_TEXTURE_2D, 0);		
 	}
Index: GTP/trunk/App/Demos/Vis/FriendlyCulling/src/RenderState.h
===================================================================
--- GTP/trunk/App/Demos/Vis/FriendlyCulling/src/RenderState.h	(revision 3028)
+++ GTP/trunk/App/Demos/Vis/FriendlyCulling/src/RenderState.h	(revision 3031)
@@ -44,8 +44,8 @@
 		change was issued.
 	*/
-	bool SetState(Mode mode);
+	bool SetMode(Mode mode);
 	/** Sets the current render state.
 	*/
-	void SetState(bool texturing, bool alphaTest, bool cullFace);
+	void SetState(Texture *tex, bool alphaTest, bool cullFace);
 	/** Returns either query or render mode
 	*/
@@ -86,4 +86,5 @@
 	static ShaderProgram *sCgMrtFragmentProgram;
 	static ShaderProgram *sCgMrtFragmentTexProgram;
+	static ShaderProgram *sCgMrtVertexProgram;
 
 	static int sTexParam;
Index: GTP/trunk/App/Demos/Vis/FriendlyCulling/src/Material.cpp
===================================================================
--- GTP/trunk/App/Demos/Vis/FriendlyCulling/src/Material.cpp	(revision 3028)
+++ GTP/trunk/App/Demos/Vis/FriendlyCulling/src/Material.cpp	(revision 3031)
@@ -57,7 +57,5 @@
 void Material::Render(RenderState *state)
 {
-	state->SetState(mTexture != NULL, mAlphaTestEnabled, mCullFaceEnabled);
-
-	state->SetTexture(mTexture);
+	state->SetState(mTexture, mAlphaTestEnabled, mCullFaceEnabled);
 
 	glMaterialfv(GL_FRONT, GL_AMBIENT, (float *)&mAmbientColor.r);
Index: GTP/trunk/App/Demos/Vis/FriendlyCulling/src/Transform3.cpp
===================================================================
--- GTP/trunk/App/Demos/Vis/FriendlyCulling/src/Transform3.cpp	(revision 2960)
+++ GTP/trunk/App/Demos/Vis/FriendlyCulling/src/Transform3.cpp	(revision 3031)
@@ -1,4 +1,5 @@
 #include "Transform3.h"
 #include "RenderState.h"
+#include "ShaderProgram.h"
 
 
@@ -33,5 +34,6 @@
 	if (state->GetRenderPassType() == RenderState::DEFERRED)
 	{
-		cgGLSetMatrixParameterfc(sModelMatrixParam, (const float *)mMatrix.x);
+		//cgGLSetMatrixParameterfc(sModelMatrixParam, (const float *)mMatrix.x);
+		RenderState::sCgMrtVertexProgram->SetMatrix("modelView", mMatrix);
 	}
 
@@ -49,5 +51,5 @@
 	{
 		static Matrix4x4 identity = IdentityMatrix();
-		cgGLSetMatrixParameterfc(sModelMatrixParam, (const float *)identity.x);
+		RenderState::sCgMrtVertexProgram->SetMatrix("modelView", identity);
 	}
 
Index: GTP/trunk/App/Demos/Vis/FriendlyCulling/src/chcdemo.cpp
===================================================================
--- GTP/trunk/App/Demos/Vis/FriendlyCulling/src/chcdemo.cpp	(revision 3028)
+++ GTP/trunk/App/Demos/Vis/FriendlyCulling/src/chcdemo.cpp	(revision 3031)
@@ -282,6 +282,4 @@
 static CGcontext sCgContext = NULL;
 
-ShaderProgram *sCgMrtVertexProgram = NULL;
-
 static CGparameter sEyePosParamTex;
 static CGparameter sEyePosParam;
@@ -490,7 +488,4 @@
 	InitCg();
 
-	DeferredRenderer::InitCG(sCgContext);
-	SkyPreetham::InitCG(sCgContext);
-
 	Vector3 cubeCenter(470.398f, 240.364f, 182.5f);
 	
@@ -557,8 +552,8 @@
 	cgGLSetManageTextureParameters(sCgContext, true);
 
-	sCgMrtVertexProgram = 
-		new ShaderProgram(sCgContext, "src/shaders/mrt.cg", RenderState::sCgFragmentProfile, "vtx");
-
-	if (!sCgMrtVertexProgram->IsValid())
+	RenderState::sCgMrtVertexProgram = 
+		new ShaderProgram(sCgContext, "src/shaders/mrt.cg", RenderState::sCgVertexProfile, "vtx");
+
+	if (!RenderState::sCgMrtVertexProgram->IsValid())
 		cerr << "fragment program failed to load" << endl;
 
@@ -567,5 +562,5 @@
 
 	if (!RenderState::sCgMrtFragmentTexProgram->IsValid())
-		cerr << "fragment program failed to load" << endl;
+		cerr << "fragment tex program failed to load" << endl;
 
 	RenderState::sCgMrtFragmentProgram = 
@@ -577,4 +572,7 @@
 
 	PrintGLerror("init");
+
+	DeferredRenderer::InitCG(sCgContext);
+	SkyPreetham::InitCG(sCgContext);
 
 	cout << "cg initialization successful" << endl;
@@ -856,5 +854,5 @@
 	if ((renderMethod == RENDER_DEFERRED) || (renderMethod == RENDER_DEPTH_PASS_DEFERRED))
 	{
-		cgGLSetMatrixParameterfc(Transform3::sModelMatrixParam, (const float *)IdentityMatrix().x);
+		RenderState::sCgMrtVertexProgram->SetMatrix("modelView", IdentityMatrix());
 	}
 }
@@ -908,5 +906,5 @@
 
 	cgGLEnableProfile(RenderState::sCgVertexProfile);
-	sCgMrtVertexProgram->Bind();
+	RenderState::sCgMrtVertexProgram->Bind();
 
 	cgGLEnableProfile(RenderState::sCgFragmentProfile);
@@ -915,6 +913,6 @@
 	const Vector3 pos = camera->GetPosition();
 
-	cgGLSetParameter3f(sEyePosParam, pos.x, pos.y, pos.z);
-	cgGLSetParameter3f(sEyePosParamTex, pos.x, pos.y, pos.z);
+	RenderState::sCgMrtFragmentProgram->SetValue3f("eyePos", pos.x, pos.y, pos.z);
+	RenderState::sCgMrtFragmentTexProgram->SetValue3f("eyePos", pos.x, pos.y, pos.z);
 
 
@@ -1751,5 +1749,5 @@
 	DEL_PTR(RenderState::sCgMrtFragmentProgram);
 	DEL_PTR(RenderState::sCgMrtFragmentTexProgram);
-	DEL_PTR(sCgMrtVertexProgram);
+	DEL_PTR(RenderState::sCgMrtVertexProgram);
 	
 	DeferredRenderer::ReleaseCG();
