Browse Source

added sfml2 sample (uses glew)

AirBash 14 years ago
parent
commit
9b8b93a4b8

+ 26 - 0
Samples/basic/sfml2/SFML.sln

@@ -0,0 +1,26 @@
+
+Microsoft Visual Studio Solution File, Format Version 11.00
+# Visual Studio 2010
+Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "SFML", "SFML.vcxproj", "{6A08A6A5-3848-4E4F-BCE8-6351E221164C}"
+EndProject
+Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Shell", "..\..\shell\Shell.vcxproj", "{AF4FF882-AFD9-457B-979E-A5B482388D46}"
+EndProject
+Global
+	GlobalSection(SolutionConfigurationPlatforms) = preSolution
+		Debug|Win32 = Debug|Win32
+		Release|Win32 = Release|Win32
+	EndGlobalSection
+	GlobalSection(ProjectConfigurationPlatforms) = postSolution
+		{6A08A6A5-3848-4E4F-BCE8-6351E221164C}.Debug|Win32.ActiveCfg = Debug|Win32
+		{6A08A6A5-3848-4E4F-BCE8-6351E221164C}.Debug|Win32.Build.0 = Debug|Win32
+		{6A08A6A5-3848-4E4F-BCE8-6351E221164C}.Release|Win32.ActiveCfg = Release|Win32
+		{6A08A6A5-3848-4E4F-BCE8-6351E221164C}.Release|Win32.Build.0 = Release|Win32
+		{AF4FF882-AFD9-457B-979E-A5B482388D46}.Debug|Win32.ActiveCfg = Debug|Win32
+		{AF4FF882-AFD9-457B-979E-A5B482388D46}.Debug|Win32.Build.0 = Debug|Win32
+		{AF4FF882-AFD9-457B-979E-A5B482388D46}.Release|Win32.ActiveCfg = Release|Win32
+		{AF4FF882-AFD9-457B-979E-A5B482388D46}.Release|Win32.Build.0 = Release|Win32
+	EndGlobalSection
+	GlobalSection(SolutionProperties) = preSolution
+		HideSolutionNode = FALSE
+	EndGlobalSection
+EndGlobal

+ 198 - 0
Samples/basic/sfml2/SFML.vcproj

