changeset 51:efd2b1ca5b77

Clean up gui
author koryspansel <koryspansel@bendbroadband.com>
date Tue, 27 Sep 2011 09:42:01 -0700
parents 7ff46a00bcd3
children 2444937929ae
files Assets/Maps/map00.def Assets/Maps/map01.def Assets/Maps/map02.def Assets/Maps/map03.def Assets/Maps/map04.def Data/Maps/map00.map Data/Maps/map01.map Data/Maps/map02.map Data/Maps/map03.map Data/Maps/map04.map Data/Shaders/TexturedQuad.fx LightClone/LightClone.vcproj LightClone/Source/GraphicsDevice.cpp LightClone/Source/GuiButton.cpp LightClone/Source/GuiButton.h LightClone/Source/GuiCursor.cpp LightClone/Source/GuiCursor.h LightClone/Source/GuiElement.cpp LightClone/Source/GuiElement.h LightClone/Source/GuiImage.cpp LightClone/Source/GuiImage.h LightClone/Source/GuiLabel.cpp LightClone/Source/GuiLabel.h LightClone/Source/GuiRenderContext.cpp LightClone/Source/GuiRenderContext.h LightClone/Source/HashMap.h LightClone/Source/HashMapIterator.h LightClone/Source/Loader.cpp LightClone/Source/ResourceManager.cpp LightClone/Source/VertexTypes.cpp LightClone/Source/VertexTypes.h LightClone/Source/World.cpp LightClone/ToDo.txt LightTools/build.py
diffstat 34 files changed, 612 insertions(+), 781 deletions(-) [+]
line wrap: on
line diff
--- a/Assets/Maps/map00.def	Fri Sep 23 17:58:17 2011 -0700
+++ b/Assets/Maps/map00.def	Tue Sep 27 09:42:01 2011 -0700
@@ -5,62 +5,11 @@
 7,7
 3,1
 0
-2
-10
-10
 
-0,1
-0,1
-0,1
-0,1
-0,1
-0,1
-0,1
-
-0,1
-0,1
-0,1
-0,1
-0,1
-0,1
-0,1
-
-0,1
-0,1
-0,1
-0,1
-0,1
-0,1
-0,1
-
-0,1
-0,1
-0,1
-0,1
-0,1
-0,1
-0,1
-
-0,1
-0,1
-0,1
-1,1
-0,1
-0,1
-0,1
-
-0,1
-0,1
-0,1
-0,1
-0,1
-0,1
-0,1
-
-0,1
-0,1
-0,1
-0,1
-0,1
-0,1
-0,1
+(1,0)(1,0)(1,0)(1,0)(1,0)(1,0)(1,0)
+(1,0)(1,0)(1,0)(1,0)(1,0)(1,0)(1,0)
+(1,0)(1,0)(1,0)(1,0)(1,0)(1,0)(1,0)
+(1,0)(1,0)(1,0)(1,0)(1,0)(1,0)(1,0)
+(1,0)(1,0)(1,0)(1,1)(1,0)(1,0)(1,0)
+(1,0)(1,0)(1,0)(1,0)(1,0)(1,0)(1,0)
+(1,0)(1,0)(1,0)(1,0)(1,0)(1,0)(1,0)
--- a/Assets/Maps/map01.def	Fri Sep 23 17:58:17 2011 -0700
+++ b/Assets/Maps/map01.def	Tue Sep 27 09:42:01 2011 -0700
@@ -5,62 +5,11 @@
 7,7
 3,1
 0
-2
-10
-10
 
-0,1
-0,1
-0,1
-0,1
-0,1
-0,1
-0,1
-
-0,1
-0,1
-0,1
-0,1
-0,1
-0,1
-0,1
-
-0,1
-0,1
-0,1
-0,1
-0,1
-0,1
-0,1
-
-0,2
-0,2
-0,2
-0,2
-0,2
-0,2
-0,2
-
-0,1
-0,1
-0,1
-0,1
-0,1
-0,1
-0,1
-
-0,1
-0,1
-0,1
-1,1
-0,1
-0,1
-0,1
-
-0,1
-0,1
-0,1
-0,1
-0,1
-0,1
-0,1
+(1,0)(1,0)(1,0)(1,0)(1,0)(1,0)(1,0)
+(1,0)(1,0)(1,0)(1,0)(1,0)(1,0)(1,0)
+(1,0)(1,0)(1,0)(1,0)(1,0)(1,0)(1,0)
+(2,0)(2,0)(2,0)(2,0)(2,0)(2,0)(2,0)
+(1,0)(1,0)(1,0)(1,0)(1,0)(1,0)(1,0)
+(1,0)(1,0)(1,0)(1,1)(1,0)(1,0)(1,0)
+(1,0)(1,0)(1,0)(1,0)(1,0)(1,0)(1,0)
--- a/Assets/Maps/map02.def	Fri Sep 23 17:58:17 2011 -0700
+++ b/Assets/Maps/map02.def	Tue Sep 27 09:42:01 2011 -0700
@@ -1,66 +1,15 @@
 #
-# map00
+# map02
 #
 
 7,7
 3,1
 0
-2
-10
-10
 
-0,1
-0,1
-0,1
-0,1
-0,1
-0,1
-0,1
-
-0,1
-0,1
-0,1
-0,1
-0,1
-0,1
-0,1
-
-0,1
-0,1
-0,1
-0,1
-0,1
-0,1
-0,1
-
-0,1
-0,1
-0,1
-0,1
-0,1
-0,1
-0,1
-
-0,1
-0,1
-0,1
-1,1
-0,1
-1,1
-0,1
-
-0,1
-0,1
-0,1
-0,1
-0,1
-0,1
-0,1
-
-0,1
-0,1
-0,1
-0,1
-0,1
-0,1
-0,1
+(1,0)(1,0)(1,0)(1,0)(1,0)(1,0)(1,0)
+(1,0)(1,0)(1,0)(1,0)(1,0)(1,0)(1,0)
+(1,0)(1,0)(1,0)(1,0)(1,0)(1,0)(1,0)
+(1,0)(1,0)(1,0)(1,0)(1,0)(1,0)(1,0)
+(1,0)(1,0)(1,0)(1,1)(1,0)(1,1)(1,0)
+(1,0)(1,0)(1,0)(1,0)(1,0)(1,0)(1,0)
+(1,0)(1,0)(1,0)(1,0)(1,0)(1,0)(1,0)
--- a/Assets/Maps/map03.def	Fri Sep 23 17:58:17 2011 -0700
+++ b/Assets/Maps/map03.def	Tue Sep 27 09:42:01 2011 -0700
@@ -1,66 +1,15 @@
 #
-# map00
+# map03
 #
 
 7,7
 3,1
 0
-2
-10
-10
 
-0,1
-0,1
-0,1
-0,1
-0,1
-0,1
-0,1
-
-0,1
-0,1
-0,1
-0,1
-0,1
-0,1
-0,1
-
-0,1
-0,1
-0,1
-1,2
-0,1
-0,1
-0,1
-
-0,1
-0,1
-1,2
-0,1
-1,2
-0,1
-0,1
-
-0,1
-0,1
-0,1
-1,2
-0,1
-0,1
-0,1
-
-0,1
-0,1
-0,1
-0,1
-0,1
-0,1
-0,1
-
-0,1
-0,1
-0,1
-0,1
-0,1
-0,1
-0,1
+(1,0)(1,0)(1,0)(1,0)(1,0)(1,0)(1,0)
+(1,0)(1,0)(1,0)(1,0)(1,0)(1,0)(1,0)
+(1,0)(1,0)(1,0)(2,1)(1,0)(1,0)(1,0)
+(1,0)(1,0)(2,1)(1,0)(2,1)(1,0)(1,0)
+(1,0)(1,0)(1,0)(2,1)(1,0)(1,0)(1,0)
+(1,0)(1,0)(1,0)(1,0)(1,0)(1,0)(1,0)
+(1,0)(1,0)(1,0)(1,0)(1,0)(1,0)(1,0)
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Assets/Maps/map04.def	Tue Sep 27 09:42:01 2011 -0700
@@ -0,0 +1,15 @@
+#
+# map04
+#
+
+7,7
+0,0
+0
+
+(1,1)(1,1)(1,1)(1,1)(1,1)(1,1)(1,1)
+(1,1)(1,0)(1,0)(1,0)(1,0)(1,0)(1,1)
+(1,1)(1,0)(1,0)(1,0)(1,0)(1,0)(1,1)
+(1,1)(1,0)(1,0)(1,0)(1,0)(1,0)(1,1)
+(1,1)(1,0)(1,0)(1,0)(1,0)(1,0)(1,1)
+(1,1)(1,0)(1,0)(1,0)(1,0)(1,0)(1,1)
+(1,1)(1,1)(1,1)(1,1)(1,1)(1,1)(1,1)
Binary file Data/Maps/map00.map has changed
Binary file Data/Maps/map01.map has changed
Binary file Data/Maps/map02.map has changed
Binary file Data/Maps/map03.map has changed
Binary file Data/Maps/map04.map has changed
--- a/Data/Shaders/TexturedQuad.fx	Fri Sep 23 17:58:17 2011 -0700
+++ b/Data/Shaders/TexturedQuad.fx	Tue Sep 27 09:42:01 2011 -0700
@@ -32,6 +32,27 @@
 };
 
 /*
+ * VertexInput1
+ */
+struct VertexInput1
+{
+	/*
+	 * Position
+	 */
+	float3 Position : POSITION0;
+
+	/*
+	 * TextureCoordinate
+	 */
+	float2 TextureCoordinate : TEXCOORD0;
+	
+	/*
+	 * Color
+	 */
+	float4 Color : COLOR0;
+};
+
+/*
  * VertexOutput
  */
 struct VertexOutput
