Pārlūkot izejas kodu

Merge pull request #170 from feature/directx10-example

DirectX 10 Sample

Conflicts:
Build/cmake/gen_samplelists.sh
David Wimsey 11 gadi atpakaļ
vecāks
revīzija
da2a0dcaba

+ 26 - 0
Build/CMakeLists.txt

@@ -77,6 +77,7 @@ option(BUILD_SAMPLES "Build samples" OFF)
 if(WIN32)
 	option(SKIP_DIRECTX_SAMPLES "Skip build of all DirectX related samples.  Only applies if BUILD_SAMPLES is ON" OFF)
 	option(SKIP_DIRECTX9_SAMPLE "Skip build of DirectX 9 related sample.  Only applies if BUILD_SAMPLES is ON and SKIP_DIRECTX_SAMPLES is OFF" OFF)
+	option(SKIP_DIRECTX10_SAMPLE "Skip build of DirectX 10 related sample.  Only applies if BUILD_SAMPLES is ON and SKIP_DIRECTX_SAMPLES is OFF" OFF)
 endif()
 
 if(IOS)
@@ -350,6 +351,19 @@ if(BUILD_SAMPLES)
 					endif()
 				endif()
 
+				if(SKIP_DIRECTX10_SAMPLE)
+					message("-- Skipping build of DirectX 10 sample: User disabled")
+					list(APPEND DIRECTX_SKIPPED_SAMPLE_LIST "DirectX10 ")
+				else()
+					if(DirectX_D3D10_FOUND)
+						list(APPEND DIRECTX_SAMPLE_LIST "DirectX10 ")
+					else()
+						set(SKIP_DIRECTX10_SAMPLE ON)
+						message("-- Skipping build of DirectX 10 sample: Missing DirectX_D3D10_INCLUDE_DIR, DirectX_D3D10_LIBRARY or DirectX_D3DX10_LIBRARY")
+						list(APPEND DIRECTX_SKIPPED_SAMPLE_LIST "DirectX10 ")
+					endif()
+				endif()
+
 
 				if(DIRECTX_SAMPLE_LIST)
 					message("-- Enabled DirectX samples: " ${DIRECTX_SAMPLE_LIST})
@@ -419,6 +433,18 @@ if(BUILD_SAMPLES)
 				RUNTIME DESTINATION ${SAMPLES_DIR}/directx
 				BUNDLE DESTINATION ${SAMPLES_DIR})
 		endif()
+
+		if(NOT SKIP_DIRECTX10_SAMPLE)
+			include_directories(${DirectX_INCLUDE_DIR} ${DirectX_D3D10_INCLUDE_DIRS})
+
+			bl_sample(directx10 ${sample_LIBRARIES}  ${DirectX_D3D10_LIBRARIES})
+
+			# The samples always set this as their current working directory
+			install(DIRECTORY DESTINATION ${SAMPLES_DIR}/basic/directx10)
+			install(TARGETS directx10 
+				RUNTIME DESTINATION ${SAMPLES_DIR}/directx10
+				BUNDLE DESTINATION ${SAMPLES_DIR})
+		endif()
 	endif()
 
     # Build and install the tutorials

+ 80 - 70
Build/cmake/SampleFileList.cmake

@@ -1,5 +1,22 @@
 # This file was auto-generated with gen_samplelists.sh
 
+set(shell_HDR_FILES
+    ${PROJECT_SOURCE_DIR}/Samples/shell/include/Input.h
+    ${PROJECT_SOURCE_DIR}/Samples/shell/include/Shell.h
+    ${PROJECT_SOURCE_DIR}/Samples/shell/include/ShellFileInterface.h
+    ${PROJECT_SOURCE_DIR}/Samples/shell/include/ShellOpenGL.h
+    ${PROJECT_SOURCE_DIR}/Samples/shell/include/ShellRenderInterfaceOpenGL.h
+    ${PROJECT_SOURCE_DIR}/Samples/shell/include/ShellSystemInterface.h
+)
+
+set(shell_SRC_FILES
+    ${PROJECT_SOURCE_DIR}/Samples/shell/src/Input.cpp
+    ${PROJECT_SOURCE_DIR}/Samples/shell/src/Shell.cpp
+    ${PROJECT_SOURCE_DIR}/Samples/shell/src/ShellFileInterface.cpp
+    ${PROJECT_SOURCE_DIR}/Samples/shell/src/ShellRenderInterfaceOpenGL.cpp
+    ${PROJECT_SOURCE_DIR}/Samples/shell/src/ShellSystemInterface.cpp
+)
+
 set(customlog_HDR_FILES
     ${PROJECT_SOURCE_DIR}/Samples/basic/customlog/src/SystemInterface.h
 )
@@ -9,15 +26,6 @@ set(customlog_SRC_FILES
     ${PROJECT_SOURCE_DIR}/Samples/basic/customlog/src/SystemInterface.cpp
 )
 