@@ -0,0 +1,198 @@
+<?xml version="1.0" encoding="Windows-1252"?>
+<VisualStudioProject
+	ProjectType="Visual C++"
+	Version="9.00"
+	Name="SFML"
+	ProjectGUID="{6A08A6A5-3848-4E4F-BCE8-6351E221164C}"
+	RootNamespace="WorldBaseToybox"
+	Keyword="Win32Proj"
+	TargetFrameworkVersion="196613"
+	>
+	<Platforms>
+		<Platform
+			Name="Win32"
+		/>
+	</Platforms>
+	<ToolFiles>
+	</ToolFiles>
+	<Configurations>
+		<Configuration
+			Name="Debug|Win32"
+			OutputDirectory="$(SolutionDir)$(ConfigurationName)"
+			IntermediateDirectory="$(ConfigurationName)"
+			ConfigurationType="1"
+			CharacterSet="1"
+			>
+			<Tool
+				Name="VCPreBuildEventTool"
+			/>
+			<Tool
+				Name="VCCustomBuildTool"
+			/>
+			<Tool
+				Name="VCXMLDataGeneratorTool"
+			/>
+			<Tool
+				Name="VCWebServiceProxyGeneratorTool"
+			/>
+			<Tool
+				Name="VCMIDLTool"
+			/>
+			<Tool
+				Name="VCCLCompilerTool"
+				Optimization="0"
+				AdditionalIncludeDirectories="..\..\..\include;..\..\..\..\SFML\include;..\..\shell\include"
+				PreprocessorDefinitions="WIN32;_DEBUG;_CONSOLE"
+				MinimalRebuild="true"
+				BasicRuntimeChecks="3"
+				RuntimeLibrary="3"
+				UsePrecompiledHeader="0"
+				WarningLevel="3"
+				DebugInformationFormat="4"
+			/>
+			<Tool
+				Name="VCManagedResourceCompilerTool"
+			/>
+			<Tool
+				Name="VCResourceCompilerTool"
+			/>
+			<Tool
+				Name="VCPreLinkEventTool"
+			/>
+			<Tool
+				Name="VCLinkerTool"
+				AdditionalDependencies="RocketCore_d.lib RocketDebugger_d.lib sfml-system-s-d.lib sfml-window-s-d.lib sfml-graphics-s-d.lib"
+				LinkIncremental="2"
+				AdditionalLibraryDirectories="..\..\..\..\sfml\lib;..\..\..\bin"
+				GenerateDebugInformation="true"
+				SubSystem="1"
+				TargetMachine="1"
+			/>
+			<Tool
+				Name="VCALinkTool"
+			/>
+			<Tool
+				Name="VCManifestTool"
+			/>
+			<Tool
+				Name="VCXDCMakeTool"
+			/>
+			<Tool
+				Name="VCBscMakeTool"
+			/>
+			<Tool
+				Name="VCFxCopTool"
+			/>
+			<Tool
+				Name="VCAppVerifierTool"
+			/>
+			<Tool
+				Name="VCPostBuildEventTool"
+				CommandLine=""
+			/>
+		</Configuration>
+		<Configuration
+			Name="Release|Win32"
+			OutputDirectory="$(SolutionDir)$(ConfigurationName)"
+			IntermediateDirectory="$(ConfigurationName)"
+			ConfigurationType="1"
+			CharacterSet="1"
+			WholeProgramOptimization="1"
+			>
+			<Tool
+				Name="VCPreBuildEventTool"
+			/>
+			<Tool
+				Name="VCCustomBuildTool"
+			/>
+			<Tool
+				Name="VCXMLDataGeneratorTool"
+			/>
+			<Tool
+				Name="VCWebServiceProxyGeneratorTool"
+			/>
+			<Tool
+				Name="VCMIDLTool"
+			/>
+			<Tool
+				Name="VCCLCompilerTool"
+				Optimization="2"
+				EnableIntrinsicFunctions="true"
+				AdditionalIncludeDirectories="..\..\..\include;..\..\..\..\SFML\include;..\..\Shell\Include"
+				PreprocessorDefinitions="WIN32;NDEBUG;_CONSOLE"
+				RuntimeLibrary="2"
+				EnableFunctionLevelLinking="true"
+				UsePrecompiledHeader="0"
+				WarningLevel="3"
+				DebugInformationFormat="3"
+			/>
+			<Tool
+				Name="VCManagedResourceCompilerTool"
+			/>
+			<Tool
+				Name="VCResourceCompilerTool"
+			/>
+			<Tool
+				Name="VCPreLinkEventTool"
+			/>
+			<Tool
+				Name="VCLinkerTool"
+				AdditionalDependencies="RocketCore.lib RocketDebugger.lib sfml-system-s.lib sfml-window-s.lib sfml-graphics-s.lib"
+				LinkIncremental="1"
+				AdditionalLibraryDirectories="..\..\..\..\sfml\lib;..\..\..\bin"
+				GenerateDebugInformation="true"
+				SubSystem="1"
+				OptimizeReferences="2"
+				EnableCOMDATFolding="2"
+				TargetMachine="1"
+			/>
+			<Tool
+				Name="VCALinkTool"
+			/>
+			<Tool
+				Name="VCManifestTool"
+			/>
+			<Tool
+				Name="VCXDCMakeTool"
+			/>
+			<Tool
+				Name="VCBscMakeTool"
+			/>
+			<Tool
+				Name="VCFxCopTool"
+			/>
+			<Tool
+				Name="VCAppVerifierTool"
+			/>
+			<Tool
+				Name="VCPostBuildEventTool"
+			/>
+		</Configuration>
+	</Configurations>
+	<References>
+	</References>
+	<Files>
+		<File
+			RelativePath=".\src\main.cpp"
+			>
+		</File>
+		<File
+			RelativePath=".\src\RenderInterfaceSFML.cpp"
+			>
+		</File>
+		<File
+			RelativePath=".\src\RenderInterfaceSFML.h"
+			>
+		</File>
+		<File
+			RelativePath=".\src\SystemInterfaceSFML.cpp"
+			>
+		</File>
+		<File
+			RelativePath=".\src\SystemInterfaceSFML.h"
+			>
+		</File>
+	</Files>
+	<Globals>
+	</Globals>
+</VisualStudioProject>

+ 349 - 0
Samples/basic/sfml2/src/RenderInterfaceSFML.cpp