@@ -48,6 +69,27 @@
 };
 
 /*
+ * VertexOutput1
+ */
+struct VertexOutput1
+{
+	/*
+	 * Position
+	 */
+	float4 Position : POSITION0;
+
+	/*
+	 * TextureCoordinate
+	 */
+	float2 TextureCoordinate : TEXCOORD0;
+	
+	/*
+	 * Color
+	 */
+	float4 Color : COLOR0;
+};
+
+/*
  * PixelInput
  */
 struct PixelInput
@@ -88,6 +130,20 @@
 }
 
 /*
+ * TexturedQuadVS
+ */
+VertexOutput1 TexturedQuadVS1(VertexInput1 kInput)
+{
+	VertexOutput1 kOutput;
+
+	kOutput.Position			= mul(float4(kInput.Position, 1.0f), kProjection);
+	kOutput.TextureCoordinate	= kInput.TextureCoordinate;
+	kOutput.Color				= kInput.Color;
+
+	return kOutput;
+}
+
+/*
  * TexturedQuadPS
  */
 PixelOutput TexturedQuadPS(PixelInput kInput)
@@ -102,6 +158,19 @@
 	return kOutput;
 }
 
+/*
+ * TexturedQuadPS
+ */
+PixelOutput TexturedQuadPS1(PixelInput kInput)
+{
+	PixelOutput kOutput;
+
+	float4 kTexture = tex2D(TextureSampler, kInput.TextureCoordinate);
+	kOutput.Color = float4(kTexture.rgb * kInput.Color.rgb, kTexture.a);
+
+	return kOutput;
+}
+
 technique Default
 {
 	pass Opaque
@@ -109,15 +178,31 @@
 		vertexShader		= compile vs_2_0 TexturedQuadVS();
 		pixelShader			= compile ps_2_0 TexturedQuadPS();
 
-		/*
-		ZEnable				= true;
-		ZWriteEnable		= true;
-		ZFunc				= LessEqual;
-		*/
+		//ZEnable				= true;
+		//ZWriteEnable		= true;
+		//ZFunc				= LessEqual;
 
 		AlphaBlendEnable	= true;
 		AlphaFunc			= LessEqual;
 		SrcBlend			= SrcAlpha;
 		DestBlend			= InvSrcAlpha;
 	}
-}
\ No newline at end of file
+}
+
+technique Color
+{
+	pass Opaque
+	{
+		vertexShader		= compile vs_2_0 TexturedQuadVS1();
+		pixelShader			= compile ps_2_0 TexturedQuadPS1();
+
+		ZEnable				= true;
+		ZWriteEnable		= true;
+		//ZFunc				= LessEqual;
+
+		AlphaBlendEnable	= true;
+		AlphaFunc			= LessEqual;
+		SrcBlend			= SrcAlpha;
+		DestBlend			= InvSrcAlpha;
+	}
+}
--- a/LightClone/LightClone.vcproj	Fri Sep 23 17:58:17 2011 -0700
+++ b/LightClone/LightClone.vcproj	Tue Sep 27 09:42:01 2011 -0700
@@ -513,6 +513,10 @@
 					RelativePath="..\Assets\Maps\map03.def"
 					>
 				</File>
+				<File
+					RelativePath="..\Assets\Maps\map04.def"
+					>
+				</File>
 			</Filter>
 		</Filter>
 		<File
--- a/LightClone/Source/GraphicsDevice.cpp	Fri Sep 23 17:58:17 2011 -0700
+++ b/LightClone/Source/GraphicsDevice.cpp	Tue Sep 27 09:42:01 2011 -0700
@@ -206,4 +206,5 @@
 	pDevice->SetVertexDeclaration(pDeclaration);
 	pDevice->SetStreamSource(0, pBuffer, 0, nSize);
 	pDevice->DrawPrimitive(D3DPT_TRIANGLELIST, 0, nCount);
+	pDevice->SetStreamSource(0, NULL, 0, 0);
 }
--- a/LightClone/Source/GuiButton.cpp	Fri Sep 23 17:58:17 2011 -0700
+++ b/LightClone/Source/GuiButton.cpp	Tue Sep 27 09:42:01 2011 -0700
@@ -14,7 +14,7 @@
 /*
  * GuiButton
  */
-GuiButton::GuiButton() : nState(GuiButtonState_Normal), pEffect(NULL), pVertexBuffer(NULL), pFont(NULL)
+GuiButton::GuiButton() : GuiElement(), nState(GuiButtonState_Normal), pFont(NULL)
 {
 	SetFlag(GuiElementFlag_Pickable);
 
@@ -22,88 +22,18 @@
 }
 
 /*
- * Initialize
- */
-ErrorCode GuiButton::Initialize(ResourceManager* pManager)
-{
-	ErrorCode eCode = pManager->CreateEffectFromFile("Data\\Shaders\\TexturedQuad.fx", &pEffect);
-	if(eCode == Error_Success)
-	{
-		eCode = pManager->CreateVertexBuffer(6 * sizeof(Vertex::Quad), D3DUSAGE_WRITEONLY, D3DPOOL_MANAGED, &pVertexBuffer);
-		if(eCode == Error_Success)
-		{
-			eCode = SetupVertexBuffer();
-			if(eCode == Error_Success)
-			{
-				pResourceManager = pManager;
-			}
-		}
-	}
-
-	return eCode;
-}
-
-/*
- * Terminate
- */
-void GuiButton::Terminate()
-{
-	if(pVertexBuffer)
-	{
-		pVertexBuffer->Release();
-		pVertexBuffer = NULL;
-	}
-}
-
-/*
- * Update
- */
-void GuiButton::Update(float fElapsed)
-{
-}
-
-/*
  * Render
  */
