Merge branch 'freetype'

This commit is contained in:
pchote
2010-02-20 19:46:35 +13:00
13 changed files with 121 additions and 73 deletions

BIN
FreeSans.ttf Executable file

Binary file not shown.

BIN
FreeSansBold.ttf Normal file

Binary file not shown.

View File

@@ -8,7 +8,7 @@ COMMON_LIBS = System.dll System.Core.dll System.Drawing.dll System.Xml.dll
fileformats_SRCS = $(shell find OpenRa.FileFormats/ -iname '*.cs') fileformats_SRCS = $(shell find OpenRa.FileFormats/ -iname '*.cs')
fileformats_TARGET = OpenRa.FileFormats.dll fileformats_TARGET = OpenRa.FileFormats.dll
fileformats_KIND = library fileformats_KIND = library
fileformats_LIBS = $(COMMON_LIBS) fileformats_LIBS = $(COMMON_LIBS) thirdparty/Tao/Tao.Glfw.dll
gl_SRCS = $(shell find OpenRa.Gl/ -iname '*.cs') gl_SRCS = $(shell find OpenRa.Gl/ -iname '*.cs')
gl_TARGET = OpenRa.Gl.dll gl_TARGET = OpenRa.Gl.dll
@@ -16,7 +16,7 @@ gl_KIND = library
gl_DEPS = $(fileformats_TARGET) $(game_TARGET) \ gl_DEPS = $(fileformats_TARGET) $(game_TARGET) \
thirdparty/Tao/Tao.Glfw.dll thirdparty/Tao/Tao.Glfw.dll
gl_LIBS = $(COMMON_LIBS) System.Windows.Forms.dll \ gl_LIBS = $(COMMON_LIBS) System.Windows.Forms.dll \
thirdparty/Tao/Tao.Cg.dll thirdparty/Tao/Tao.OpenGl.dll \ thirdparty/Tao/Tao.Cg.dll thirdparty/Tao.Externals.dll \
$(gl_DEPS) $(game_TARGET) $(gl_DEPS) $(game_TARGET)
game_SRCS = $(shell find OpenRa.Game/ -iname '*.cs') game_SRCS = $(shell find OpenRa.Game/ -iname '*.cs')
@@ -24,7 +24,7 @@ game_TARGET = OpenRa.Game.exe
game_KIND = winexe game_KIND = winexe
game_DEPS = $(fileformats_TARGET) game_DEPS = $(fileformats_TARGET)
game_LIBS = $(COMMON_LIBS) System.Windows.Forms.dll $(game_DEPS) \ game_LIBS = $(COMMON_LIBS) System.Windows.Forms.dll $(game_DEPS) \
thirdparty/Tao/Tao.OpenAl.dll thirdparty/Tao.Externals.dll thirdparty/ISE.FreeType.dll
game_FLAGS = -win32icon:OpenRa.Game/OpenRa.ico game_FLAGS = -win32icon:OpenRa.Game/OpenRa.ico
ra_SRCS = $(shell find OpenRa.Mods.RA/ -iname '*.cs') ra_SRCS = $(shell find OpenRa.Mods.RA/ -iname '*.cs')

View File

@@ -1,4 +1,5 @@
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003" ToolsVersion="3.5"> <?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003" ToolsVersion="3.5">
<PropertyGroup> <PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration> <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform> <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
@@ -24,6 +25,8 @@
<DebugType>full</DebugType> <DebugType>full</DebugType>
<PlatformTarget>AnyCPU</PlatformTarget> <PlatformTarget>AnyCPU</PlatformTarget>
<ErrorReport>prompt</ErrorReport> <ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<Optimize>false</Optimize>
</PropertyGroup> </PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' "> <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<OutputPath>bin\Release\</OutputPath> <OutputPath>bin\Release\</OutputPath>
@@ -33,6 +36,7 @@
<DebugType>pdbonly</DebugType> <DebugType>pdbonly</DebugType>
<PlatformTarget>AnyCPU</PlatformTarget> <PlatformTarget>AnyCPU</PlatformTarget>
<ErrorReport>prompt</ErrorReport> <ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>
<Reference Include="System" /> <Reference Include="System" />
@@ -42,6 +46,10 @@
<Reference Include="System.Data" /> <Reference Include="System.Data" />
<Reference Include="System.Drawing" /> <Reference Include="System.Drawing" />
<Reference Include="System.Xml" /> <Reference Include="System.Xml" />
<Reference Include="Tao.Glfw, Version=2.6.0.0, Culture=neutral, PublicKeyToken=2bb092b6587e4402">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\thirdparty\Tao\Tao.Glfw.dll</HintPath>
</Reference>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<Compile Include="AudLoader.cs" /> <Compile Include="AudLoader.cs" />