@@ -0,0 +1,349 @@
+/*
+ * This source file is part of libRocket, the HTML/CSS Interface Middleware
+ *
+ * For the latest information, see http://www.librocket.com
+ *
+ * Copyright (c) 2008-2010 Nuno Silva
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ * 
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ *
+ */
+
+#include <Rocket/Core/Core.h>
+#include "RenderInterfaceSFML.h"
+
+#ifdef ENABLE_GLEW
+#include <gl/glew.h>
+#endif
+
+#ifndef GL_CLAMP_TO_EDGE
+#define GL_CLAMP_TO_EDGE 0x812F
+#endif
+// If built with the GL Easy Extension library we can compile geometry to VBO's
+// http://www.opengl.org/sdk/libs/GLee/
+#ifdef ENABLE_GLEW
+
+class RocketSFMLRendererGeometryHandler
+{
+public:
+	GLuint VertexID, IndexID;
+	int NumVertices;
+	Rocket::Core::TextureHandle Texture;
+
+	RocketSFMLRendererGeometryHandler() : VertexID(0), IndexID(0), Texture(0), NumVertices(0)
+	{
+	};
+
+	~RocketSFMLRendererGeometryHandler()
+	{
+		if(VertexID)
+			glDeleteBuffers(1, &VertexID);
+
+		if(IndexID)
+			glDeleteBuffers(1, &IndexID);
+
+		VertexID = IndexID = 0;
+	};
+};
+
+#endif
+
+struct RocketSFMLRendererVertex
+{
+	sf::Vector2f Position, TexCoord;
+	sf::Color Color;
+};
+
+RocketSFMLRenderer::RocketSFMLRenderer()
+{
+}
+
+void RocketSFMLRenderer::SetWindow(sf::RenderWindow *Window)
+{
+	MyWindow = Window;
+
+	Resize();
+};
+
+sf::RenderWindow *RocketSFMLRenderer::GetWindow()
+{
+	return MyWindow;
+};
+
+void RocketSFMLRenderer::Resize()
+{
+	MyWindow->SetActive(true);
+	//MyWindow->SaveGLStates();
+
+	static sf::View View;
+	//View.SetFromRect(sf::FloatRect(0, (float)MyWindow->GetWidth(), (float)MyWindow->GetHeight(), 0));
+	View.SetViewport(sf::FloatRect(0, (float)MyWindow->GetWidth(), (float)MyWindow->GetHeight(), 0));
+	MyWindow->SetView(View);
+
+	glMatrixMode(GL_PROJECTION);
+	glLoadIdentity();
+	glOrtho(0, MyWindow->GetWidth(), MyWindow->GetHeight(), 0, -1, 1);
+	glMatrixMode(GL_MODELVIEW);
+
+	glViewport(0, 0, MyWindow->GetWidth(), MyWindow->GetHeight());
+
+	//MyWindow->RestoreGLStates();
+};
+
+// Called by Rocket when it wants to render geometry that it does not wish to optimise.
+void RocketSFMLRenderer::RenderGeometry(Rocket::Core::Vertex* vertices, int num_vertices, int* indices, int num_indices, const Rocket::Core::TextureHandle texture, const Rocket::Core::Vector2f& translation)
+{
+	MyWindow->SetActive();
+
+	glPushMatrix();
+	glTranslatef(translation.x, translation.y, 0);
+
+	std::vector<Rocket::Core::Vector2f> Positions(num_vertices);
+	std::vector<Rocket::Core::Colourb> Colors(num_vertices);
+	std::vector<Rocket::Core::Vector2f> TexCoords(num_vertices);
+
+	for(int  i = 0; i < num_vertices; i++)
+	{
+		Positions[i] = vertices[i].position;
+		Colors[i] = vertices[i].colour;
+		TexCoords[i] = vertices[i].tex_coord;
+	};
+
+	glEnableClientState(GL_VERTEX_ARRAY);
+	glEnableClientState(GL_COLOR_ARRAY);
+	glEnableClientState(GL_TEXTURE_COORD_ARRAY);
+
+	glVertexPointer(2, GL_FLOAT, 0, &Positions[0]);
+	glColorPointer(4, GL_UNSIGNED_BYTE, 0, &Colors[0]);
+	glTexCoordPointer(2, GL_FLOAT, 0, &TexCoords[0]);
+
+	glEnable(GL_BLEND);
+	glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
+
+	sf::Image *image = (sf::Image *)texture;
+
+	if(image)
+	{
+		image->Bind();
+	}
+	else
+	{
+		glDisableClientState(GL_TEXTURE_COORD_ARRAY);
+		glBindTexture(GL_TEXTURE_2D, 0);
+	};
+
+	glDrawElements(GL_TRIANGLES, num_indices, GL_UNSIGNED_INT, indices);
+
+	glDisableClientState(GL_VERTEX_ARRAY);
+	glDisableClientState(GL_COLOR_ARRAY);
+	glDisableClientState(GL_TEXTURE_COORD_ARRAY);
+
+	glColor4f(1, 1, 1, 1);
+
+	glPopMatrix();
+}
+
+// Called by Rocket when it wants to compile geometry it believes will be static for the forseeable future.		
+Rocket::Core::CompiledGeometryHandle RocketSFMLRenderer::CompileGeometry(Rocket::Core::Vertex* vertices,
+																		   int num_vertices, int* indices,
+																		   int num_indices,
+																		   const Rocket::Core::TextureHandle texture)
+{
+#ifdef ENABLE_GLEW
+	MyWindow->SetActive();
+
+	//if(!GLEE_VERSION_2_0)
+		//return (Rocket::Core::CompiledGeometryHandle) NULL;
+
+	std::vector<RocketSFMLRendererVertex> Data(num_vertices);
+
+	for(unsigned long i = 0; i < Data.size(); i++)
+	{
+		Data[i].Position = *(sf::Vector2f*)&vertices[i].position;
+		Data[i].TexCoord = *(sf::Vector2f*)&vertices[i].tex_coord;
+		Data[i].Color = sf::Color(vertices[i].colour.red, vertices[i].colour.green,
+			vertices[i].colour.blue, vertices[i].colour.alpha);
+	};
+
+	RocketSFMLRendererGeometryHandler *Geometry = new RocketSFMLRendererGeometryHandler();
+	Geometry->NumVertices = num_indices;
+
+	glGenBuffers(1, &Geometry->VertexID);
+	glBindBuffer(GL_ARRAY_BUFFER, Geometry->VertexID);
+	glBufferData(GL_ARRAY_BUFFER, sizeof(RocketSFMLRendererVertex) * num_vertices, &Data[0],
+		GL_STATIC_DRAW);
+
+	glGenBuffers(1, &Geometry->IndexID);
+	glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, Geometry->IndexID);
+	glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(int) * num_indices, indices, GL_STATIC_DRAW);
+
+	glBindBuffer(GL_ARRAY_BUFFER, 0);
+
+	Geometry->Texture = texture;
+
+	return (Rocket::Core::CompiledGeometryHandle)Geometry;
+#else
+	return NULL;
+#endif
+}
+
+// Called by Rocket when it wants to render application-compiled geometry.		
+void RocketSFMLRenderer::RenderCompiledGeometry(Rocket::Core::CompiledGeometryHandle geometry, const Rocket::Core::Vector2f& translation)
+{
+#ifdef ENABLE_GLEW
+	MyWindow->SetActive();
+
+	RocketSFMLRendererGeometryHandler *RealGeometry = (RocketSFMLRendererGeometryHandler *)geometry;
+
+	glPushMatrix();
+	glTranslatef(translation.x, translation.y, 0);
+	glEnable(GL_BLEND);
+	glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
+
+	sf::Image *image = (sf::Image *)RealGeometry->Texture;
+
+	if(image)
+	{
+		image->Bind();
+	}
+	else
+	{
+		glBindTexture(GL_TEXTURE_2D, 0);
+	};
+
+	glEnable(GL_VERTEX_ARRAY);
+	glEnable(GL_TEXTURE_COORD_ARRAY);
+	glEnable(GL_COLOR_ARRAY);
+
+	#define BUFFER_OFFSET(x) ((char*)0 + x)
+
+	glBindBuffer(GL_ARRAY_BUFFER, RealGeometry->VertexID);
+	glVertexPointer(2, GL_FLOAT, sizeof(RocketSFMLRendererVertex), BUFFER_OFFSET(0));
+	glTexCoordPointer(2, GL_FLOAT, sizeof(RocketSFMLRendererVertex), BUFFER_OFFSET(sizeof(sf::Vector2f)));
+	glColorPointer(4, GL_UNSIGNED_BYTE, sizeof(RocketSFMLRendererVertex), BUFFER_OFFSET(sizeof(sf::Vector2f[2])));
+
+	glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, RealGeometry->IndexID);
+	glDrawElements(GL_TRIANGLES, RealGeometry->NumVertices, GL_UNSIGNED_INT, BUFFER_OFFSET(0));
+
+	glBindBuffer(GL_ARRAY_BUFFER, 0);
+
+	glDisable(GL_COLOR_ARRAY);
+	glDisable(GL_TEXTURE_COORD_ARRAY);
+	glDisable(GL_VERTEX_ARRAY);
+
+	glColor4f(1, 1, 1, 1);
+
+	glPopMatrix();
+#else
+	ROCKET_ASSERT(false /*& "Not Implemented"*/);
+#endif
+}
+
+// Called by Rocket when it wants to release application-compiled geometry.		
+void RocketSFMLRenderer::ReleaseCompiledGeometry(Rocket::Core::CompiledGeometryHandle geometry)
+{
+#ifdef ENABLE_GLEW
+	MyWindow->SetActive();
+
+	delete (RocketSFMLRendererGeometryHandler *)geometry;
+#else
+	ROCKET_ASSERT(false /*& "Not Implemented"*/);
+#endif
+}
+
+// Called by Rocket when it wants to enable or disable scissoring to clip content.		
+void RocketSFMLRenderer::EnableScissorRegion(bool enable)
+{
+	MyWindow->SetActive();
+
+	if (enable)
+		glEnable(GL_SCISSOR_TEST);
+	else
+		glDisable(GL_SCISSOR_TEST);
+}
+
+// Called by Rocket when it wants to change the scissor region.		
+void RocketSFMLRenderer::SetScissorRegion(int x, int y, int width, int height)
+{
+	MyWindow->SetActive();
+
+	glScissor(x, MyWindow->GetHeight() - (y + height), width, height);
+}
+
+// Called by Rocket when a texture is required by the library.		
+bool RocketSFMLRenderer::LoadTexture(Rocket::Core::TextureHandle& texture_handle, Rocket::Core::Vector2i& texture_dimensions, const Rocket::Core::String& source)
+{
+	MyWindow->SetActive();
+
+	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);
+
+	sf::Image *image = new sf::Image();
+
+	if(!image->LoadFromMemory(buffer, buffer_size))
+	{
+		delete buffer;
+		delete image;
+
+		return false;
+	};
+	delete buffer;
+
+	texture_handle = (Rocket::Core::TextureHandle) image;
+	texture_dimensions = Rocket::Core::Vector2i(image->GetWidth(), image->GetHeight());
+
+	return true;
+}
+
+// Called by Rocket when a texture is required to be built from an internally-generated sequence of pixels.
+bool RocketSFMLRenderer::GenerateTexture(Rocket::Core::TextureHandle& texture_handle, const Rocket::Core::byte* source, const Rocket::Core::Vector2i& source_dimensions)
+{
+	MyWindow->SetActive();
+
+	sf::Image *image = new sf::Image();
+
+	if(!image->LoadFromPixels(source_dimensions.x, source_dimensions.y, source))
+	{
+		delete image;
+
+		return false;
+	};
+
+	texture_handle = (Rocket::Core::TextureHandle)image;
+
+	return true;
+}
+
+// Called by Rocket when a loaded texture is no longer required.		
+void RocketSFMLRenderer::ReleaseTexture(Rocket::Core::TextureHandle texture_handle)
+{
+	MyWindow->SetActive();
+
+	delete (sf::Image *)texture_handle;
+}