-//void GuiButton::Render(RenderContext& kContext, Camera& kCamera)
 void GuiButton::Render(GuiRenderContext& kContext)
 {
 	if(nFlags & GuiElementFlag_Visible)
 	{
 		if(pTexture[nState])
 		{
-			uint32 nPasses = 0;
-
-			const float fOffsetX = -0.5f * ScreenSizeX;
-			const float fOffsetY = +0.5f * ScreenSizeY;
-
-			const D3DXVECTOR4 kColorVector(1.0f, 1.0f, 1.0f, 1.0f);
-
-			kContext.GetRenderContext()->ApplyCameraToEffect(*kContext.GetCamera(), pEffect);
-
-			D3DXMATRIX kScale;
-			D3DXMatrixScaling(&kScale, kDimensions.x, kDimensions.y, 1.0f);
-
 			const D3DXVECTOR2& kLocation = GetPosition();
 
-			D3DXMATRIX kTranslate;
-			D3DXMatrixTranslation(&kTranslate, fOffsetX + kLocation.x + 0.5f, fOffsetY - kLocation.y + 0.5f, 0.0f);
-
-			D3DXMATRIX kWorldMatrix;
-			D3DXMatrixMultiply(&kWorldMatrix, &kScale, &kTranslate);
-
-			pEffect->SetMatrix(pEffect->GetParameterByName(NULL, "kWorld"), &kWorldMatrix);
-			pEffect->SetVector(pEffect->GetParameterByName(NULL, "kColor"), &kColorVector);
-			pEffect->SetTexture(pEffect->GetParameterByName(NULL, "kTexture"), pTexture[nState]);
-
-			pEffect->SetTechnique(pEffect->GetTechnique(0));
-			pEffect->Begin(&nPasses, 0);
-			pEffect->BeginPass(0);
-
-			kContext.GetRenderContext()->DrawTriangles(Vertex::Quad::Declaration, pVertexBuffer, sizeof(Vertex::Quad), TrianglesPerFace);
-
-			pEffect->EndPass();
-			pEffect->End();
+			kContext.Add(pTexture[nState], kLocation, 1.0f, GetDimensions(), D3DCOLOR_XRGB(255, 255, 255));
+			kContext.Flush();
 
 			if(pFont && kText.Length() > 0)
 			{
@@ -256,28 +186,3 @@
 		nState = GuiButtonState_Hover;
 	}
 }
-
-/*
- * SetupVertexBuffer
- */
-ErrorCode GuiButton::SetupVertexBuffer()
-{
-	Vertex::Quad* pVertices = NULL;
-
-	HRESULT hResult = pVertexBuffer->Lock(0, 0, (void**)&pVertices, D3DLOCK_DISCARD);
-	if(FAILED(hResult))
-	{
-		return Error_Fail;
-	}
-
-	pVertices[0] = Vertex::Quad(+0.0f, -1.0f, 1.0f, 0.0f, 1.0f);
-	pVertices[1] = Vertex::Quad(+0.0f, +0.0f, 1.0f, 0.0f, 0.0f);
-	pVertices[2] = Vertex::Quad(+1.0f, +0.0f, 1.0f, 1.0f, 0.0f);
-	pVertices[3] = Vertex::Quad(+0.0f, -1.0f, 1.0f, 0.0f, 1.0f);
-	pVertices[4] = Vertex::Quad(+1.0f, +0.0f, 1.0f, 1.0f, 0.0f);
-	pVertices[5] = Vertex::Quad(+1.0f, -1.0f, 1.0f, 1.0f, 1.0f);
-
-	pVertexBuffer->Unlock();
-
-	return Error_Success;
-}
--- a/LightClone/Source/GuiButton.h	Fri Sep 23 17:58:17 2011 -0700
+++ b/LightClone/Source/GuiButton.h	Tue Sep 27 09:42:01 2011 -0700
@@ -35,26 +35,11 @@
 private:
 
 	/*
-	 * pResourceManager
-	 */
-	ResourceManager* pResourceManager;
-
-	/*
 	 * nState
 	 */
 	uint32 nState;
 
 	/*
-	 * pEffect
-	 */
-	ID3DXEffect* pEffect;
-
-	/*
-	 * pVertexBuffer
-	 */
-	IDirect3DVertexBuffer9* pVertexBuffer;
-
-	/*
 	 * pTexture
 	 */
 	IDirect3DTexture9* pTexture[GuiButtonState_Count];
@@ -77,25 +62,9 @@
 	GuiButton();
 
 	/*
-	 * Initialize
-	 */
-	virtual ErrorCode Initialize(ResourceManager* pManager);
-
-	/*
-	 * Terminate
-	 */
-	virtual void Terminate();
-
-	/*
-	 * Update
-	 */
-	virtual void Update(float fElapsed);
-
-	/*
 	 * Render
 	 */
 	virtual void Render(GuiRenderContext& kContext);
-	//virtual void Render(RenderContext& kContext, Camera& kCamera);
 
 	/*
 	 * SetTexture
@@ -136,13 +105,6 @@
 	 * OnMouseMove
 	 */
 	virtual void OnMouseMove(float fX, float fY);
-
-private:
-
-	/*
-	 * SetupVertexBuffer
-	 */
-	ErrorCode SetupVertexBuffer();
 };
 
 #endif //__GUIBUTTON_H__
--- a/LightClone/Source/GuiCursor.cpp	Fri Sep 23 17:58:17 2011 -0700
+++ b/LightClone/Source/GuiCursor.cpp	Tue Sep 27 09:42:01 2011 -0700
@@ -8,57 +8,18 @@
 /*
  * GuiCursor
  */
-GuiCursor::GuiCursor() : pEffect(NULL), pVertexBuffer(NULL), pTexture(NULL)
-{
-}
-
-/*
- * Initialize
- */
-ErrorCode GuiCursor::Initialize(ResourceManager* pManager)
-{
-	pResourceManager = pManager;
-
-	ErrorCode eCode = pResourceManager->CreateEffectFromFile("Data\\Shaders\\TexturedQuad.fx", &pEffect);
-	if(eCode == Error_Success)
-	{
-		eCode = pResourceManager->CreateVertexBuffer(6 * sizeof(Vertex::Quad), D3DUSAGE_WRITEONLY, D3DPOOL_MANAGED, &pVertexBuffer);
-		if(eCode == Error_Success)
-		{
-			eCode = SetupVertexBuffer();
-		}
-	}
-
-	return eCode;
-}
-
-/*
- * Terminate
- */
-void GuiCursor::Terminate()
-{
-	if(pVertexBuffer)
-	{
-		pVertexBuffer->Release();
-		pVertexBuffer = NULL;
-	}
-}
-
-/*
- * Update
- */
-void GuiCursor::Update(float fElapsed)
+GuiCursor::GuiCursor() : GuiElement(), pTexture(NULL)
 {
 }
 
 /*
  * Render
  */
-//void GuiCursor::Render(RenderContext& kContext, Camera& kCamera)
 void GuiCursor::Render(GuiRenderContext& kContext)
 {
 	if(pTexture)
 	{
+		/*
 		uint32 nPasses = 0;
 
 		const float fOffsetX = -0.5f * ScreenSizeX;
@@ -90,6 +51,8 @@
 
 		pEffect->EndPass();
 		pEffect->End();
+		*/
+		kContext.Add(pTexture, GetPosition(), GetDepth(), GetDimensions(), kColor);
 	}
 
 	GuiElement::Render(kContext);
@@ -117,28 +80,3 @@
 
 	return eCode;
 }
-
-/*
- * SetupVertexBuffer
- */
-ErrorCode GuiCursor::SetupVertexBuffer()
-{
-	Vertex::Quad* pVertices = NULL;
-
-	HRESULT hResult = pVertexBuffer->Lock(0, 0, (void**)&pVertices, D3DLOCK_DISCARD);
-	if(FAILED(hResult))
-	{
-		return Error_Fail;
-	}
-
-	pVertices[0]	= Vertex::Quad(+0.0f, -1.0f, 1.0f, 0.0f, 1.0f);
-	pVertices[1]	= Vertex::Quad(+0.0f, +0.0f, 1.0f, 0.0f, 0.0f);
-	pVertices[2]	= Vertex::Quad(+1.0f, +0.0f, 1.0f, 1.0f, 0.0f);
-	pVertices[3]	= Vertex::Quad(+0.0f, -1.0f, 1.0f, 0.0f, 1.0f);
-	pVertices[4]	= Vertex::Quad(+1.0f, +0.0f, 1.0f, 1.0f, 0.0f);
-	pVertices[5]	= Vertex::Quad(+1.0f, -1.0f, 1.0f, 1.0f, 1.0f);
-
-	pVertexBuffer->Unlock();
-
-	return Error_Success;
-}
--- a/LightClone/Source/GuiCursor.h	Fri Sep 23 17:58:17 2011 -0700
+++ b/LightClone/Source/GuiCursor.h	Tue Sep 27 09:42:01 2011 -0700
@@ -14,21 +14,6 @@
 class GuiCursor : public GuiElement
 {
 	/*
-	 * pResourceManager
-	 */
-	ResourceManager* pResourceManager;
-
-	/*
-	 * pEffect
-	 */
-	ID3DXEffect* pEffect;
-
-	/*
-	 * pVertexBuffer
-	 */
-	IDirect3DVertexBuffer9* pVertexBuffer;
-
-	/*
 	 * pTexture
 	 */
 	IDirect3DTexture9* pTexture;
@@ -41,37 +26,14 @@
 	GuiCursor();
 
 	/*
-	 * Initialize
-	 */
-	virtual ErrorCode Initialize(ResourceManager* pResourceManager);
-
-	/*
-	 * Terminate
-	 */
-	virtual void Terminate();
-
-	/*
-	 * Update
-	 */
-	virtual void Update(float fElapsed);
-
-	/*
 	 * Render
 	 */
-	//virtual void Render(RenderContext& kContext, Camera& kCamera);
 	virtual void Render(GuiRenderContext& kContext);
 
 	/*
 	 * SetTexture
 	 */
 	ErrorCode SetTexture(const char* pName, bool bResize = true);
-
-private:
-
-	/*
-	 * SetupVertexBuffer
-	 */
-	ErrorCode SetupVertexBuffer();
 };
 
 #endif //__GUICURSOR_H__
--- a/LightClone/Source/GuiElement.cpp	Fri Sep 23 17:58:17 2011 -0700
+++ b/LightClone/Source/GuiElement.cpp	Tue Sep 27 09:42:01 2011 -0700
@@ -12,8 +12,14 @@
 /*
  * GuiElement
  */
-GuiElement::GuiElement() : pContainer(NULL), kPosition(0.0f, 0.0f), kDimensions(0.0f, 0.0f), kColor(0xFFFFFFFF), nFlags(GuiElementFlag_Visible)
+GuiElement::GuiElement()
 {
+	pContainer	= NULL;
+	kPosition	= D3DXVECTOR2(0.0f, 0.0f);
+	fDepth		= 1.0f;
+	kDimensions	= D3DXVECTOR2(0.0f, 0.0f);
+	kColor		= D3DCOLOR_XRGB(255, 255, 255);
+	nFlags		= GuiElementFlag_Visible;
 }
 
 /*
@@ -26,8 +32,11 @@
 /*
  * Initialize
  */
-ErrorCode GuiElement::Initialize(ResourceManager* pResourceManager)
+ErrorCode GuiElement::Initialize(ResourceManager* pManager)
 {
+	//ASSERT(pManager != NULL);
+	pResourceManager = pManager;
+
 	return Error_Success;
 }
 
@@ -52,7 +61,6 @@
 /*
  * Render
  */
-//void GuiElement::Render(RenderContext& kContext, Camera& kCamera)
 void GuiElement::Render(GuiRenderContext& kContext)
 {
 	if(nFlags & GuiElementFlag_Visible)
@@ -127,6 +135,22 @@
 }
 
 /*
+ * SetDepth
+ */
+void GuiElement::SetDepth(float fValue)
+{
+	fDepth = fValue;
+}
+
+/*
+ * GetDepth
+ */
+float GuiElement::GetDepth() const
+{
+	return fDepth;
+}
+
+/*
  * SetDimensions
  */
 void GuiElement::SetDimensions(float fWidth, float fHeight)
--- a/LightClone/Source/GuiElement.h	Fri Sep 23 17:58:17 2011 -0700
+++ b/LightClone/Source/GuiElement.h	Tue Sep 27 09:42:01 2011 -0700
@@ -47,6 +47,11 @@
 protected:
 
 	/*
+	 * pResourceManager
+	 */
+	ResourceManager* pResourceManager;
+
+	/*
 	 * pInterface
 	 */
 	GuiInterface* pInterface;
@@ -62,6 +67,11 @@
 	D3DXVECTOR2 kPosition;
 
 	/*
+	 * fDepth
+	 */
+	float fDepth;
+
+	/*
 	 * kDimensions
 	 */
 	D3DXVECTOR2 kDimensions;
@@ -111,7 +121,6 @@
 	/*
 	 * Render
 	 */
-	//virtual void Render(RenderContext& kContext, Camera& kCamera);
 	virtual void Render(GuiRenderContext& kContext);
 
 	/*
@@ -150,6 +159,16 @@
 	const D3DXVECTOR2 GetPosition() const;
 
 	/*
+	 * SetDepth
+	 */
+	void SetDepth(float fDepth);
+
+	/*
+	 * GetDepth
+	 */
+	float GetDepth() const;
+
+	/*
 	 * SetDimensions
 	 */
 	void SetDimensions(float fWidth, float fHeight);
--- a/LightClone/Source/GuiImage.cpp	Fri Sep 23 17:58:17 2011 -0700
+++ b/LightClone/Source/GuiImage.cpp	Tue Sep 27 09:42:01 2011 -0700
@@ -8,100 +8,28 @@
 /*
  * GuiImage
  */
-GuiImage::GuiImage() : pEffect(NULL), pVertexBuffer(NULL), pTexture(NULL)
+GuiImage::GuiImage() : pTexture(NULL)
 {
 }
 
 /*
  * Initialize
  */
-ErrorCode GuiImage::Initialize(ResourceManager* pManager)
+ErrorCode GuiImage::Initialize(ResourceManager* pResourceManager)
 {
-	pResourceManager = pManager;
-
-	/*
-	ErrorCode eCode = pResourceManager->CreateEffectFromFile("Data\\Shaders\\TexturedQuad.fx", &pEffect);
-	if(eCode == Error_Success)
-	{
-		eCode = pResourceManager->CreateVertexBuffer(6 * sizeof(Vertex::Quad), D3DUSAGE_WRITEONLY, D3DPOOL_MANAGED, &pVertexBuffer);
-		if(eCode == Error_Success)
-		{
-			eCode = SetupVertexBuffer();
-		}
-	}
-	*/
-
-	return Error_Success;
-}
-
-/*
- * Terminate
- */
-void GuiImage::Terminate()
-{
-	/*
-	if(pVertexBuffer)
-	{
-		pVertexBuffer->Release();
-		pVertexBuffer = NULL;
-	}
-	*/
-}
-
-/*
- * Update
- */
-void GuiImage::Update(float fElapsed)
-{
+	return GuiElement::Initialize(pResourceManager);
 }
 
 /*
  * Render
  */
-//void GuiImage::Render(RenderContext& kContext, Camera& kCamera)
 void GuiImage::Render(GuiRenderContext& kContext)
 {
 	if(nFlags & GuiElementFlag_Visible)
 	{
 		if(pTexture)
 		{
-			/*
-			uint32 nPasses = 0;
-
-			const float fOffsetX = -0.5f * ScreenSizeX;
-			const float fOffsetY = +0.5f * ScreenSizeY;
-
-			const D3DXVECTOR4 kColorVector(1.0f, 1.0f, 1.0f, 1.0f);
-
-			kContext.GetRenderContext()->ApplyCameraToEffect(*kContext.GetCamera(), pEffect);
-
-			D3DXMATRIX kScale;
-			D3DXMatrixScaling(&kScale, kDimensions.x, kDimensions.y, 1.0f);
-
-			const D3DXVECTOR2& kLocation = GetPosition();
-
-			D3DXMATRIX kTranslate;
-			D3DXMatrixTranslation(&kTranslate, fOffsetX + kLocation.x + 0.5f, fOffsetY - kLocation.y + 0.5f, 0.0f);
-
-			D3DXMATRIX kWorldMatrix;
-			D3DXMatrixMultiply(&kWorldMatrix, &kScale, &kTranslate);
-
-			//pEffect->SetMatrix(pEffect->GetParameterByName(NULL, "kWorld"), &kWorldMatrix);
-			//pEffect->SetVector(pEffect->GetParameterByName(NULL, "kColor"), &kColorVector);
-			//pEffect->SetTexture(pEffect->GetParameterByName(NULL, "kTexture"), pTexture);
-
-			//pEffect->SetTechnique(pEffect->GetTechnique(0));
-			//pEffect->Begin(&nPasses, 0);
-			//pEffect->BeginPass(0);
-
-			//kContext.GetRenderContext()->DrawTriangles(Vertex::Quad::Declaration, pVertexBuffer, sizeof(Vertex::Quad), TrianglesPerFace);
-			kContext.AddToBatch(pTexture, kLocation, GetDimensions(), kColor);
-
-			//pEffect->EndPass();
-			//pEffect->End();
-			*/
-
-			kContext.AddToBatch(pTexture, GetPosition(), GetDimensions(), D3DCOLOR_XRGB(255, 255, 255));
+			kContext.Add(pTexture, GetPosition(), GetDepth(), GetDimensions(), D3DCOLOR_XRGB(255, 255, 255));
 		}
 
 		GuiElement::Render(kContext);
@@ -130,28 +58,3 @@
 
 	return eCode;
 }
-
-/*
- * SetupVertexBuffer
- */
-ErrorCode GuiImage::SetupVertexBuffer()
-{
-	Vertex::Quad* pVertices = NULL;
-
-	HRESULT hResult = pVertexBuffer->Lock(0, 0, (void**)&pVertices, D3DLOCK_DISCARD);
-	if(FAILED(hResult))
-	{
-		return Error_Fail;
-	}
-
-	pVertices[0]	= Vertex::Quad(+0.0f, -1.0f, 1.0f, 0.0f, 1.0f);
-	pVertices[1]	= Vertex::Quad(+0.0f, +0.0f, 1.0f, 0.0f, 0.0f);
-	pVertices[2]	= Vertex::Quad(+1.0f, +0.0f, 1.0f, 1.0f, 0.0f);
-	pVertices[3]	= Vertex::Quad(+0.0f, -1.0f, 1.0f, 0.0f, 1.0f);
-	pVertices[4]	= Vertex::Quad(+1.0f, +0.0f, 1.0f, 1.0f, 0.0f);
-	pVertices[5]	= Vertex::Quad(+1.0f, -1.0f, 1.0f, 1.0f, 1.0f);
-
-	pVertexBuffer->Unlock();
-
-	return Error_Success;
-}
--- a/LightClone/Source/GuiImage.h	Fri Sep 23 17:58:17 2011 -0700
+++ b/LightClone/Source/GuiImage.h	Tue Sep 27 09:42:01 2011 -0700
@@ -16,21 +16,6 @@
 protected:
 
 	/*
-	 * pResourceManager
-	 */
-	ResourceManager* pResourceManager;
-
-	/*
-	 * pEffect
-	 */
-	ID3DXEffect* pEffect;
-
-	/*
-	 * pVertexBuffer
-	 */
-	IDirect3DVertexBuffer9* pVertexBuffer;
-
-	/*
 	 * pTexture
 	 */
 	IDirect3DTexture9* pTexture;
@@ -48,32 +33,14 @@
 	virtual ErrorCode Initialize(ResourceManager* pResourceManager);
 
 	/*
-	 * Terminate
-	 */
-	virtual void Terminate();
-
-	/*
-	 * Update
-	 */
-	virtual void Update(float fElapsed);
-
-	/*
 	 * Render
 	 */
-	//virtual void Render(RenderContext& kContext, Camera& kCamera);
 	virtual void Render(GuiRenderContext& kContext);
 
 	/*
 	 * SetTexture
 	 */
 	ErrorCode SetTexture(const char* pName, bool bResize = false);
-
-private:
-
-	/*
-	 * SetupVertexBuffer
-	 */
-	ErrorCode SetupVertexBuffer();
 };
 
 #endif //__GUIIMAGE_H__
--- a/LightClone/Source/GuiLabel.cpp	Fri Sep 23 17:58:17 2011 -0700
+++ b/LightClone/Source/GuiLabel.cpp	Tue Sep 27 09:42:01 2011 -0700
@@ -7,30 +7,16 @@
 /*
  * GuiLabel
  */
-GuiLabel::GuiLabel() : pResourceManager(NULL), pFont(NULL), nLabelFlags(0)
+GuiLabel::GuiLabel() : pFont(NULL), nLabelFlags(0)
 {
 }
 
 /*
  * Initialize
  */
-ErrorCode GuiLabel::Initialize(ResourceManager* pManager)
+ErrorCode GuiLabel::Initialize(ResourceManager* pResourceManager)
 {
-	return pResourceManager = pManager, Error_Success;
-}
-
-/*
- * Terminate
- */
-void GuiLabel::Terminate()
-{
-}
-
-/*
- * Update
- */
-void GuiLabel::Update(float fElapsed)
-{
+	return GuiElement::Initialize(pResourceManager);
 }
 
 /*
@@ -62,6 +48,9 @@
 				nFormat |= DT_VCENTER;
 			}
 
+			//TODO: Hack to draw any pending triangles before drawing text
+			kContext.Flush();
+
 			pFont->DrawTextA(NULL, kLabel, kLabel.Length(), &kRectangle, nFormat | DT_CALCRECT, kColor);
 			pFont->DrawTextA(NULL, kLabel, kLabel.Length(), &kRectangle, nFormat, kColor);
 		}
--- a/LightClone/Source/GuiLabel.h	Fri Sep 23 17:58:17 2011 -0700
+++ b/LightClone/Source/GuiLabel.h	Tue Sep 27 09:42:01 2011 -0700
@@ -24,11 +24,6 @@
 class GuiLabel : public GuiElement
 {
 	/*
-	 * pResourceManager
-	 */
-	ResourceManager* pResourceManager;
-
-	/*
 	 * pFont
 	 */
 	ID3DXFont* pFont;
@@ -56,19 +51,8 @@
 	virtual ErrorCode Initialize(ResourceManager* pResourceManager);
 
 	/*
-	 * Terminate
-	 */
-	virtual void Terminate();
-
-	/*
-	 * Update
-	 */
-	virtual void Update(float fElapsed);
-
-	/*
 	 * Render
 	 */
-	//virtual void Render(RenderContext& kContext, Camera& kCamera);
 	virtual void Render(GuiRenderContext& kContext);
 
 	/*
--- a/LightClone/Source/GuiRenderContext.cpp	Fri Sep 23 17:58:17 2011 -0700
+++ b/LightClone/Source/GuiRenderContext.cpp	Tue Sep 27 09:42:01 2011 -0700
@@ -1,14 +1,13 @@
 /*
- * RenderContext
+ * GuiRenderContext
  */
 
 #include "GuiRenderContext.h"
-#include "VertexTypes.h"
 
 /*
  * GuiRenderContext
  */
-GuiRenderContext::GuiRenderContext() : pContext(NULL), pCamera(NULL), pEffect(NULL), pVertexBuffer(NULL)
+GuiRenderContext::GuiRenderContext() : pContext(NULL), pCamera(NULL), pEffect(NULL), pTexture(NULL), pVertices(NULL), nPrimitiveCount(0)
 {
 }
 
@@ -20,27 +19,7 @@
 	ErrorCode eCode = pResourceManager->CreateEffectFromFile("Data\\Shaders\\TexturedQuad.fx", &pEffect);
 	if(eCode == Error_Success)
 	{
-		eCode = pResourceManager->CreateVertexBuffer(QuadsPerBatch * VerticesPerQuad * sizeof(Vertex::Quad), D3DUSAGE_WRITEONLY, D3DPOOL_MANAGED, &pVertexBuffer);
-		if(eCode == Error_Success)
-		{
-			//eCode = SetupVertexBuffer();
-			Vertex::Quad* pVertices = NULL;
-
-			HRESULT hResult = pVertexBuffer->Lock(0, 0, (void**)&pVertices, D3DLOCK_DISCARD);
-			if(FAILED(hResult))
-			{
-				return Error_Fail;
-			}
-
-			pVertices[0]	= Vertex::Quad(+0.0f, -1.0f, 1.0f, 0.0f, 1.0f);
-			pVertices[1]	= Vertex::Quad(+0.0f, +0.0f, 1.0f, 0.0f, 0.0f);
-			pVertices[2]	= Vertex::Quad(+1.0f, +0.0f, 1.0f, 1.0f, 0.0f);
-			pVertices[3]	= Vertex::Quad(+0.0f, -1.0f, 1.0f, 0.0f, 1.0f);
-			pVertices[4]	= Vertex::Quad(+1.0f, +0.0f, 1.0f, 1.0f, 0.0f);
-			pVertices[5]	= Vertex::Quad(+1.0f, -1.0f, 1.0f, 1.0f, 1.0f);
-
-			pVertexBuffer->Unlock();
-		}
+		eCode = pResourceManager->CreateVertexBuffer(VertexBufferSize, D3DUSAGE_WRITEONLY | D3DUSAGE_DYNAMIC, D3DPOOL_DEFAULT, &pVertexBuffer);
 	}
 
 	return eCode;
@@ -70,16 +49,22 @@
 		pContext = pRenderContext;
 		pCamera = pRenderCamera;
 
-		if(pEffect)
-		{
-			uint32 nPasses = 0;			
+		uint32 nPasses = 0;			
+
+		D3DXHANDLE kTechnique = pEffect->GetTechniqueByName("Color");
+		//ASSERT(kTechnique != NULL);
+
+		pEffect->SetTechnique(kTechnique);
 
-			pEffect->SetTechnique(pEffect->GetTechnique(0));
-			pEffect->Begin(&nPasses, 0);
-			pEffect->BeginPass(0);
+		pEffect->Begin(&nPasses, 0);
+		pEffect->BeginPass(0);
+
+		pContext->ApplyCameraToEffect(*pCamera, pEffect);
 
-			pContext->ApplyCameraToEffect(*pCamera, pEffect);
-		}
+		nPrimitiveCount = 0;
+		pVertices		= NULL;
+
+		pVertexBuffer->Lock(0, 0, (void**)&pVertices, D3DLOCK_DISCARD);
 	}
 }
 