View File

@@ -1,4 +1,4 @@
#region Copyright & License Information #region Copyright & License Information
/* /*
* Copyright 2007,2009,2010 Chris Forbes, Robert Pepperell, Matthew Bowra-Dean, Paul Chote, Alli Witheford. * Copyright 2007,2009,2010 Chris Forbes, Robert Pepperell, Matthew Bowra-Dean, Paul Chote, Alli Witheford.
* This file is part of OpenRA. * This file is part of OpenRA.
@@ -19,35 +19,26 @@
#endregion #endregion
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
using Tao.Glfw;
namespace OpenRa.Support namespace OpenRa.Support
{ {
public class Stopwatch public class Stopwatch
{ {
//[DllImport("kernel32.dll")] double start;
static bool QueryPerformanceCounter(out long value) { value = 1; return true; }
//[DllImport("kernel32.dll")]
static bool QueryPerformanceFrequency(out long frequency) { frequency = 1; return true; }
long freq, start;
public Stopwatch() public Stopwatch()
{ {
QueryPerformanceFrequency(out freq); Reset();
QueryPerformanceCounter(out start);
} }
public double ElapsedTime() public double ElapsedTime()
{ {
long current; return (Glfw.glfwGetTime() - start);
QueryPerformanceCounter(out current);
return (current - start) / (double)freq;
} }
public void Reset() public void Reset()
{ {
QueryPerformanceCounter(out start); start = Glfw.glfwGetTime();
} }
} }
} }

View File

@@ -27,6 +27,8 @@ using OpenRa.FileFormats;
using OpenRa.FileFormats.Graphics; using OpenRa.FileFormats.Graphics;
using OpenRa.Support; using OpenRa.Support;
using System.IO; using System.IO;
using ISE;
using Tao.OpenGl;
namespace OpenRa.Graphics namespace OpenRa.Graphics
{ {
@@ -43,11 +45,8 @@ namespace OpenRa.Graphics
public ITexture PaletteTexture; public ITexture PaletteTexture;
readonly Font fDebug, fTitle; readonly FTFontGL regularFont, boldFont;
const int RenderedFontSize = 48;
Sheet textSheet;
SpriteRenderer rgbaRenderer;
Sprite textSprite;
public Size Resolution { get { return device.WindowSize; } } public Size Resolution { get { return device.WindowSize; } }
@@ -60,11 +59,21 @@ namespace OpenRa.Graphics
RgbaSpriteShader = device.CreateShader(FileSystem.Open("shaders/chrome-rgba.fx")); RgbaSpriteShader = device.CreateShader(FileSystem.Open("shaders/chrome-rgba.fx"));
WorldSpriteShader = device.CreateShader(FileSystem.Open("shaders/chrome-shp.fx")); WorldSpriteShader = device.CreateShader(FileSystem.Open("shaders/chrome-shp.fx"));
//fDebug = new Font("Tahoma", 10, FontStyle.Regular); int Errors;
//fTitle = new Font("Tahoma", 10, FontStyle.Bold); regularFont = new FTFontGL("FreeSans.ttf", out Errors);
textSheet = new Sheet(this, new Size(256, 256));
rgbaRenderer = new SpriteRenderer(this, true, RgbaSpriteShader); if (Errors > 0)
textSprite = new Sprite(textSheet, new Rectangle(0, 0, 256, 256), TextureChannel.Alpha); throw new InvalidOperationException("Error(s) loading font");
regularFont.ftRenderToTexture(RenderedFontSize, 192);
regularFont.FT_ALIGN = FTFontAlign.FT_ALIGN_LEFT;
boldFont = new FTFontGL("FreeSansBold.ttf", out Errors);
if (Errors > 0)
throw new InvalidOperationException("Error(s) loading font");
boldFont.ftRenderToTexture(RenderedFontSize, 192);
boldFont.FT_ALIGN = FTFontAlign.FT_ALIGN_LEFT;
} }
IGraphicsDevice CreateDevice( Assembly rendererDll, int width, int height, bool fullscreen, bool vsync ) IGraphicsDevice CreateDevice( Assembly rendererDll, int width, int height, bool fullscreen, bool vsync )
@@ -77,25 +86,6 @@ namespace OpenRa.Graphics
throw new NotImplementedException(); throw new NotImplementedException();
} }
Bitmap RenderTextToBitmap(string s, Font f, Color c)
{
Bitmap b = new Bitmap(256, 256);
using (var g = System.Drawing.Graphics.FromImage(b))
{
g.TextRenderingHint = TextRenderingHint.SingleBitPerPixelGridFit;
g.DrawString(s, f, new SolidBrush(c), 0, 0);
g.Flush();
}
return b;
}
int2 GetTextSize(string s, Font f)
{
Bitmap b = new Bitmap(1,1);
System.Drawing.Graphics g = System.Drawing.Graphics.FromImage(b);
return new int2(g.MeasureString(s, f).ToSize());
}
public IGraphicsDevice Device { get { return device; } } public IGraphicsDevice Device { get { return device; } }
public void BeginFrame(float2 r1, float2 r2, float2 scroll) public void BeginFrame(float2 r1, float2 r2, float2 scroll)
@@ -154,38 +144,61 @@ namespace OpenRa.Graphics
PerfHistory.Increment("batches", 1); PerfHistory.Increment("batches", 1);
} }
public void DrawText(string text, int2 pos, Color c) static void CheckError()
{
var e = Gl.glGetError();
if (e != Gl.GL_NO_ERROR)
throw new InvalidOperationException("GL Error: " + Gl.glGetString(e));
}
const float emHeight = 14f; /* px */
void DrawTextInner(FTFontGL f, string text, int2 pos, Color c)
{ {
return;
using (new PerfSample("text")) using (new PerfSample("text"))
{ {
Bitmap b = RenderTextToBitmap(text, fDebug, c); pos.Y += (int)(emHeight);
textSheet.Texture.SetData(b);
rgbaRenderer.DrawSprite(textSprite, pos.ToFloat2(), "chrome"); Gl.glMatrixMode(Gl.GL_MODELVIEW);
rgbaRenderer.Flush(); Gl.glPushMatrix();
Gl.glLoadIdentity();
Gl.glMatrixMode(Gl.GL_PROJECTION);
Gl.glPushMatrix();
Gl.glLoadIdentity();
Gl.glOrtho(0, Resolution.Width, 0, Resolution.Height, 0, 1);
Gl.glMatrixMode(Gl.GL_MODELVIEW);
Gl.glTranslatef(pos.X, Resolution.Height - pos.Y, 0);
Gl.glScalef(emHeight / RenderedFontSize, emHeight / RenderedFontSize, 1);
f.ftBeginFont(false);
Gl.glColor4f(c.R / 255f, c.G / 255f, c.B / 255f, c.A / 255f);
f.ftWrite(text);
f.ftEndFont();
Gl.glMatrixMode(Gl.GL_PROJECTION);
Gl.glPopMatrix();
Gl.glMatrixMode(Gl.GL_MODELVIEW);
Gl.glPopMatrix();
CheckError();
} }
} }
public void DrawText2(string text, int2 pos, Color c) public void DrawText(string text, int2 pos, Color c) { DrawTextInner(regularFont, text, pos, c); }
{ public void DrawText2(string text, int2 pos, Color c) { DrawTextInner(boldFont, text, pos, c); }
return;
using (new PerfSample("text"))
{
Bitmap b = RenderTextToBitmap(text, fTitle, c);
textSheet.Texture.SetData(b);
rgbaRenderer.DrawSprite(textSprite, pos.ToFloat2(), "chrome");
rgbaRenderer.Flush();
}
}
public int2 MeasureText(string text) public int2 MeasureText(string text)
{ {
return new int2(0,0); //GetTextSize(text, fDebug); return new int2((int)(regularFont.ftExtent(ref text) / 3), (int)emHeight);
} }
public int2 MeasureText2(string text) public int2 MeasureText2(string text)
{ {
return new int2(0,0);// GetTextSize(text, fTitle); return new int2((int)(boldFont.ftExtent(ref text) / 3), (int)emHeight);
} }
} }
} }