+ 77 - 0
Samples/basic/sfml2/src/RenderInterfaceSFML.h

@@ -0,0 +1,77 @@
+/*
+ * This source file is part of libRocket, the HTML/CSS Interface Middleware
+ *
+ * For the latest information, see http://www.librocket.com
+ *
+ * Copyright (c) 2008-2010 Nuno Silva
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ * 
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ *
+ */
+#ifndef RENDERINTERFACESFML_H
+#define RENDERINTERFACESFML_H
+
+
+#include <Rocket/Core/RenderInterface.h>
+#include <SFML/Graphics.hpp>
+
+#define ENABLE_GLEW
+
+class RocketSFMLRenderer : public Rocket::Core::RenderInterface
+{
+public:
+	RocketSFMLRenderer();
+
+	/// Sets the window
+	void SetWindow(sf::RenderWindow *Window);
+
+	/// Returns the currently assigned window
+	sf::RenderWindow *GetWindow();
+
+	/// Resizes the viewport automatically
+	void Resize();
+
+	/// 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 Rocket::Core::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);
+
+private:
+	sf::RenderWindow *MyWindow;
+};
+
+#endif

+ 341 - 0
Samples/basic/sfml2/src/SystemInterfaceSFML.cpp

@@ -0,0 +1,341 @@
+/*
+ * This source file is part of libRocket, the HTML/CSS Interface Middleware
+ *
+ * For the latest information, see http://www.librocket.com
+ *
+ * Copyright (c) 2008-2010 Nuno Silva
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ * 
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ *
+ */
+#include <Rocket/Core.h>
+#include "SystemInterfaceSFML.h"
+
+int RocketSFMLSystemInterface::GetKeyModifiers(sf::Window *Window)
+{
+	int Modifiers = 0;
+
+	if(Window->GetInput().IsKeyDown(sf::Key::LShift) ||
+		Window->GetInput().IsKeyDown(sf::Key::RShift))
+		Modifiers |= Rocket::Core::Input::KM_SHIFT;
+
+	if(Window->GetInput().IsKeyDown(sf::Key::LControl) ||
+		Window->GetInput().IsKeyDown(sf::Key::RControl))
+		Modifiers |= Rocket::Core::Input::KM_CTRL;
+
+	if(Window->GetInput().IsKeyDown(sf::Key::LAlt) ||
+		Window->GetInput().IsKeyDown(sf::Key::RAlt))
+		Modifiers |= Rocket::Core::Input::KM_ALT;
+
+	return Modifiers;
+};
+
+Rocket::Core::Input::KeyIdentifier RocketSFMLSystemInterface::TranslateKey(sf::Key::Code Key)
+{
+	switch(Key)
+	{
+	case sf::Key::A:
+		return Rocket::Core::Input::KI_A;
+		break;
+	case sf::Key::B:
+		return Rocket::Core::Input::KI_B;
+		break;
+	case sf::Key::C:
+		return Rocket::Core::Input::KI_C;
+		break;
+	case sf::Key::D:
+		return Rocket::Core::Input::KI_D;
+		break;
+	case sf::Key::E:
+		return Rocket::Core::Input::KI_E;
+		break;
+	case sf::Key::F:
+		return Rocket::Core::Input::KI_F;
+		break;
+	case sf::Key::G:
+		return Rocket::Core::Input::KI_G;
+		break;
+	case sf::Key::H:
+		return Rocket::Core::Input::KI_H;
+		break;
+	case sf::Key::I:
+		return Rocket::Core::Input::KI_I;
+		break;
+	case sf::Key::J:
+		return Rocket::Core::Input::KI_J;
+		break;
+	case sf::Key::K:
+		return Rocket::Core::Input::KI_K;
+		break;
+	case sf::Key::L:
+		return Rocket::Core::Input::KI_L;
+		break;
+	case sf::Key::M:
+		return Rocket::Core::Input::KI_M;
+		break;
+	case sf::Key::N:
+		return Rocket::Core::Input::KI_N;
+		break;
+	case sf::Key::O:
+		return Rocket::Core::Input::KI_O;
+		break;
+	case sf::Key::P:
+		return Rocket::Core::Input::KI_P;
+		break;
+	case sf::Key::Q:
+		return Rocket::Core::Input::KI_Q;
+		break;
+	case sf::Key::R:
+		return Rocket::Core::Input::KI_R;
+		break;
+	case sf::Key::S:
+		return Rocket::Core::Input::KI_S;
+		break;
+	case sf::Key::T:
+		return Rocket::Core::Input::KI_T;
+		break;
+	case sf::Key::U:
+		return Rocket::Core::Input::KI_U;
+		break;
+	case sf::Key::V:
+		return Rocket::Core::Input::KI_V;
+		break;
+	case sf::Key::W:
+		return Rocket::Core::Input::KI_W;
+		break;
+	case sf::Key::X:
+		return Rocket::Core::Input::KI_X;
+		break;
+	case sf::Key::Y:
+		return Rocket::Core::Input::KI_Y;
+		break;
+	case sf::Key::Z:
+		return Rocket::Core::Input::KI_Z;
+		break;
+	case sf::Key::Num0:
+		return Rocket::Core::Input::KI_0;
+		break;
+	case sf::Key::Num1:
+		return Rocket::Core::Input::KI_1;
+		break;
+	case sf::Key::Num2:
+		return Rocket::Core::Input::KI_2;
+		break;
+	case sf::Key::Num3:
+		return Rocket::Core::Input::KI_3;
+		break;
+	case sf::Key::Num4:
+		return Rocket::Core::Input::KI_4;
+		break;
+	case sf::Key::Num5:
+		return Rocket::Core::Input::KI_5;
+		break;
+	case sf::Key::Num6:
+		return Rocket::Core::Input::KI_6;
+		break;
+	case sf::Key::Num7:
+		return Rocket::Core::Input::KI_7;
+		break;
+	case sf::Key::Num8:
+		return Rocket::Core::Input::KI_8;
+		break;
+	case sf::Key::Num9:
+		return Rocket::Core::Input::KI_9;
+		break;
+	case sf::Key::Numpad0:
+		return Rocket::Core::Input::KI_NUMPAD0;
+		break;
+	case sf::Key::Numpad1:
+		return Rocket::Core::Input::KI_NUMPAD1;
+		break;
+	case sf::Key::Numpad2:
+		return Rocket::Core::Input::KI_NUMPAD2;
+		break;
+	case sf::Key::Numpad3:
+		return Rocket::Core::Input::KI_NUMPAD3;
+		break;
+	case sf::Key::Numpad4:
+		return Rocket::Core::Input::KI_NUMPAD4;
+		break;
+	case sf::Key::Numpad5:
+		return Rocket::Core::Input::KI_NUMPAD5;
+		break;
+	case sf::Key::Numpad6:
+		return Rocket::Core::Input::KI_NUMPAD6;
+		break;
+	case sf::Key::Numpad7:
+		return Rocket::Core::Input::KI_NUMPAD7;
+		break;
+	case sf::Key::Numpad8:
+		return Rocket::Core::Input::KI_NUMPAD8;
+		break;
+	case sf::Key::Numpad9:
+		return Rocket::Core::Input::KI_NUMPAD9;
+		break;
+	case sf::Key::Left:
+		return Rocket::Core::Input::KI_LEFT;
+		break;
+	case sf::Key::Right:
+		return Rocket::Core::Input::KI_RIGHT;
+		break;
+	case sf::Key::Up:
+		return Rocket::Core::Input::KI_UP;
+		break;
+	case sf::Key::Down:
+		return Rocket::Core::Input::KI_DOWN;
+		break;
+	case sf::Key::Add:
+		return Rocket::Core::Input::KI_ADD;
+		break;
+	case sf::Key::Back:
+		return Rocket::Core::Input::KI_BACK;
+		break;
+	case sf::Key::Delete:
+		return Rocket::Core::Input::KI_DELETE;
+		break;
+	case sf::Key::Divide:
+		return Rocket::Core::Input::KI_DIVIDE;
+		break;
+	case sf::Key::End:
+		return Rocket::Core::Input::KI_END;
+		break;
+	case sf::Key::Escape:
+		return Rocket::Core::Input::KI_ESCAPE;
+		break;
+	case sf::Key::F1:
+		return Rocket::Core::Input::KI_F1;
+		break;
+	case sf::Key::F2:
+		return Rocket::Core::Input::KI_F2;
+		break;
+	case sf::Key::F3:
+		return Rocket::Core::Input::KI_F3;
+		break;
+	case sf::Key::F4:
+		return Rocket::Core::Input::KI_F4;
+		break;
+	case sf::Key::F5:
+		return Rocket::Core::Input::KI_F5;
+		break;
+	case sf::Key::F6:
+		return Rocket::Core::Input::KI_F6;
+		break;
+	case sf::Key::F7:
+		return Rocket::Core::Input::KI_F7;
+		break;
+	case sf::Key::F8:
+		return Rocket::Core::Input::KI_F8;
+		break;
+	case sf::Key::F9:
+		return Rocket::Core::Input::KI_F9;
+		break;
+	case sf::Key::F10:
+		return Rocket::Core::Input::KI_F10;
+		break;
+	case sf::Key::F11:
+		return Rocket::Core::Input::KI_F11;
+		break;
+	case sf::Key::F12:
+		return Rocket::Core::Input::KI_F12;
+		break;
+	case sf::Key::F13:
+		return Rocket::Core::Input::KI_F13;
+		break;
+	case sf::Key::F14:
+		return Rocket::Core::Input::KI_F14;
+		break;
+	case sf::Key::F15:
+		return Rocket::Core::Input::KI_F15;
+		break;
+	case sf::Key::Home:
+		return Rocket::Core::Input::KI_HOME;
+		break;
+	case sf::Key::Insert:
+		return Rocket::Core::Input::KI_INSERT;
+		break;
+	case sf::Key::LControl:
+		return Rocket::Core::Input::KI_LCONTROL;
+		break;
+	case sf::Key::LShift:
+		return Rocket::Core::Input::KI_LSHIFT;
+		break;
+	case sf::Key::Multiply:
+		return Rocket::Core::Input::KI_MULTIPLY;
+		break;
+	case sf::Key::Pause:
+		return Rocket::Core::Input::KI_PAUSE;
+		break;
+	case sf::Key::RControl:
+		return Rocket::Core::Input::KI_RCONTROL;
+		break;
+	case sf::Key::Return:
+		return Rocket::Core::Input::KI_RETURN;
+		break;
+	case sf::Key::RShift:
+		return Rocket::Core::Input::KI_RSHIFT;
+		break;
+	case sf::Key::Space:
+		return Rocket::Core::Input::KI_SPACE;
+		break;
+	case sf::Key::Subtract:
+		return Rocket::Core::Input::KI_SUBTRACT;
+		break;
+	case sf::Key::Tab:
+		return Rocket::Core::Input::KI_TAB;
+		break;
+	};
+
+	return Rocket::Core::Input::KI_UNKNOWN;
+};
+
+float RocketSFMLSystemInterface::GetElapsedTime()
+{
+	return timer.GetElapsedTime();
+};
+
+bool RocketSFMLSystemInterface::LogMessage(Rocket::Core::Log::Type type, const Rocket::Core::String& message)
+{
+	std::string Type;
+
+	switch(type)
+	{
+	case Rocket::Core::Log::LT_ALWAYS:
+		Type = "[Always]";
+		break;
+	case Rocket::Core::Log::LT_ERROR:
+		Type = "[Error]";
+		break;
+	case Rocket::Core::Log::LT_ASSERT:
+		Type = "[Assert]";
+		break;
+	case Rocket::Core::Log::LT_WARNING:
+		Type = "[Warning]";
+		break;
+	case Rocket::Core::Log::LT_INFO:
+		Type = "[Info]";
+		break;
+	case Rocket::Core::Log::LT_DEBUG:
+		Type = "[Debug]";
+		break;
+	};
+
+	printf("%s - %s\n", Type.c_str(), message.CString());
+
+	return true;
+};