@@ -88,52 +73,115 @@
  */
 void GuiRenderContext::End()
 {
-	pContext = NULL;
-	pCamera	= NULL;
-
-	//TODO: Submit primitives
-
-	/*
-	for each batch:
+	if(pVertices)
 	{
-		// setup effect parameters
-		pEffect->SetMatrix(pEffect->GetParameterByName(NULL, "kWorld"), &kWorldMatrix);
-		pEffect->SetVector(pEffect->GetParameterByName(NULL, "kColor"), &kColorVector);
-		pEffect->SetTexture(pEffect->GetParameterByName(NULL, "kTexture"), pTexture);
+		if(nPrimitiveCount > 0)
+		{
+			pVertexBuffer->Unlock();
+
+			D3DXHANDLE kTextureHandle = pEffect->GetParameterByName(NULL, "kTexture");
+			//ASSERT(kTextureHandle != NULL);
 
+			pEffect->SetTexture(kTextureHandle, pTexture);
+			pEffect->CommitChanges();
+
+			pContext->DrawTriangles(Vertex::ColorQuad::Declaration, pVertexBuffer, sizeof(Vertex::ColorQuad), nPrimitiveCount);
+
+			nPrimitiveCount = 0;
+			pVertices		= NULL;
+			pTexture		= NULL;
+		}
 	}
-	*/
 
 	pEffect->EndPass();
 	pEffect->End();
+
+	pContext = NULL;
+	pCamera	= NULL;
 }
 
 /*
- * AddToBatch
+ * Add
  */