-set(directx_HDR_FILES
-    ${PROJECT_SOURCE_DIR}/Samples/basic/directx/src/RenderInterfaceDirectX.h
-)
-
-set(directx_SRC_FILES
-    ${PROJECT_SOURCE_DIR}/Samples/basic/directx/src/main.cpp
-    ${PROJECT_SOURCE_DIR}/Samples/basic/directx/src/RenderInterfaceDirectX.cpp
-)
-
 set(drag_HDR_FILES
     ${PROJECT_SOURCE_DIR}/Samples/basic/drag/src/DragListener.h
     ${PROJECT_SOURCE_DIR}/Samples/basic/drag/src/Inventory.h
@@ -62,6 +70,69 @@ set(treeview_SRC_FILES
     ${PROJECT_SOURCE_DIR}/Samples/basic/treeview/src/main.cpp
 )
 
+set(directx_HDR_FILES
+    ${PROJECT_SOURCE_DIR}/Samples/basic/directx/src/RenderInterfaceDirectX.h
+)
+
+set(directx_SRC_FILES
+    ${PROJECT_SOURCE_DIR}/Samples/basic/directx/src/main.cpp
+    ${PROJECT_SOURCE_DIR}/Samples/basic/directx/src/RenderInterfaceDirectX.cpp
+)
+
+set(directx10_HDR_FILES
+    ${PROJECT_SOURCE_DIR}/Samples/basic/directx10/src/D3D10Effect.h
+    ${PROJECT_SOURCE_DIR}/Samples/basic/directx10/src/RenderInterfaceDirectx10.h
+)
+
+set(directx10_SRC_FILES
+    ${PROJECT_SOURCE_DIR}/Samples/basic/directx10/src/main.cpp
+    ${PROJECT_SOURCE_DIR}/Samples/basic/directx10/src/RenderInterfaceDirectx10.cpp
+)
+
+set(template_HDR_FILES
+)
+
+set(template_SRC_FILES
+    ${PROJECT_SOURCE_DIR}/Samples/tutorial/template/src/main.cpp
+)
+
+set(datagrid_HDR_FILES
+    ${PROJECT_SOURCE_DIR}/Samples/tutorial/datagrid/src/DecoratorDefender.h
+    ${PROJECT_SOURCE_DIR}/Samples/tutorial/datagrid/src/DecoratorInstancerDefender.h
+    ${PROJECT_SOURCE_DIR}/Samples/tutorial/datagrid/src/HighScores.h
+)
+
+set(datagrid_SRC_FILES
+    ${PROJECT_SOURCE_DIR}/Samples/tutorial/datagrid/src/DecoratorDefender.cpp
+    ${PROJECT_SOURCE_DIR}/Samples/tutorial/datagrid/src/DecoratorInstancerDefender.cpp
+    ${PROJECT_SOURCE_DIR}/Samples/tutorial/datagrid/src/HighScores.cpp
+    ${PROJECT_SOURCE_DIR}/Samples/tutorial/datagrid/src/main.cpp
+)
+
+set(datagrid_tree_HDR_FILES
+    ${PROJECT_SOURCE_DIR}/Samples/tutorial/datagrid_tree/src/DecoratorDefender.h
+    ${PROJECT_SOURCE_DIR}/Samples/tutorial/datagrid_tree/src/DecoratorInstancerDefender.h
+    ${PROJECT_SOURCE_DIR}/Samples/tutorial/datagrid_tree/src/HighScores.h
+    ${PROJECT_SOURCE_DIR}/Samples/tutorial/datagrid_tree/src/HighScoresShipFormatter.h
+)
+
+set(datagrid_tree_SRC_FILES
+    ${PROJECT_SOURCE_DIR}/Samples/tutorial/datagrid_tree/src/DecoratorDefender.cpp
+    ${PROJECT_SOURCE_DIR}/Samples/tutorial/datagrid_tree/src/DecoratorInstancerDefender.cpp
+    ${PROJECT_SOURCE_DIR}/Samples/tutorial/datagrid_tree/src/HighScores.cpp
+    ${PROJECT_SOURCE_DIR}/Samples/tutorial/datagrid_tree/src/HighScoresShipFormatter.cpp
+    ${PROJECT_SOURCE_DIR}/Samples/tutorial/datagrid_tree/src/main.cpp
+)
+
+set(tutorial_drag_HDR_FILES
+    ${PROJECT_SOURCE_DIR}/Samples/tutorial/tutorial_drag/src/Inventory.h
+)
+
+set(tutorial_drag_SRC_FILES
+    ${PROJECT_SOURCE_DIR}/Samples/tutorial/tutorial_drag/src/Inventory.cpp
+    ${PROJECT_SOURCE_DIR}/Samples/tutorial/tutorial_drag/src/main.cpp
+)
+
 set(invaders_HDR_FILES
     ${PROJECT_SOURCE_DIR}/Samples/invaders/src/DecoratorDefender.h
     ${PROJECT_SOURCE_DIR}/Samples/invaders/src/DecoratorInstancerDefender.h
@@ -185,67 +256,6 @@ set(pyinvaders_SRC_FILES
     ${PROJECT_SOURCE_DIR}/Samples/pyinvaders/src/Sprite.cpp
 )
 
-set(shell_HDR_FILES
-    ${PROJECT_SOURCE_DIR}/Samples/shell/include/Input.h
-    ${PROJECT_SOURCE_DIR}/Samples/shell/include/Shell.h
-    ${PROJECT_SOURCE_DIR}/Samples/shell/include/ShellFileInterface.h
-    ${PROJECT_SOURCE_DIR}/Samples/shell/include/ShellOpenGL.h
-    ${PROJECT_SOURCE_DIR}/Samples/shell/include/ShellRenderInterfaceOpenGL.h
-    ${PROJECT_SOURCE_DIR}/Samples/shell/include/ShellSystemInterface.h
-)
-
-set(shell_SRC_FILES
-    ${PROJECT_SOURCE_DIR}/Samples/shell/src/Input.cpp
-    ${PROJECT_SOURCE_DIR}/Samples/shell/src/Shell.cpp
-    ${PROJECT_SOURCE_DIR}/Samples/shell/src/ShellFileInterface.cpp
-    ${PROJECT_SOURCE_DIR}/Samples/shell/src/ShellRenderInterfaceOpenGL.cpp
-    ${PROJECT_SOURCE_DIR}/Samples/shell/src/ShellSystemInterface.cpp
-)
-
-set(template_HDR_FILES
-)
-
-set(template_SRC_FILES
-    ${PROJECT_SOURCE_DIR}/Samples/tutorial/template/src/main.cpp
-)
-
-set(datagrid_HDR_FILES
-    ${PROJECT_SOURCE_DIR}/Samples/tutorial/datagrid/src/DecoratorDefender.h
-    ${PROJECT_SOURCE_DIR}/Samples/tutorial/datagrid/src/DecoratorInstancerDefender.h
-    ${PROJECT_SOURCE_DIR}/Samples/tutorial/datagrid/src/HighScores.h
-)
-
-set(datagrid_SRC_FILES
-    ${PROJECT_SOURCE_DIR}/Samples/tutorial/datagrid/src/DecoratorDefender.cpp
-    ${PROJECT_SOURCE_DIR}/Samples/tutorial/datagrid/src/DecoratorInstancerDefender.cpp
-    ${PROJECT_SOURCE_DIR}/Samples/tutorial/datagrid/src/HighScores.cpp
-    ${PROJECT_SOURCE_DIR}/Samples/tutorial/datagrid/src/main.cpp
-)
-
-set(datagrid_tree_HDR_FILES
-    ${PROJECT_SOURCE_DIR}/Samples/tutorial/datagrid_tree/src/DecoratorDefender.h
-    ${PROJECT_SOURCE_DIR}/Samples/tutorial/datagrid_tree/src/DecoratorInstancerDefender.h
-    ${PROJECT_SOURCE_DIR}/Samples/tutorial/datagrid_tree/src/HighScores.h
-    ${PROJECT_SOURCE_DIR}/Samples/tutorial/datagrid_tree/src/HighScoresShipFormatter.h
-)
-
-set(datagrid_tree_SRC_FILES
-    ${PROJECT_SOURCE_DIR}/Samples/tutorial/datagrid_tree/src/DecoratorDefender.cpp
-    ${PROJECT_SOURCE_DIR}/Samples/tutorial/datagrid_tree/src/DecoratorInstancerDefender.cpp
-    ${PROJECT_SOURCE_DIR}/Samples/tutorial/datagrid_tree/src/HighScores.cpp
-    ${PROJECT_SOURCE_DIR}/Samples/tutorial/datagrid_tree/src/HighScoresShipFormatter.cpp
-    ${PROJECT_SOURCE_DIR}/Samples/tutorial/datagrid_tree/src/main.cpp
-)
-
-set(tutorial_drag_HDR_FILES
-    ${PROJECT_SOURCE_DIR}/Samples/tutorial/tutorial_drag/src/Inventory.h
-)
-
-set(tutorial_drag_SRC_FILES
-    ${PROJECT_SOURCE_DIR}/Samples/tutorial/tutorial_drag/src/Inventory.cpp
-    ${PROJECT_SOURCE_DIR}/Samples/tutorial/tutorial_drag/src/main.cpp
-)
-
 # Deal with platform specific sources for sample shell
 if(WIN32)
        list(APPEND shell_SRC_FILES

+ 4 - 2
Build/cmake/gen_samplelists.sh

@@ -6,9 +6,11 @@ src='set(sample_SRC_FILES'
 hdr='set(sample_HDR_FILES'
 srcdir='${PROJECT_SOURCE_DIR}'
 srcpath=Samples
-samples=('basic/customlog' 'basic/directx' 'basic/drag' 'basic/loaddocument'
-        'basic/ogre3d' 'basic/treeview' 'invaders' 'luainvaders' 'pyinvaders' 'shell'
+samples=( 'shell'
+	'basic/customlog' 'basic/drag' 'basic/loaddocument' 'basic/ogre3d' 'basic/treeview'
+	'basic/directx' 'basic/directx10'
 	'tutorial/template' 'tutorial/datagrid' 'tutorial/datagrid_tree' 'tutorial/tutorial_drag'
+	'invaders' 'luainvaders' 'pyinvaders'
 )
 
 printfiles() {

+ 2 - 1
Samples/README.TXT

@@ -35,7 +35,8 @@ Directory Overview:
                 installing custom interfaces.
 
                   * customlog    - setting up custom logging
-                  * directx      - using DirectX as a renderer
+                  * directx      - using DirectX 9 as a renderer
+                  * directx10    - using DirectX 10 as a renderer
                   * drag         - dragging elements between containers
                   * loaddocument - loading your first document
                   * ogre3d       - interfacing with Ogre3D engine

+ 56 - 0
Samples/basic/directx10/src/D3D10Effect.h

@@ -0,0 +1,56 @@
+#ifndef D3D10EFFECT_H
+#define D3D10EFFECT_H
+
+const char * pEffectData="float4x4 matWorld;" 
+"float4x4 matProjection;" 
+"struct VS_INPUT" 
+"{" 
+	"float4 Pos:POSITION;" 
+	"float4 Colour:COLOR;" 
+	"float2 TexCoord:TEXCOORD;" 
+"};" 
+"struct PS_INPUT" 
+"{" 
+	"float4 Pos:SV_POSITION;" 
+	"float4 Colour:COLOR; "
+	"float2 TexCoord:TEXCOORD;" 
+"};" 
+"Texture2D diffuseMap;" 
+"SamplerState diffuseSampler" 
+"{"
+    "Filter = MIN_MAG_MIP_POINT;" 
+    "AddressU = WRAP;" 
+    "AddressV = WRAP;" 
+"};" 
+"PS_INPUT VS( VS_INPUT input )" 
+"{"
+	"PS_INPUT output=(PS_INPUT)0;"
+	"float4x4 worldViewProjection=mul(matWorld,matProjection);" 	
+	"output.Pos=mul(input.Pos,worldViewProjection);" 
+	"output.TexCoord=input.TexCoord;" 
+	"output.Colour=input.Colour;" 
+    "return output;"
+"}" 
+"float4 PS(PS_INPUT input ) : SV_Target"
+"{"
+	"float4 finalColour=diffuseMap.Sample(diffuseSampler,input.TexCoord)*input.Colour;"
+    "return finalColour;"
+"}"
+"BlendState AlphaBlendingOn"
+"{"
+    "BlendEnable[0] = TRUE;"
+    "DestBlend = INV_SRC_ALPHA;"
+    "SrcBlend = SRC_ALPHA;"
+"};"
+"technique10 Render"
+"{" 
+    "pass P0" 
+    "{" 
+	"SetBlendState(AlphaBlendingOn, float4(0.0f, 0.0f, 0.0f, 0.0f), 0xFFFFFFFF);"
+    "SetVertexShader( CompileShader( vs_4_0, VS() ) );" 
+    "SetGeometryShader( NULL );" 
+    "SetPixelShader( CompileShader( ps_4_0, PS() ) ); " 
+    "}"
+"}";
+
+#endif

+ 491 - 0
Samples/basic/directx10/src/RenderInterfaceDirectx10.cpp

@@ -0,0 +1,491 @@
+#include "RenderInterfaceDirectX10.h"
+#include <Rocket/Core.h>
+
+#include "D3D10Effect.h"
+
+//RocketD3D10 Texture, this contains the actual texture and the resource view
+//for sending it to the effect
+struct RocketD3D10Texture
+{
+	ID3D10ShaderResourceView * textureView;
+	ID3D10Texture2D * texture2D;
+};
+
+// This structure is created for each set of geometry that Rocket compiles. It stores the vertex and index buffers and
+// the texture associated with the geometry, if one was specified.
+struct RocketD310DCompiledGeometry
+{
+	//Vertex Buffer
+	ID3D10Buffer * vertices;
+	DWORD num_vertices;
+
+	//Index buffer
+	ID3D10Buffer * indices;
+	DWORD num_primitives;
+	//Texture
+	RocketD3D10Texture * texture;
+};
+
+// The internal format of the vertex we use for rendering Rocket geometry. We could optimise space by having a second
+// untextured vertex for use when rendering coloured borders and backgrounds.
+struct RocketD3D10Vertex
+{
+	FLOAT x, y, z;
+	D3DXCOLOR colour;
+	FLOAT u, v;
+};
+
+//The layout of the vertices
+const D3D10_INPUT_ELEMENT_DESC layout[] =
+{
+    { "POSITION",0, DXGI_FORMAT_R32G32B32_FLOAT, 0, 0, D3D10_INPUT_PER_VERTEX_DATA, 0 },
+	{ "COLOR",0, DXGI_FORMAT_R32G32B32A32_FLOAT, 0, 12, D3D10_INPUT_PER_VERTEX_DATA, 0},
+	{"TEXCOORD",0,DXGI_FORMAT_R32G32_FLOAT,0,28,D3D10_INPUT_PER_VERTEX_DATA,0},
+};
+
+//The constructor of the render
+RenderInterfaceDirectX10::RenderInterfaceDirectX10(ID3D10Device * pD3D10Device,float screenWidth,float screenHeight)
+{
+	m_pScissorTestDisable = NULL;
+	m_pScissorTestEnable = NULL;
+	m_pD3D10Device=pD3D10Device;
+	setupEffect();
+	//Create our view and projection matrix
+	D3DXMatrixOrthoOffCenterLH(&m_matProjection, 0, screenWidth, screenHeight, 0, -1, 1);
+	m_pProjectionMatrixVariable->SetMatrix((float*)m_matProjection);
+
+	//Create scissor raster states
+	D3D10_RASTERIZER_DESC rasterDesc;
+	rasterDesc.FillMode=D3D10_FILL_SOLID;
+	rasterDesc.CullMode=D3D10_CULL_NONE;
+	rasterDesc.ScissorEnable=TRUE;
+	rasterDesc.FrontCounterClockwise=TRUE;
+	if (FAILED(m_pD3D10Device->CreateRasterizerState(&rasterDesc, &m_pScissorTestEnable)))
+	{
+		Rocket::Core::Log::Message(Rocket::Core::Log::LT_ERROR, "Can't create Raster State - ScissorEnable");
+	}
+
+	rasterDesc.ScissorEnable=FALSE;
+	if (FAILED(m_pD3D10Device->CreateRasterizerState(&rasterDesc, &m_pScissorTestDisable)))
+	{
+		Rocket::Core::Log::Message(Rocket::Core::Log::LT_ERROR, "Can't create Raster State - ScissorDisable");
+	}
+}
+
+//Loads the effect from memory and retrieves initial variables from the effect
+void RenderInterfaceDirectX10::setupEffect()
+{
+	//The pass we are going to use
+	ID3D10EffectPass *pass=NULL;
+	DWORD dwShaderFlags = 0;
+	#if defined( DEBUG ) || defined( _DEBUG )
+		// Set the D3D10_SHADER_DEBUG flag to embed debug information in the shaders.
+		// Setting this flag improves the shader debugging experience, but still allows 
+		// the shaders to be optimized and to run exactly the way they will run in 
+		// the release configuration of this program. - BMD
+		dwShaderFlags |= D3D10_SHADER_DEBUG;
+
+	#endif
+	//Create our effect from Memory
+	if (FAILED(D3DX10CreateEffectFromMemory((void*)pEffectData,strlen(pEffectData),"DefaultEffect",NULL,NULL,"fx_4_0",dwShaderFlags,0,m_pD3D10Device,NULL,NULL,&m_pEffect,NULL,NULL)))
+	{
+		//Log error
+		Rocket::Core::Log::Message(Rocket::Core::Log::LT_ERROR, "Can't create default effect for rendering, graphics card may not support Shader Model 4");
+		
+	}
+	
+	//Number of elements in the layout - BMD
+	UINT numElements = sizeof(layout)/sizeof(D3D10_INPUT_ELEMENT_DESC);
+	//Get the pass description so we can get some info about the input signature of the vertices
+	D3D10_PASS_DESC passDesc;
+	m_pTechnique=m_pEffect->GetTechniqueByName("Render");
+	pass=m_pTechnique->GetPassByName("P0");
+	pass->GetDesc(&passDesc);
+	//create input layout, to allow us to map our vertex structure to the one held in the effect
+	if (FAILED(m_pD3D10Device->CreateInputLayout(layout, numElements, passDesc.pIAInputSignature, passDesc.IAInputSignatureSize, &m_pVertexLayout)))
+	{
+		Rocket::Core::Log::Message(Rocket::Core::Log::LT_ERROR, "Unable to create input layout");
+	}
+	//grab effect variables
+	m_pWorldMatrixVariable=m_pEffect->GetVariableByName("matWorld")->AsMatrix();
+	m_pProjectionMatrixVariable=m_pEffect->GetVariableByName("matProjection")->AsMatrix();
+
+	//grab texture variable
+	m_pDiffuseTextureVariable=m_pEffect->GetVariableByName("diffuseMap")->AsShaderResource();
+}
+
+RenderInterfaceDirectX10::~RenderInterfaceDirectX10()
+{
+	if (m_pVertexLayout)
+	{
+		m_pVertexLayout->Release();
+		m_pVertexLayout = NULL;
+	}
+	if (m_pEffect)
+	{
+		m_pEffect->Release();
+		m_pEffect = NULL;
+	}
+	if (m_pScissorTestDisable){
+		m_pScissorTestDisable->Release();
+		m_pScissorTestDisable = NULL;
+	}
+	if (m_pScissorTestEnable){
+		m_pScissorTestEnable->Release();
+		m_pScissorTestEnable = NULL;
+	}
+}
+
+// Called by Rocket when it wants to render geometry that it does not wish to optimise.
+void RenderInterfaceDirectX10::RenderGeometry(Rocket::Core::Vertex* ROCKET_UNUSED_PARAMETER(vertices), int ROCKET_UNUSED_PARAMETER(num_vertices), int* ROCKET_UNUSED_PARAMETER(indices), int ROCKET_UNUSED_PARAMETER(num_indices), const Rocket::Core::TextureHandle ROCKET_UNUSED_PARAMETER(texture), const Rocket::Core::Vector2f& ROCKET_UNUSED_PARAMETER(translation))
+{
+	ROCKET_UNUSED(vertices);
+	ROCKET_UNUSED(num_vertices);
+	ROCKET_UNUSED(indices);
+	ROCKET_UNUSED(num_indices);
+	ROCKET_UNUSED(texture);
+	ROCKET_UNUSED(translation);
+
+	// We've chosen to not support non-compiled geometry in the DirectX renderer. If you wanted to render non-compiled
+	// geometry, for example for very small sections of geometry, you could use DrawIndexedPrimitiveUP or write to a
+	// dynamic vertex buffer which is flushed when either the texture changes or compiled geometry is drawn.
+}
+
+// Called by Rocket when it wants to compile geometry it believes will be static for the forseeable future.
+Rocket::Core::CompiledGeometryHandle RenderInterfaceDirectX10::CompileGeometry(Rocket::Core::Vertex* vertices, int num_vertices, int* indices, int num_indices, Rocket::Core::TextureHandle texture)
+{
+	//Create instance of geometry
+	RocketD310DCompiledGeometry * geometry =new RocketD310DCompiledGeometry();
+
+	//Vertex Buffer description
+	D3D10_BUFFER_DESC bd;
+	bd.Usage = D3D10_USAGE_DEFAULT;
+	//Set the size of the buffer
+	bd.ByteWidth = sizeof(RocketD3D10Vertex) * num_vertices;
+	//This is a vertex buffer
+	bd.BindFlags = D3D10_BIND_VERTEX_BUFFER;
+	bd.CPUAccessFlags = 0;
+	bd.MiscFlags = 0;
+
+	//copy vertices into buffer
+	RocketD3D10Vertex * pD3D10Vertices=new RocketD3D10Vertex[num_vertices];
+	for (int i=0;i<num_vertices;++i)
+	{
+		pD3D10Vertices[i].x = vertices[i].position.x;
+		pD3D10Vertices[i].y = vertices[i].position.y;
+		pD3D10Vertices[i].z = 0;
+
+		pD3D10Vertices[i].colour=D3DXCOLOR((float)(vertices[i].colour.red/255), (float)(vertices[i].colour.green/255), (float)(vertices[i].colour.blue/255), 
+			(float)(vertices[i].colour.alpha/255));
+		
+		pD3D10Vertices[i].u = vertices[i].tex_coord[0];
+		pD3D10Vertices[i].v = vertices[i].tex_coord[1];
+	}
+	D3D10_SUBRESOURCE_DATA InitData;
+	InitData.pSysMem = pD3D10Vertices;
+
+	//Create VB
+	if (FAILED(m_pD3D10Device->CreateBuffer(
+		&bd,
+		&InitData,
+		&geometry->vertices))){
+		Rocket::Core::Log::Message(Rocket::Core::Log::LT_ERROR, "Undable to create vertex buffer for geometry");
+		return false;
+	}
+
+	delete pD3D10Vertices;
+
+	//Index buffer desc
+	bd.Usage = D3D10_USAGE_DEFAULT;
+	bd.ByteWidth = sizeof( UINT ) * num_indices;
+	bd.BindFlags = D3D10_BIND_INDEX_BUFFER;
+	bd.CPUAccessFlags = 0;
+	bd.MiscFlags = 0;
+
+	//Index values
+	InitData.pSysMem = indices;
+	//Fill and create buffer
+	if (FAILED(m_pD3D10Device->CreateBuffer(
+		&bd,
+		&InitData,
+		&geometry->indices))){
+		Rocket::Core::Log::Message(Rocket::Core::Log::LT_ERROR, "Undable to create index buffer for geometry");
+		return false;
+	}
+
+	//save some info in the instance of the structure
+	geometry->num_vertices = (DWORD) num_vertices;
+	geometry->num_primitives = (DWORD) num_indices / 3;
+
+	geometry->texture = texture == NULL ? NULL : (RocketD3D10Texture *) texture;
+
+	return (Rocket::Core::CompiledGeometryHandle)geometry;
+}
+
+// Called by Rocket when it wants to render application-compiled geometry.
+void RenderInterfaceDirectX10::RenderCompiledGeometry(Rocket::Core::CompiledGeometryHandle geometry, const Rocket::Core::Vector2f& translation)
+{
+	//Cast to D3D10 geometry
+	RocketD310DCompiledGeometry* d3d10_geometry = (RocketD310DCompiledGeometry*) geometry;
+	
+	//if we have a texture then send it, notice we are sending the view(Shader resource) to the 
+	//effect
+	if (d3d10_geometry->texture)
+		m_pDiffuseTextureVariable->SetResource(d3d10_geometry->texture->textureView);
+	else
+		m_pDiffuseTextureVariable->SetResource(NULL);
+	
+	//build and send the world matrix
+	D3DXMatrixTranslation(&m_matWorld, translation.x, translation.y, 0);
+	m_pWorldMatrixVariable->SetMatrix((float*)m_matWorld);
+	//Set the layout of the vertices that are held in the VB
+	m_pD3D10Device->IASetInputLayout(m_pVertexLayout);
+	//Get the stride(size) of the a vertex, we need this to tell the pipeline the size of one vertex 
+	UINT stride = sizeof(RocketD3D10Vertex);
+	//The offset from start of the buffer to where our vertices are located 
+	UINT offset = 0;
+	//Set the VB we are using
+	m_pD3D10Device->IASetVertexBuffers( 
+							0, 
+							1, 
+							&d3d10_geometry->vertices, 
+							&stride, 
+							&offset );
+	//Set the IB we are using
+	m_pD3D10Device->IASetIndexBuffer(d3d10_geometry->indices,DXGI_FORMAT_R32_UINT,0);
+
+
+	D3D10_TECHNIQUE_DESC techDesc;
+	m_pTechnique->GetDesc( &techDesc );
+	//Loop through the passes in the technique
+	for( UINT p = 0; p < techDesc.Passes; ++p )
+	{
+		//Get a pass at current index and apply it
+		m_pTechnique->GetPassByIndex( p )->Apply( 0 );
+		//We are drawing trangle lists
+		m_pD3D10Device->IASetPrimitiveTopology( D3D10_PRIMITIVE_TOPOLOGY_TRIANGLELIST );		
+							
+		//Draw call
+		m_pD3D10Device->DrawIndexed(d3d10_geometry->num_primitives*3,0,0);
+	}
+}
+
+// Called by Rocket when it wants to release application-compiled geometry.
+void RenderInterfaceDirectX10::ReleaseCompiledGeometry(Rocket::Core::CompiledGeometryHandle geometry)
+{
+	//Clean up after ourselves
+	RocketD310DCompiledGeometry* d3d10_geometry=(RocketD310DCompiledGeometry*)geometry;
+
+	if (d3d10_geometry->vertices){
+		d3d10_geometry->vertices->Release();
+		d3d10_geometry->vertices = NULL;
+	}
+	if (d3d10_geometry->indices){
+		d3d10_geometry->indices->Release();
+		d3d10_geometry->indices = NULL;
+	}
+
+	delete d3d10_geometry;
+}
+
+// Called by Rocket when it wants to enable or disable scissoring to clip content.
+void RenderInterfaceDirectX10::EnableScissorRegion(bool enable)
+{
+	//Is the scissor test enabled?
+	enable ? m_pD3D10Device->RSSetState(m_pScissorTestEnable) : m_pD3D10Device->RSSetState(m_pScissorTestDisable);
+}
+
+// Called by Rocket when it wants to change the scissor region.
+void RenderInterfaceDirectX10::SetScissorRegion(int x, int y, int width, int height)
+{
+	//The scissor rect
+	D3D10_RECT rect;
+	rect.left=x;
+	rect.right=x+width;
+	rect.top=y;
+	rect.bottom=y+height;
+
+	m_pD3D10Device->RSSetScissorRects(1,&rect);
+}
+
+// Set to byte packing, or the compiler will expand our struct, which means it won't read correctly from file
+#pragma pack(1) 
+struct TGAHeader 
+{
+	char  idLength;
+	char  colourMapType;
+	char  dataType;
+	short int colourMapOrigin;
+	short int colourMapLength;
+	char  colourMapDepth;
+	short int xOrigin;
+	short int yOrigin;
+	short int width;
+	short int height;
+	char  bitsPerPixel;
+	char  imageDescriptor;
+};
+// Restore packing
+#pragma pack()
+
+// Called by Rocket when a texture is required by the library.
+bool RenderInterfaceDirectX10::LoadTexture(Rocket::Core::TextureHandle& texture_handle, Rocket::Core::Vector2i& texture_dimensions, const Rocket::Core::String& source)
+{
+	Rocket::Core::FileInterface* file_interface = Rocket::Core::GetFileInterface();
+	Rocket::Core::FileHandle file_handle = file_interface->Open(source);
+	if (file_handle == NULL)
+		return false;
+
+	file_interface->Seek(file_handle, 0, SEEK_END);
+	size_t buffer_size = file_interface->Tell(file_handle);
+	file_interface->Seek(file_handle, 0, SEEK_SET);
+	
+	char* buffer = new char[buffer_size];
+	file_interface->Read(buffer, buffer_size, file_handle);
+	file_interface->Close(file_handle);
+
+	TGAHeader header;
+	memcpy(&header, buffer, sizeof(TGAHeader));
+	
+	int color_mode = header.bitsPerPixel / 8;
+	int image_size = header.width * header.height * 4; // We always make 32bit textures 
+	
+	if (header.dataType != 2)
+	{
+		Rocket::Core::Log::Message(Rocket::Core::Log::LT_ERROR, "Only 24/32bit uncompressed TGAs are supported.");
+		return false;
+	}
+	
+	// Ensure we have at least 3 colors
+	if (color_mode < 3)
+	{
+		Rocket::Core::Log::Message(Rocket::Core::Log::LT_ERROR, "Only 24 and 32bit textures are supported");
+		return false;
+	}
+	
+	const char* image_src = buffer + sizeof(TGAHeader);
+	unsigned char* image_dest = new unsigned char[image_size];
+	
+	// Targa is BGR, swap to RGB and flip Y axis
+	for (long y = 0; y < header.height; y++)
+	{
+		long read_index = y * header.width * color_mode;
+		long write_index = ((header.imageDescriptor & 32) != 0) ? read_index : (header.height - y - 1) * header.width * color_mode;
+		for (long x = 0; x < header.width; x++)
+		{
+			image_dest[write_index] = image_src[read_index+2];
+			image_dest[write_index+1] = image_src[read_index+1];
+			image_dest[write_index+2] = image_src[read_index];
+			if (color_mode == 4)
+				image_dest[write_index+3] = image_src[read_index+3];
+			else
+				image_dest[write_index+3] = 255;
+			
+			write_index += 4;
+			read_index += color_mode;
+		}
+	}
+
+	texture_dimensions.x = header.width;
+	texture_dimensions.y = header.height;
+	
+	bool success = GenerateTexture(texture_handle, image_dest, texture_dimensions);
+	
+	delete [] image_dest;
+	delete [] buffer;
+	
+	return success;
+}
+
+// Called by Rocket when a texture is required to be built from an internally-generated sequence of pixels.
+bool RenderInterfaceDirectX10::GenerateTexture(Rocket::Core::TextureHandle& texture_handle, const byte* source, const Rocket::Core::Vector2i& source_dimensions)
+{
+	//Create the instance of our texture
+	RocketD3D10Texture * pTexture=new RocketD3D10Texture();
+
+	//Texture description
+	D3D10_TEXTURE2D_DESC textureDesc;
+	//Width and height of the texture
+	textureDesc.Width=source_dimensions.x;
+	textureDesc.Height=source_dimensions.y;
+	//Mip levels
+	textureDesc.MipLevels=1;
+	textureDesc.ArraySize = 1;
+	//the format of the texture
+	textureDesc.Format=DXGI_FORMAT_R8G8B8A8_UNORM;
+	//The access and usage of the texture
+	textureDesc.CPUAccessFlags=D3D10_CPU_ACCESS_WRITE;
+	textureDesc.Usage=D3D10_USAGE_DYNAMIC;
+	//Our are we going to bind this texture to the pipeline
+	textureDesc.BindFlags= D3D10_BIND_SHADER_RESOURCE;
+	textureDesc.MiscFlags=0;
+	textureDesc.SampleDesc.Count=1;
+	textureDesc.SampleDesc.Quality=0;
+	
+	//create our texture
+	if (FAILED(m_pD3D10Device->CreateTexture2D(&textureDesc,NULL,&pTexture->texture2D))){
+		Rocket::Core::Log::Message(Rocket::Core::Log::LT_ERROR, "Unable to create texture");
+		return false;
+	}
+
+	//now lets fill it
+	D3D10_MAPPED_TEXTURE2D mappedTex;
+	pTexture->texture2D->Map(D3D10CalcSubresource(0,0,1),D3D10_MAP_WRITE_DISCARD,0,&mappedTex);
+	for (int y = 0; y < source_dimensions.y; ++y)
+	{
+		for (int x = 0; x < source_dimensions.x; ++x)
+		{
+			const byte* source_pixel = source + (source_dimensions.x * 4 * y) + (x * 4);
+			byte* destination_pixel = ((byte*) mappedTex.pData) + mappedTex.RowPitch * y + x * 4;
+			destination_pixel[0] = source_pixel[0];
+			destination_pixel[1] = source_pixel[1];
+			destination_pixel[2] = source_pixel[2];
+			destination_pixel[3] = source_pixel[3];
+		}
+	}
+	pTexture->texture2D->Unmap(D3D10CalcSubresource(0,0,1));
+
+	//Create the shader resoure view for our texture, we need this
+	//to send the texture to the effect
+	D3D10_SHADER_RESOURCE_VIEW_DESC srvDesc;
+	srvDesc.Format=textureDesc.Format;
+	srvDesc.ViewDimension=D3D10_SRV_DIMENSION_TEXTURE2D;
+	srvDesc.Texture2D.MipLevels=textureDesc.MipLevels;
+	srvDesc.Texture2D.MostDetailedMip=0;
+	if (FAILED(m_pD3D10Device->CreateShaderResourceView(pTexture->texture2D, &srvDesc, &pTexture->textureView))){
+		Rocket::Core::Log::Message(Rocket::Core::Log::LT_ERROR, "Unable to create texture view");
+		return false;
+	}
+
+	texture_handle = (Rocket::Core::TextureHandle)pTexture;
+	return true;
+}
+
+// Called by Rocket when a loaded texture is no longer required.
+void RenderInterfaceDirectX10::ReleaseTexture(Rocket::Core::TextureHandle texture_handle)
+{
+	//clean up after ourselves
+	RocketD3D10Texture * pTexture = (RocketD3D10Texture*)texture_handle;
+	if (pTexture->texture2D){
+		pTexture->texture2D->Release();
+		pTexture->texture2D = NULL;
+	}
+	if (pTexture->textureView){
+		pTexture->textureView->Release();
+		pTexture->textureView = NULL;
+	}
+	delete pTexture;
+}
+
+// Returns the native horizontal texel offset for the renderer.
+float RenderInterfaceDirectX10::GetHorizontalTexelOffset()
+{
+	return 0.0f;
+}
+
+// Returns the native vertical texel offset for the renderer.
+float RenderInterfaceDirectX10::GetVerticalTexelOffset()
+{
+	return 0.0f;
+}
+

+ 79 - 0
Samples/basic/directx10/src/RenderInterfaceDirectx10.h

@@ -0,0 +1,79 @@
+#ifndef RENDERINTERFACEDIRECTX_H
+#define RENDERINTERFACEDIRECTX_H
+
+#include <Rocket/Core/RenderInterface.h>
+#include <d3d10.h>
+#include <d3dx10.h>
+
+/**
+	A sample render interface for Rocket into DirectX 10.
+
+	TODO: 
+	1) Constant Buffers for variables
+
+	@author Brian McDonald
+ */
+
+class RenderInterfaceDirectX10 : public Rocket::Core::RenderInterface
+{
+public:
+	RenderInterfaceDirectX10(ID3D10Device * pD3D10Device,float screenWidth,float screenHeight);
+	virtual ~RenderInterfaceDirectX10();
+
+	/// Called by Rocket when it wants to render geometry that it does not wish to optimise.
+	virtual void RenderGeometry(Rocket::Core::Vertex* vertices, int num_vertices, int* indices, int num_indices, Rocket::Core::TextureHandle texture, const Rocket::Core::Vector2f& translation);
+
+	/// Called by Rocket when it wants to compile geometry it believes will be static for the forseeable future.
+	virtual Rocket::Core::CompiledGeometryHandle CompileGeometry(Rocket::Core::Vertex* vertices, int num_vertices, int* indices, int num_indices, Rocket::Core::TextureHandle texture);
+
+	/// Called by Rocket when it wants to render application-compiled geometry.
+	virtual void RenderCompiledGeometry(Rocket::Core::CompiledGeometryHandle geometry, const Rocket::Core::Vector2f& translation);
+	/// Called by Rocket when it wants to release application-compiled geometry.
+	virtual void ReleaseCompiledGeometry(Rocket::Core::CompiledGeometryHandle geometry);
+
+	/// Called by Rocket when it wants to enable or disable scissoring to clip content.
+	virtual void EnableScissorRegion(bool enable);
+	/// Called by Rocket when it wants to change the scissor region.
+	virtual void SetScissorRegion(int x, int y, int width, int height);
+
+	/// Called by Rocket when a texture is required by the library.
+	virtual bool LoadTexture(Rocket::Core::TextureHandle& texture_handle, Rocket::Core::Vector2i& texture_dimensions, const Rocket::Core::String& source);
+	/// Called by Rocket when a texture is required to be built from an internally-generated sequence of pixels.
+	virtual bool GenerateTexture(Rocket::Core::TextureHandle& texture_handle, const byte* source, const Rocket::Core::Vector2i& source_dimensions);
+	/// Called by Rocket when a loaded texture is no longer required.
+	virtual void ReleaseTexture(Rocket::Core::TextureHandle texture_handle);
+
+	/// Returns the native horizontal texel offset for the renderer.
+	float GetHorizontalTexelOffset();
+	/// Returns the native vertical texel offset for the renderer.
+	float GetVerticalTexelOffset();
+
+	//loads the effect from memory
+	void setupEffect();
+
+private:
+	//The D3D 10 Device
+	ID3D10Device * m_pD3D10Device;
+	//The Effect we are using to render GUI
+	ID3D10Effect * m_pEffect;
+	//The Current technique
+	ID3D10EffectTechnique*  m_pTechnique;
+	//The Vertex Layout
+	ID3D10InputLayout*      m_pVertexLayout;
+
+	//Effect varibales, used to send variables to the effect
+	ID3D10EffectMatrixVariable * m_pProjectionMatrixVariable;
+	ID3D10EffectMatrixVariable * m_pWorldMatrixVariable;
+	ID3D10EffectShaderResourceVariable *m_pDiffuseTextureVariable;
+
+	//Matrices
+	D3DXMATRIX m_matProjection;
+	D3DXMATRIX m_matWorld;
+
+	//Renderstate Blocks
+	ID3D10RasterizerState *m_pScissorTestEnable;
+	ID3D10RasterizerState *m_pScissorTestDisable;
+
+};
+
+#endif

+ 177 - 0
Samples/basic/directx10/src/main.cpp

@@ -0,0 +1,177 @@
+#include <Rocket/Core.h>
+#include <Rocket/Debugger.h>
+#include <Input.h>
+#include <Shell.h>
+#include "RenderInterfaceDirectX10.h"
+
+// Because we're a windows app
+#include <windows.h>
+
+// For _T unicode/mbcs macro
+#include <tchar.h>
+
+//Our device for this sample
+static ID3D10Device * pD3D10Device=NULL;
+//Swap Chain
+static IDXGISwapChain * pSwapChain=NULL;
+//Render Target
+static ID3D10RenderTargetView * pRenderTargetView=NULL;
+
+static Rocket::Core::Context* context = NULL;
+
+bool InitialiseDirectX()
+{
+	//get the size of the window
+	RECT windowRect;
+	GetClientRect((HWND) Shell::GetWindowHandle(),&windowRect);
+	UINT width=windowRect.right-windowRect.left;
+	UINT height=windowRect.bottom-windowRect.top;
+
+	//put the device into debug if we are in a debug build
+	UINT createDeviceFlags=0;
+#ifdef _DEBUG
+	createDeviceFlags|=D3D10_CREATE_DEVICE_DEBUG;
+#endif
+
+	//Setup swap chain
+	DXGI_SWAP_CHAIN_DESC sd;
+	ZeroMemory( &sd, sizeof( sd ) );
+	sd.BufferCount=1;
+	sd.OutputWindow = (HWND) Shell::GetWindowHandle();
+	sd.Windowed = TRUE;
+	sd.SampleDesc.Count = 1;
+	sd.SampleDesc.Quality = 0;
+	sd.BufferDesc.Width = width;
+	sd.BufferDesc.Height = height;
+	sd.BufferDesc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
+	sd.BufferDesc.RefreshRate.Numerator = 60;
+	sd.BufferDesc.RefreshRate.Denominator = 1;
+	sd.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT;
+
+	//Create device and swapchain
+	if (FAILED(D3D10CreateDeviceAndSwapChain(NULL, D3D10_DRIVER_TYPE_HARDWARE, NULL, createDeviceFlags,	D3D10_SDK_VERSION, &sd, &pSwapChain, &pD3D10Device)))
+	{
+		MessageBox(NULL, _T("D3D10CreateDeviceAndSwapChain failed for D3D10_DRIVER_TYPE_HARDWARE."), _T("Could not intialized DirectX 10"), MB_OK|MB_ICONERROR);
+		return false;
+	}
+	
+	//Create Render Target
+	ID3D10Texture2D *pBackBuffer;
+	if ( FAILED (pSwapChain->GetBuffer(0, __uuidof(ID3D10Texture2D),(void**)&pBackBuffer)))
+	{
+		MessageBox(NULL, _T("SwapChain->GetBuffer failed."), _T("Could not intialized DirectX 10"), MB_OK|MB_ICONERROR);
+		return false;
+	}
+	if (FAILED(pD3D10Device->CreateRenderTargetView( pBackBuffer, NULL, &pRenderTargetView )))
+	{
+			pBackBuffer->Release();
+			MessageBox(NULL, _T("D3D10Device->CreateRenderTargetView failed."), _T("Could not intialized DirectX 10"), MB_OK|MB_ICONERROR);
+			return false;
+	}
+	pBackBuffer->Release();
+	
+	pD3D10Device->OMSetRenderTargets(1,&pRenderTargetView,NULL);
+
+	D3D10_VIEWPORT vp;
+	vp.Width = width;
+	vp.Height = height;
+	vp.MinDepth = 0.0f;
+	vp.MaxDepth = 1.0f;
+	vp.TopLeftX = 0;
+	vp.TopLeftY = 0;
+	pD3D10Device->RSSetViewports( 1, &vp );
+
+	return true;
+}
+
+void ShutdownDirectX()
+{	
+	if (pD3D10Device)
+		pD3D10Device->ClearState();
+	if (pRenderTargetView)
+		pRenderTargetView->Release();
+	if (pSwapChain)
+		pSwapChain->Release();
+	if (pD3D10Device)
+		pD3D10Device->Release();
+}
+
+void GameLoop()
+{
+	float ClearColor[4] = { 0.0f, 0.125f, 0.3f, 1.0f };
+	pD3D10Device->ClearRenderTargetView( pRenderTargetView,ClearColor );
+
+	context->Update();
+	context->Render();
+
+	pSwapChain->Present( 0, 0 );
+}
+
+int APIENTRY WinMain(HINSTANCE ROCKET_UNUSED_PARAMETER(instance_handle), HINSTANCE ROCKET_UNUSED_PARAMETER(previous_instance_handle), char* ROCKET_UNUSED_PARAMETER(command_line), int ROCKET_UNUSED_PARAMETER(command_show))
+{
+	ROCKET_UNUSED(instance_handle);
+	ROCKET_UNUSED(previous_instance_handle);
+	ROCKET_UNUSED(command_line);
+	ROCKET_UNUSED(command_show);
+
+	// Generic OS initialisation, creates a window and does not attach OpenGL.
+	if (!Shell::Initialise("../Samples/basic/directx/") ||
+		!Shell::OpenWindow("DirectX 10 Sample", false))
+	{
+		Shell::Shutdown();
+		return -1;
+	}
+
+	// DirectX initialisation.
+	if (!InitialiseDirectX())
+	{
+		Shell::CloseWindow();
+		Shell::Shutdown();
+
+		return -1;
+	}
+
+	// Install our DirectX render interface into Rocket.
+	RenderInterfaceDirectX10 directx_renderer(pD3D10Device,1024,768);
+	Rocket::Core::SetRenderInterface(&directx_renderer);
+
+	ShellSystemInterface system_interface;
+	Rocket::Core::SetSystemInterface(&system_interface);
+
+	Rocket::Core::Initialise();
+
+	// Create the main Rocket context and set it on the shell's input layer.
+	context = Rocket::Core::CreateContext("main", Rocket::Core::Vector2i(1024, 768));
+	if (context == NULL)
+	{
+		Rocket::Core::Shutdown();
+		Shell::Shutdown();
+		return -1;
+	}
+
+	Rocket::Debugger::Initialise(context);
+	Input::SetContext(context);
+
+	Shell::LoadFonts("../../assets/");
+
+	// Load and show the tutorial document.
+	Rocket::Core::ElementDocument* document = context->LoadDocument("../../assets/demo.rml");
+	if (document != NULL)
+	{
+		document->Show();
+		document->RemoveReference();
+	}
+
+	Shell::EventLoop(GameLoop);
+
+	// Shutdown Rocket.
+	context->RemoveReference();
+	Rocket::Core::Shutdown();
+
+	ShutdownDirectX();
+
+	Shell::CloseWindow();
+	Shell::Shutdown();
+
+	return 0;
+}