+ 46 - 0
Samples/basic/sfml2/src/SystemInterfaceSFML.h

@@ -0,0 +1,46 @@
+/*
+ * This source file is part of libRocket, the HTML/CSS Interface Middleware
+ *
+ * For the latest information, see http://www.librocket.com
+ *
+ * Copyright (c) 2008-2010 Nuno Silva
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ * 
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ *
+ */
+#ifndef SYSTEMINTEFACESFML_H
+#define SYSTEMINTEFACESFML_H
+
+#include <Rocket/Core/SystemInterface.h>
+#include <Rocket/Core/Input.h>
+#include <SFML/Graphics.hpp>
+
+class RocketSFMLSystemInterface : public Rocket::Core::SystemInterface
+{
+public:
+
+	Rocket::Core::Input::KeyIdentifier TranslateKey(sf::Key::Code Key);
+	int GetKeyModifiers(sf::Window *Window);
+	float GetElapsedTime();
+	bool LogMessage(Rocket::Core::Log::Type type, const Rocket::Core::String& message);
+
+private:
+	sf::Clock timer;
+};
+#endif

+ 146 - 0
Samples/basic/sfml2/src/main.cpp

@@ -0,0 +1,146 @@
+/*
+ * This source file is part of libRocket, the HTML/CSS Interface Middleware
+ *
+ * For the latest information, see http://www.librocket.com
+ *
+ * Copyright (c) 2008-2010 Nuno Silva
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ * 
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ *
+ */
+
+#include <gl/glew.h>
+#include <Rocket/Core.h>
+#include "SystemInterfaceSFML.h"
+#include "RenderInterfaceSFML.h"
+#include <Rocket/Core/Input.h>
+#include <Rocket/Debugger/Debugger.h>
+#include "ShellFileInterface.h"
+
+int main(int argc, char **argv)
+{
+	sf::RenderWindow MyWindow(sf::VideoMode(800, 600), "libRocket with SFML");
+
+	GLenum err = glewInit();
+	if (GLEW_OK != err)
+	{
+	  /* Problem: glewInit failed, something is seriously wrong. */
+	  fprintf(stderr, "Error: %s\n", glewGetErrorString(err));
+	  //...
+	}
+	fprintf(stdout, "Status: Using GLEW %s\n", glewGetString(GLEW_VERSION));
+
+	RocketSFMLRenderer Renderer;
+	RocketSFMLSystemInterface SystemInterface;
+	ShellFileInterface FileInterface("../Samples/assets/");
+
+	if(!MyWindow.IsOpened())
+		return 1;
+
+	Renderer.SetWindow(&MyWindow);
+
+	Rocket::Core::SetFileInterface(&FileInterface);
+	Rocket::Core::SetRenderInterface(&Renderer);
+	Rocket::Core::SetSystemInterface(&SystemInterface);
+
+	if(!Rocket::Core::Initialise())
+		return 1;
+
+	Rocket::Core::FontDatabase::LoadFontFace("Delicious-Bold.otf");
+	Rocket::Core::FontDatabase::LoadFontFace("Delicious-BoldItalic.otf");
+	Rocket::Core::FontDatabase::LoadFontFace("Delicious-Italic.otf");
+	Rocket::Core::FontDatabase::LoadFontFace("Delicious-Roman.otf");
+
+	Rocket::Core::Context *Context = Rocket::Core::CreateContext("default",
+		Rocket::Core::Vector2i(MyWindow.GetWidth(), MyWindow.GetHeight()));
+
+	Rocket::Debugger::Initialise(Context);
+
+	Rocket::Core::ElementDocument *Document = Context->LoadDocument("demo.rml");
+
+	if(Document)
+	{
+		Document->Show();
+		Document->RemoveReference();
+		fprintf(stdout, "\nDocument loaded");
+	}
+	else
+	{
+		fprintf(stdout, "\nDocument is NULL");
+	}
+
+	while(MyWindow.IsOpened())
+	{
+		static sf::Event event;
+
+		MyWindow.Clear();
+		Context->Render();
+		MyWindow.Display();
+
+		while(MyWindow.GetEvent(event))
+		{
+			switch(event.Type)
+			{
+			case sf::Event::Resized:
+				Renderer.Resize();
+				break;
+			case sf::Event::MouseMoved:
+				Context->ProcessMouseMove(event.MouseMove.X, event.MouseMove.Y,
+					SystemInterface.GetKeyModifiers(&MyWindow));
+				break;
+			case sf::Event::MouseButtonPressed:
+				Context->ProcessMouseButtonDown(event.MouseButton.Button,
+					SystemInterface.GetKeyModifiers(&MyWindow));
+				break;
+			case sf::Event::MouseButtonReleased:
+				Context->ProcessMouseButtonUp(event.MouseButton.Button,
+					SystemInterface.GetKeyModifiers(&MyWindow));
+				break;
+			case sf::Event::MouseWheelMoved:
+				Context->ProcessMouseWheel(event.MouseWheel.Delta,
+					SystemInterface.GetKeyModifiers(&MyWindow));
+				break;
+			case sf::Event::TextEntered:
+				if (event.Text.Unicode > 32)
+					Context->ProcessTextInput(event.Text.Unicode);
+				break;
+			case sf::Event::KeyPressed:
+				Context->ProcessKeyDown(SystemInterface.TranslateKey(event.Key.Code),
+					SystemInterface.GetKeyModifiers(&MyWindow));
+				break;
+			case sf::Event::KeyReleased:
+				if(event.Key.Code == sf::Key::F8)
+				{
+					Rocket::Debugger::SetVisible(!Rocket::Debugger::IsVisible());
+				};
+
+				Context->ProcessKeyUp(SystemInterface.TranslateKey(event.Key.Code),
+					SystemInterface.GetKeyModifiers(&MyWindow));
+				break;
+			case sf::Event::Closed:
+				return 1;
+				break;
+			};
+		};
+
+		Context->Update();
+	};
+
+	return 0;
+};