-ErrorCode GuiRenderContext::AddToBatch(IDirect3DTexture9* pTexture, const D3DXVECTOR2& kPosition, const D3DXVECTOR2& kSize, D3DCOLOR kColor)
+ErrorCode GuiRenderContext::Add(IDirect3DTexture9* pInstance, const D3DXVECTOR2& kPosition, float fDepth, const D3DXVECTOR2& kSize, D3DCOLOR kColor)
 {
-	const float fOffsetX = -0.5f * ScreenSizeX;
-	const float fOffsetY = +0.5f * ScreenSizeY;
+	if(pVertices)
+	{
+		if(pInstance != pTexture)
+		{
+			if(nPrimitiveCount > 0)
+			{
+				pVertexBuffer->Unlock();
+
+				D3DXHANDLE kTextureHandle = pEffect->GetParameterByName(NULL, "kTexture");
+				//ASSERT(kTextureHandle != NULL);
+
+				pEffect->SetTexture(kTextureHandle, pTexture);
+				pEffect->CommitChanges();
+
+				pContext->DrawTriangles(Vertex::ColorQuad::Declaration, pVertexBuffer, sizeof(Vertex::ColorQuad), nPrimitiveCount);
 
-	const D3DXVECTOR4 kColorVector(1.0f, 1.0f, 1.0f, 1.0f);
+				nPrimitiveCount = 0;
+				pVertices		= NULL;
+
+				pVertexBuffer->Lock(0, 0, (void**)&pVertices, D3DLOCK_DISCARD);
+			}
+
+			pTexture = pInstance;
+		}
 
-	D3DXMATRIX kScale;
-	D3DXMatrixScaling(&kScale, kSize.x, kSize.y, 1.0f);
+		if(nPrimitiveCount < QuadsPerBatch)
+		{
+			const float fOffsetX = 0.0f;//(nFlags & GuiRenderBatchFlag_CenterX) ? 0.5f : 0.0f;
+			const float fOffsetY = 0.0f;//(nFlags & GuiRenderBatchFlag_CenterY) ? 0.5f : 0.0f;
+
+			const float fX0 = -0.5f * ScreenSizeX + (kPosition.x + fOffsetX + 0.5f);
+			const float fY0 = +0.5f * ScreenSizeY - (kPosition.y + fOffsetY + 0.5f);
+			const float fX1 = -0.5f * ScreenSizeX + (kPosition.x + fOffsetX + kSize.x + 0.5f);
+			const float fY1 = +0.5f * ScreenSizeY - (kPosition.y + fOffsetY + kSize.y + 0.5f);
 
-	D3DXMATRIX kTranslate;
-	D3DXMatrixTranslation(&kTranslate, fOffsetX + kPosition.x + 0.5f, fOffsetY - kPosition.y + 0.5f, 0.0f);
+			*pVertices++ = Vertex::ColorQuad(fX0, fY1, 1.0f, 0.0f, 1.0f, kColor);
+			*pVertices++ = Vertex::ColorQuad(fX0, fY0, 1.0f, 0.0f, 0.0f, kColor);
+			*pVertices++ = Vertex::ColorQuad(fX1, fY0, 1.0f, 1.0f, 0.0f, kColor);
+			*pVertices++ = Vertex::ColorQuad(fX0, fY1, 1.0f, 0.0f, 1.0f, kColor);
+			*pVertices++ = Vertex::ColorQuad(fX1, fY0, 1.0f, 1.0f, 0.0f, kColor);
+			*pVertices++ = Vertex::ColorQuad(fX1, fY1, 1.0f, 1.0f, 1.0f, kColor);
 
-	D3DXMATRIX kWorldMatrix;
-	D3DXMatrixMultiply(&kWorldMatrix, &kScale, &kTranslate);
+			nPrimitiveCount += 2;
+		}
+
+		return Error_Success;
+	}
+
+	return Error_Fail;
+}
 