View File

@@ -1,7 +1,8 @@
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003" ToolsVersion="3.5"> <?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003" ToolsVersion="3.5">
<PropertyGroup> <PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration> <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform> <Platform Condition=" '$(Platform)' == '' ">x86</Platform>
<ProductVersion>9.0.30729</ProductVersion> <ProductVersion>9.0.30729</ProductVersion>
<SchemaVersion>2.0</SchemaVersion> <SchemaVersion>2.0</SchemaVersion>
<ProjectGuid>{0DFB103F-2962-400F-8C6D-E2C28CCBA633}</ProjectGuid> <ProjectGuid>{0DFB103F-2962-400F-8C6D-E2C28CCBA633}</ProjectGuid>
@@ -30,8 +31,6 @@
<UseApplicationTrust>false</UseApplicationTrust> <UseApplicationTrust>false</UseApplicationTrust>
<BootstrapperEnabled>true</BootstrapperEnabled> <BootstrapperEnabled>true</BootstrapperEnabled>
<TargetFrameworkVersion>v3.5</TargetFrameworkVersion> <TargetFrameworkVersion>v3.5</TargetFrameworkVersion>
<StartupObject>
</StartupObject>
<ApplicationIcon>OpenRA.ico</ApplicationIcon> <ApplicationIcon>OpenRA.ico</ApplicationIcon>
</PropertyGroup> </PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|x86' "> <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|x86' ">
@@ -43,6 +42,8 @@
<PlatformTarget>x86</PlatformTarget> <PlatformTarget>x86</PlatformTarget>
<UseVSHostingProcess>false</UseVSHostingProcess> <UseVSHostingProcess>false</UseVSHostingProcess>
<ErrorReport>prompt</ErrorReport> <ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<Optimize>false</Optimize>
</PropertyGroup> </PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|x86' "> <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|x86' ">
<OutputPath>bin\Release\</OutputPath> <OutputPath>bin\Release\</OutputPath>
@@ -53,6 +54,7 @@
<PlatformTarget>x86</PlatformTarget> <PlatformTarget>x86</PlatformTarget>
<UseVSHostingProcess>false</UseVSHostingProcess> <UseVSHostingProcess>false</UseVSHostingProcess>
<ErrorReport>prompt</ErrorReport> <ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>
<Reference Include="System" /> <Reference Include="System" />
@@ -64,6 +66,14 @@
<Reference Include="System.Windows.Forms" /> <Reference Include="System.Windows.Forms" />
<Reference Include="System.Xml" /> <Reference Include="System.Xml" />
<Reference Include="Tao.OpenAl, Version=1.1.0.1, Culture=neutral, PublicKeyToken=a7579dda88828311, processorArchitecture=MSIL" /> <Reference Include="Tao.OpenAl, Version=1.1.0.1, Culture=neutral, PublicKeyToken=a7579dda88828311, processorArchitecture=MSIL" />
<Reference Include="Tao.OpenGl, Version=2.1.0.12, Culture=neutral, PublicKeyToken=1ca010269a4501ef">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\thirdparty\Tao\Tao.OpenGl.dll</HintPath>
</Reference>
<Reference Include="ISE.FreeType, Version=1.0.0.0, Culture=neutral, PublicKeyToken=1b34ab585684d5ea">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\thirdparty\ISE.FreeType.dll</HintPath>
</Reference>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<Compile Include="Chat.cs" /> <Compile Include="Chat.cs" />