-	pEffect->SetMatrix(pEffect->GetParameterByName(NULL, "kWorld"), &kWorldMatrix);
-	pEffect->SetVector(pEffect->GetParameterByName(NULL, "kColor"), &kColorVector);
-	pEffect->SetTexture(pEffect->GetParameterByName(NULL, "kTexture"), pTexture);
+/*
+ * Flush
+ */
+void GuiRenderContext::Flush()
+{
+	if(pVertices)
+	{
+		if(nPrimitiveCount > 0)
+		{
+			pVertexBuffer->Unlock();
 
-	pContext->DrawTriangles(Vertex::Quad::Declaration, pVertexBuffer, sizeof(Vertex::Quad), TrianglesPerFace);
+			D3DXHANDLE kTextureHandle = pEffect->GetParameterByName(NULL, "kTexture");
+			//ASSERT(kTextureHandle != NULL);
+
+			pEffect->SetTexture(kTextureHandle, pTexture);
+			pEffect->CommitChanges();
+
+			pContext->DrawTriangles(Vertex::ColorQuad::Declaration, pVertexBuffer, sizeof(Vertex::ColorQuad), nPrimitiveCount);
 
-	return Error_Success;
+			nPrimitiveCount = 0;
+			pVertices		= NULL;
+			pTexture		= NULL;
+
+			pVertexBuffer->Lock(0, 0, (void**)&pVertices, D3DLOCK_DISCARD);
+		}
+	}
 }
 
 /*
@@ -150,4 +198,4 @@
 Camera* GuiRenderContext::GetCamera()
 {
 	return pCamera;
-}
\ No newline at end of file
+}
--- a/LightClone/Source/GuiRenderContext.h	Fri Sep 23 17:58:17 2011 -0700
+++ b/LightClone/Source/GuiRenderContext.h	Tue Sep 27 09:42:01 2011 -0700
@@ -9,6 +9,7 @@
 #include "RenderContext.h"
 #include "Camera.h"
 #include "ResourceManager.h"
+#include "VertexTypes.h"
 
 /*
  * GuiRenderContext
@@ -18,7 +19,7 @@
 	/*
 	 * QuadsPerBatch
 	 */
-	static const uint32 QuadsPerBatch = 256;
+	static const uint32 QuadsPerBatch = 64;
 
 	/*
 	 * VerticesPerQuad
@@ -26,6 +27,11 @@
 	static const uint32 VerticesPerQuad = 6;
 
 	/*
+	 * VertexBufferSize
+	 */
+	static const uint32 VertexBufferSize = QuadsPerBatch * VerticesPerQuad * sizeof(Vertex::ColorQuad);
+
+	/*
 	 * pContext
 	 */
 	RenderContext* pContext;
@@ -45,6 +51,21 @@
 	 */
 	IDirect3DVertexBuffer9* pVertexBuffer;
 
+	/*
+	 * pTexture
+	 */
+	IDirect3DTexture9* pTexture;
+
+	/*
+	 * pVertices
+	 */
+	Vertex::ColorQuad* pVertices;
+
+	/*
+	 * nPrimitiveCount
+	 */
+	uint32 nPrimitiveCount;
+
 public:
 
 	/*
@@ -73,9 +94,14 @@
 	void End();
 
 	/*
-	 * AddToBatch
+	 * Add
 	 */
-	ErrorCode AddToBatch(IDirect3DTexture9* pTexture, const D3DXVECTOR2& kPosition, const D3DXVECTOR2& kSize, D3DCOLOR kColor);
+	ErrorCode Add(IDirect3DTexture9* pInstance, const D3DXVECTOR2& kPosition, float fDepth, const D3DXVECTOR2& kSize, D3DCOLOR kColor);
+
+	/*
+	 * Flush
+	 */
+	void Flush();
 
 	/*
 	 * GetRenderContext
@@ -86,12 +112,6 @@
 	 * GetCamera
 	 */
 	Camera* GetCamera();
-
-private:
-
-	/*
-	 * SetupVertexBuffer
-	 */
 };
 
 #endif //__GUIRENDERCONTEXT_H__
--- a/LightClone/Source/HashMap.h	Fri Sep 23 17:58:17 2011 -0700
+++ b/LightClone/Source/HashMap.h	Tue Sep 27 09:42:01 2011 -0700
@@ -32,7 +32,7 @@
 	/*
 	 * Iterator
 	 */
-	friend class HashMapIterator<HashMap<Key, Value, HashFunction, Size>, Value>;
+	friend class HashMapIterator<HashMap<Key, Value, HashFunction, Size>, Key, Value>;
 
 	/*
 	 * Node
@@ -80,7 +80,7 @@
 	/*
 	 * Iterator
 	 */
-	typedef HashMapIterator<HashMap<Key, Value, HashFunction, Size>, Value> Iterator;
+	typedef HashMapIterator<HashMap<Key, Value, HashFunction, Size>, Key, Value> Iterator;
 
 private:
 
--- a/LightClone/Source/HashMapIterator.h	Fri Sep 23 17:58:17 2011 -0700
+++ b/LightClone/Source/HashMapIterator.h	Tue Sep 27 09:42:01 2011 -0700
@@ -10,7 +10,7 @@
 /*
  * HashMapIterator
  */
-template<typename Map, typename Value>
+template<typename Map, typename KeyType, typename ValueType>
 class HashMapIterator
 {
 	/*
@@ -98,11 +98,27 @@
 	}
 
 	/*
+	 * Key
+	 */
+	KeyType Key()
+	{
+		return pNode ? pNode->kKey : KeyType();
+	}
+
+	/*
+	 * Value
+	 */
+	ValueType Value()
+	{
+		return pNode ? pNode->kValue : ValueType();
+	}
+
+	/*
 	 * operator *
 	 */
-	Value operator *()
+	ValueType operator *()
 	{
-		return pNode ? pNode->kValue : Value();
+		return pNode ? pNode->kValue : ValueType();
 	}
 
 	/*
--- a/LightClone/Source/Loader.cpp	Fri Sep 23 17:58:17 2011 -0700
+++ b/LightClone/Source/Loader.cpp	Tue Sep 27 09:42:01 2011 -0700
@@ -56,8 +56,6 @@
 
 	Buffer kBuffer = LoadFile(pName);
 
-	uint32 nTemp;
-
 	if(kBuffer.Read(&kSize.X) != Error_Success)
 		return Error_Fail;
 
@@ -73,21 +71,11 @@
 	if(kBuffer.Read(&kDirection) != Error_Success)
 		return Error_Fail;
 
-	if(kBuffer.Read(&nTemp) != Error_Success)
-		return Error_Fail;
-
 	if(kSize.X == 0 || kSize.Y == 0)
 		return Error_Fail;
 
-	pType			= new uint32[kSize.X * kSize.Y];
-	pHeight			= new uint32[kSize.X * kSize.Y];
-
-	for(uint32 i = 0; i < nTemp; ++i)
-	{
-		uint32 nTemp2 = 0;
-		if(kBuffer.Read(&nTemp2) != Error_Success)
-			return Error_Fail;
-	}
+	pHeight	= new uint32[kSize.X * kSize.Y];
+	pType	= new uint32[kSize.X * kSize.Y];
 
 	for(uint32 nY = 0; nY < kSize.Y; ++nY)
 	{
@@ -95,10 +83,10 @@
 		{
 			const uint32 nIndex = nY * kSize.X + nX;
 
-			if(kBuffer.Read(pType + nIndex) != Error_Success)
+			if(kBuffer.Read(pHeight + nIndex) != Error_Success)
 				return Error_Fail;
 
-			if(kBuffer.Read(pHeight + nIndex) != Error_Success)
+			if(kBuffer.Read(pType + nIndex) != Error_Success)
 				return Error_Fail;
 		}
 	}
--- a/LightClone/Source/ResourceManager.cpp	Fri Sep 23 17:58:17 2011 -0700
+++ b/LightClone/Source/ResourceManager.cpp	Tue Sep 27 09:42:01 2011 -0700
@@ -23,7 +23,19 @@
 ErrorCode CreateEffectHelper(GraphicsDevice* pDevice, const char* pName, ID3DXEffect** pEffect)
 {
 	ID3DXBuffer* pBuffer = NULL;
-	return SUCCEEDED(D3DXCreateEffectFromFileA(*pDevice, pName, NULL, NULL, 0, NULL, pEffect, &pBuffer)) ? Error_Success : Error_Fail;
+
+	HRESULT hResult = D3DXCreateEffectFromFileA(*pDevice, pName, NULL, NULL, 0, NULL, pEffect, &pBuffer);
+	if(FAILED(hResult))
+	{
+		if(pBuffer)
+		{
+			TRACE("Failed to load effect %s: %s", pName, (const char*)pBuffer->GetBufferPointer());
+		}
+
+		return Error_Fail;
+	}
+
+	return Error_Success;
 }
 
 /*
@@ -104,13 +116,20 @@
 		IDirect3DTexture9** pInstance = kTextureCache.Find(kPath);
 		if(!pInstance)
 		{
-			pInstance = kTextureCache.Add(kPath);
-			if(pInstance)
+			IDirect3DTexture9* pTextureObject = NULL;
+
+			eCode = CreateTextureHelper(pGraphicsDevice, pName, &pTextureObject);
+			if(eCode == Error_Success)
 			{
-				eCode = CreateTextureHelper(pGraphicsDevice, pName, pInstance);
-				if(eCode != Error_Success || !pInstance)
+				if(pTextureObject)
 				{
-					kTextureCache.Remove(kPath);
+					pInstance = kTextureCache.Add(kPath);
+					//ASSERT(pInstance != NULL);
+
+					*pInstance = pTextureObject;
+				}
+				else
+				{
 					eCode = Error_Fail;
 				}
 			}
@@ -142,10 +161,22 @@
 		ID3DXEffect** pInstance = kEffectCache.Find(ResourcePath(pName));
 		if(!pInstance)
 		{
-			pInstance = kEffectCache.Add(ResourcePath(pName));
-			if(pInstance)
+			ID3DXEffect* pEffectObject = NULL;
+
+			eCode = CreateEffectHelper(pGraphicsDevice, pName, &pEffectObject);
+			if(eCode == Error_Success)
 			{
-				eCode = CreateEffectHelper(pGraphicsDevice, pName, pInstance);
+				if(pEffectObject)
+				{
+					pInstance = kEffectCache.Add(ResourcePath(pName));
+					//ASSERT(pInstance != NULL);
+
+					*pInstance = pEffectObject;
+				}
+				else
+				{
+					eCode = Error_Fail;
+				}
 			}
 		}
 		else
@@ -175,10 +206,22 @@
 		ID3DXFont** pInstance = kFontCache.Find(ResourcePath(pName));
 		if(!pInstance)
 		{
-			pInstance = kFontCache.Add(ResourcePath(pName));
-			if(pInstance)
+			ID3DXFont* pFontObject = NULL;
+
+			eCode = CreateFontHelper(pGraphicsDevice, pName, nSize, nWeight, &pFontObject);
+			if(eCode == Error_Success)
 			{
-				eCode = CreateFontHelper(pGraphicsDevice, pName, nSize, nWeight, pInstance);
+				if(pFontObject)
+				{
+					pInstance = kFontCache.Add(ResourcePath(pName));
+					//ASSERT(pInstace != NULL);
+
+					*pInstance = pFontObject;
+				}
+				else
+				{
+					eCode = Error_Fail;
+				}
 			}
 		}
 		else
--- a/LightClone/Source/VertexTypes.cpp	Fri Sep 23 17:58:17 2011 -0700
+++ b/LightClone/Source/VertexTypes.cpp	Tue Sep 27 09:42:01 2011 -0700
@@ -5,16 +5,21 @@
 #include "VertexTypes.h"
 
 /*
- * BlockVertex::Declaration
+ * Vertex::Block::Declaration
  */
 IDirect3DVertexDeclaration9* Vertex::Block::Declaration = NULL;
 
 /*
- * QuadVertex::Declaration
+ * Vertex::Quad::Declaration
  */
 IDirect3DVertexDeclaration9* Vertex::Quad::Declaration = NULL;
 
 /*
+ * Vertex::ColorQuad::Declaration
+ */
+IDirect3DVertexDeclaration9* Vertex::ColorQuad::Declaration = NULL;
+
+/*
  * InitializeVertexTypes
  */
 ErrorCode InitializeVertexTypes(IDirect3DDevice9* pDevice)
@@ -52,6 +57,23 @@
 		}
 	}
 
+	{
+		const D3DVERTEXELEMENT9 kElements[] = 
+		{
+			{0,	0,	D3DDECLTYPE_FLOAT3,		D3DDECLMETHOD_DEFAULT,	D3DDECLUSAGE_POSITION,	0},
+			{0, 12,	D3DDECLTYPE_FLOAT2,		D3DDECLMETHOD_DEFAULT,	D3DDECLUSAGE_TEXCOORD,	0},
+			{0, 20,	D3DDECLTYPE_D3DCOLOR,	D3DDECLMETHOD_DEFAULT,	D3DDECLUSAGE_COLOR,		0},
+
+			D3DDECL_END(),
+		};
+
+		HRESULT hResult = pDevice->CreateVertexDeclaration(kElements, &Vertex::ColorQuad::Declaration);
+		if(FAILED(hResult))
+		{
+			return Error_Fail;
+		}
+	}
+
 	return Error_Success;
 }
 
--- a/LightClone/Source/VertexTypes.h	Fri Sep 23 17:58:17 2011 -0700
+++ b/LightClone/Source/VertexTypes.h	Tue Sep 27 09:42:01 2011 -0700
@@ -91,6 +91,47 @@
 			TextureCoordinates.y	= fV;
 		}
 	};