BIN
thirdparty/ISE.FreeType.dll vendored Executable file

Binary file not shown.

7
thirdparty/ISE.FreeType.dll.config vendored Normal file
View File

@@ -0,0 +1,7 @@
<configuration>
<dllmap dll="freetype6.dll">
<dllentry os="linux" dll="libfreetype.so.6" />
<dllentry os="windows" dll="freetype6.dll" />
<dllentry os="osx" dll="/sw/lib/libfreetype.dylib" />
</dllmap>
</configuration>

BIN
thirdparty/Tao.Externals.dll vendored Executable file

Binary file not shown.

12
thirdparty/Tao.Externals.dll.config vendored Normal file
View File

@@ -0,0 +1,12 @@
<configuration>
<dllmap dll="freetype6.dll">
<dllentry os="linux" dll="libfreetype.so.6" />
<dllentry os="windows" dll="freetype6.dll" />
<dllentry os="osx" dll="/sw/lib/libfreetype.dylib" />
</dllmap>
</configuration>
<dllmap dll="OpenAL32.dll">
<dllentry os="linux" dll="libopenal.so.1" />
<dllentry os="windows" dll="OpenAL32.dll" />
<dllentry os="osx" dll="/System/Library/Frameworks/OpenAL.framework/OpenAL" />
</dllmap>

BIN
thirdparty/Tao/Tao.FreeType.dll vendored Executable file

Binary file not shown.

View File

@@ -0,0 +1,7 @@
<configuration>
<dllmap dll="freetype6.dll">
<dllentry os="linux" dll="libfreetype.so.6" />
<dllentry os="windows" dll="freetype6.dll" />
<dllentry os="osx" dll="/sw/lib/libfreetype.dylib" />
</dllmap>
</configuration>