+
+	/*
+	 * ColorQuad
+	 */
+	struct ColorQuad
+	{
+		/*
+		 * Position
+		 */
+		D3DXVECTOR3 Position;
+
+		/*
+		 * TextureCoordinates
+		 */
+		D3DXVECTOR2 TextureCoordinates;
+
+		/*
+		 * Color
+		 */
+		D3DCOLOR Color;
+
+		/*
+		 * Declaration
+		 */
+		static IDirect3DVertexDeclaration9* Declaration;
+
+	public:
+
+		/*
+		 * ColorQuad
+		 */
+		ColorQuad(float fX, float fY, float fZ, float fU, float fV, D3DCOLOR nColor)
+		{
+			Position.x				= fX;
+			Position.y				= fY;
+			Position.z				= fZ;
+			TextureCoordinates.x	= fU;
+			TextureCoordinates.y	= fV;
+			Color					= nColor;
+		}
+	};
 }
 
 /*
--- a/LightClone/Source/World.cpp	Fri Sep 23 17:58:17 2011 -0700
+++ b/LightClone/Source/World.cpp	Tue Sep 27 09:42:01 2011 -0700
@@ -241,6 +241,7 @@
 		pBackground->Initialize(pResourceManager);
 		pBackground->SetTexture("Data\\Textures\\Background03.tga", true);
 		pBackground->SetPosition(ScreenSizeX - pBackground->GetWidth(), 0.0f);
+		pBackground->SetDepth(512.0f);
 
 		pToolbar = new CodePanel(4, 2);
 		pToolbar->Initialize(pResourceManager);
@@ -254,6 +255,7 @@
 		pToolbar->SetAction(5, Action_FunctionA);
 		pToolbar->SetAction(6, Action_FunctionB);
 		pToolbar->SetPermanent(true);
+		pToolbar->SetDepth(256.0f);
 
 		GuiLabel* pMainLabel = new GuiLabel();
 		pMainLabel->Initialize(pResourceManager);
@@ -261,12 +263,14 @@
 		pMainLabel->SetText("Main:");
 		pMainLabel->SetColor(D3DCOLOR_XRGB(0, 0, 0));
 		pMainLabel->SetPosition(26.0f, 149.0f);
+		pMainLabel->SetDepth(256.0f);
 
 		pMain = new CodePanel(4, 3);
 		pMain->Initialize(pResourceManager);
 		pMain->SetTexture("Data\\Textures\\PanelB.png");
 		pMain->SetPosition(16.0f, 160.0f);
 		pMain->Subscribe(CodePanel::EventAction, &World::OnAction, this);
+		pMain->SetDepth(256.0f);
 
 		GuiLabel* pFunctionALabel = new GuiLabel();
 		pFunctionALabel->Initialize(pResourceManager);
@@ -431,6 +435,97 @@
 	{
 		kCameraController.Move(-0.1f);
 	}
+
+	static bool bControl = false;
+	static uint32 nBuffer[4] = {0};
+	static uint32 nCount = 0;
+
+	if(bControl)
+	{
+		if(pInputManager->IsKeyDown(DIK_0) && !pInputManager->WasKeyDown(DIK_0))
+		{
+			nBuffer[nCount++] = 0;
+		}
+		else
+
+		if(pInputManager->IsKeyDown(DIK_1) && !pInputManager->WasKeyDown(DIK_1))
+		{
+			nBuffer[nCount++] = 1;
+		}
+		else
+
+		if(pInputManager->IsKeyDown(DIK_2) && !pInputManager->WasKeyDown(DIK_2))
+		{
+			nBuffer[nCount++] = 2;
+		}
+		else
+
+		if(pInputManager->IsKeyDown(DIK_3) && !pInputManager->WasKeyDown(DIK_3))
+		{
+			nBuffer[nCount++] = 3;
+		}
+		else
+
+		if(pInputManager->IsKeyDown(DIK_4) && !pInputManager->WasKeyDown(DIK_4))
+		{
+			nBuffer[nCount++] = 4;
+		}
+		else
+
+		if(pInputManager->IsKeyDown(DIK_5) && !pInputManager->WasKeyDown(DIK_5))
+		{
+			nBuffer[nCount++] = 5;
+		}
+		else
+
+		if(pInputManager->IsKeyDown(DIK_6) && !pInputManager->WasKeyDown(DIK_6))
+		{
+			nBuffer[nCount++] = 6;
+		}
+		else
+
+		if(pInputManager->IsKeyDown(DIK_7) && !pInputManager->WasKeyDown(DIK_7))
+		{
+			nBuffer[nCount++] = 7;
+		}
+		else
+
+		if(pInputManager->IsKeyDown(DIK_8) && !pInputManager->WasKeyDown(DIK_8))
+		{
+			nBuffer[nCount++] = 8;
+		}
+		else
+
+		if(pInputManager->IsKeyDown(DIK_9) && !pInputManager->WasKeyDown(DIK_9))
+		{
+			nBuffer[nCount++] = 9;
+		}
+
+		if(!pInputManager->IsKeyDown(DIK_LCONTROL))
+		{
+			if(nCount > 0)
+			{
+				nCurrentLevel	= 0;
+				nGameState		= GameState_LoadMap;
+
+				for(uint32 i = 0; i < nCount; ++i)
+				{
+					nCurrentLevel += (uint32)(nBuffer[i] * powf(10.0f, (float)i));
+				}
+			}
+
+			bControl = false;
+		}
+	}
+	else
+	{
+		if(pInputManager->IsKeyDown(DIK_LCONTROL))
+		{
+			bControl = true;
+			nCount = 0;
+		}
+	}
+
 	#endif
 }
 
--- a/LightClone/ToDo.txt	Fri Sep 23 17:58:17 2011 -0700
+++ b/LightClone/ToDo.txt	Tue Sep 27 09:42:01 2011 -0700
@@ -3,6 +3,7 @@
 3.	Main menu
 4.	Pause menu
 5.	Robot model & texture
-6.	Implement confirm exit dialog
 7.	Help interface
-8.	Implement gui batching
\ No newline at end of file
+8.	Implement gui batching
+9.	Add depth to gui elements
+10.	Move render manager into gui element
\ No newline at end of file
--- a/LightTools/build.py	Fri Sep 23 17:58:17 2011 -0700
+++ b/LightTools/build.py	Tue Sep 27 09:42:01 2011 -0700
@@ -7,16 +7,17 @@
 import struct
 import os
 import functools
+import re
+
+_pattern = re.compile('\(\s*(\d+)\s*,\s*(\d+)\s*\)')
 
 class MapDefinition:
     Parse = functools.partial(string.split, sep=',')
 
-    def __init__(self, size, position, direction, fcount, functions, grid):
+    def __init__(self, size, position, direction, grid):
         self.Size = self._ParseVector(size)
         self.Position = self._ParseVector(position)
         self.Direction = self._ParseVector(direction)
-        self.Count = self._ParseVector(fcount)
-        self.Functions = self._ParseList(functions)
         self.Grid = self._ParseList(grid)
 
     def Write(self, filename):
@@ -24,10 +25,6 @@
             handle.write(struct.pack('i' * len(self.Size),      *self.Size))            # 8
             handle.write(struct.pack('i' * len(self.Position),  *self.Position))        # 8
             handle.write(struct.pack('i' * len(self.Direction), *self.Direction))       # 4
-            handle.write(struct.pack('i' * len(self.Count),     *self.Count))           # 4
-
-            for function in self.Functions:
-                handle.write(struct.pack('i' * len(function), *function))               # 4 * Count
 
             for tower in self.Grid:
                 handle.write(struct.pack('i' * len(tower), *tower))                     # 8 * Size.X * Size.Y
@@ -36,7 +33,22 @@
         return map(int, self.Parse(line))
 
     def _ParseList(self, lines):
-        return [self._ParseVector(line) for line in lines]
+        #return [self._ParseVector(line) for line in lines]
+        tuples = []
+
+        #print ''.join(lines)
+        #print _pattern.split(''.join(lines))
+
+        for item in _pattern.finditer(''.join(lines)):
+            #print item.groups()
+            #tuples.append((int(item.group(1)), int(item.group(2))))
+            tuples.append(map(int, item.groups()))
+
+        #print tuples
+        return tuples
+        #print tuples
+
+        #return [map(int, item.groups()) for item in _pattern.finditer(''.join(lines))]
 
 def ReadDefinition(filename):
     def FilterLines(lines):
@@ -49,22 +61,13 @@
 
     definition = tuple(FilterLines(lines))
 
-    offset = 0
-    size = definition[offset]
-    offset += 1
-    position = definition[offset]
-    offset += 1
-    direction = definition[offset]
-    offset += 1
-    fcount = definition[offset]
-    offset += 1
-    length = int(fcount)
-    functions = definition[offset:offset+length]
-    offset += length
-    grid = definition[offset:]
+    size = definition[0]
+    position = definition[1]
+    direction = definition[2]
+    grid = definition[3:]
 
-    return MapDefinition(size, position, direction, fcount, functions, grid)
-        
+    return MapDefinition(size, position, direction, grid)
+
 if __name__ == '__main__':
     path_root   = os.path.dirname(sys.argv[0])
     path_assets = os.path.abspath(os.path.join(path_root, '..', 'Assets', 'Maps'))