diff --git a/FreeSans.ttf b/FreeSans.ttf new file mode 100755 index 0000000000..9d51347052 Binary files /dev/null and b/FreeSans.ttf differ diff --git a/FreeSansBold.ttf b/FreeSansBold.ttf new file mode 100644 index 0000000000..029000eb95 Binary files /dev/null and b/FreeSansBold.ttf differ diff --git a/Makefile b/Makefile index e5f4ea4848..6c968599c7 100644 --- a/Makefile +++ b/Makefile @@ -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_TARGET = OpenRa.FileFormats.dll 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_TARGET = OpenRa.Gl.dll @@ -16,7 +16,7 @@ gl_KIND = library gl_DEPS = $(fileformats_TARGET) $(game_TARGET) \ thirdparty/Tao/Tao.Glfw.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) game_SRCS = $(shell find OpenRa.Game/ -iname '*.cs') @@ -24,7 +24,7 @@ game_TARGET = OpenRa.Game.exe game_KIND = winexe game_DEPS = $(fileformats_TARGET) 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 ra_SRCS = $(shell find OpenRa.Mods.RA/ -iname '*.cs') diff --git a/OpenRa.FileFormats/OpenRa.FileFormats.csproj b/OpenRa.FileFormats/OpenRa.FileFormats.csproj index 0408851752..4df27feeff 100644 --- a/OpenRa.FileFormats/OpenRa.FileFormats.csproj +++ b/OpenRa.FileFormats/OpenRa.FileFormats.csproj @@ -1,4 +1,5 @@ - + + Debug AnyCPU @@ -24,6 +25,8 @@ full AnyCPU prompt + 4 + false bin\Release\ @@ -33,6 +36,7 @@ pdbonly AnyCPU prompt + 4 @@ -42,6 +46,10 @@ + + False + ..\thirdparty\Tao\Tao.Glfw.dll + diff --git a/OpenRa.FileFormats/Support/Stopwatch.cs b/OpenRa.FileFormats/Support/Stopwatch.cs index a8a5ae84f5..1b23824b88 100755 --- a/OpenRa.FileFormats/Support/Stopwatch.cs +++ b/OpenRa.FileFormats/Support/Stopwatch.cs @@ -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. * This file is part of OpenRA. @@ -19,35 +19,26 @@ #endregion using System.Runtime.InteropServices; +using Tao.Glfw; namespace OpenRa.Support { public class Stopwatch { - //[DllImport("kernel32.dll")] - 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; - + double start; public Stopwatch() { - QueryPerformanceFrequency(out freq); - QueryPerformanceCounter(out start); + Reset(); } public double ElapsedTime() { - long current; - QueryPerformanceCounter(out current); - - return (current - start) / (double)freq; + return (Glfw.glfwGetTime() - start); } public void Reset() { - QueryPerformanceCounter(out start); + start = Glfw.glfwGetTime(); } } } diff --git a/OpenRa.Game/Graphics/Renderer.cs b/OpenRa.Game/Graphics/Renderer.cs index 4774abe858..827e35cfbb 100644 --- a/OpenRa.Game/Graphics/Renderer.cs +++ b/OpenRa.Game/Graphics/Renderer.cs @@ -27,6 +27,8 @@ using OpenRa.FileFormats; using OpenRa.FileFormats.Graphics; using OpenRa.Support; using System.IO; +using ISE; +using Tao.OpenGl; namespace OpenRa.Graphics { @@ -43,11 +45,8 @@ namespace OpenRa.Graphics public ITexture PaletteTexture; - readonly Font fDebug, fTitle; - - Sheet textSheet; - SpriteRenderer rgbaRenderer; - Sprite textSprite; + readonly FTFontGL regularFont, boldFont; + const int RenderedFontSize = 48; public Size Resolution { get { return device.WindowSize; } } @@ -60,11 +59,21 @@ namespace OpenRa.Graphics RgbaSpriteShader = device.CreateShader(FileSystem.Open("shaders/chrome-rgba.fx")); WorldSpriteShader = device.CreateShader(FileSystem.Open("shaders/chrome-shp.fx")); - //fDebug = new Font("Tahoma", 10, FontStyle.Regular); - //fTitle = new Font("Tahoma", 10, FontStyle.Bold); - textSheet = new Sheet(this, new Size(256, 256)); - rgbaRenderer = new SpriteRenderer(this, true, RgbaSpriteShader); - textSprite = new Sprite(textSheet, new Rectangle(0, 0, 256, 256), TextureChannel.Alpha); + int Errors; + regularFont = new FTFontGL("FreeSans.ttf", out Errors); + + if (Errors > 0) + 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 ) @@ -77,25 +86,6 @@ namespace OpenRa.Graphics 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 void BeginFrame(float2 r1, float2 r2, float2 scroll) @@ -154,38 +144,61 @@ namespace OpenRa.Graphics PerfHistory.Increment("batches", 1); } - public void DrawText(string text, int2 pos, Color c) - { - return; - using (new PerfSample("text")) + 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) + { + using (new PerfSample("text")) { - Bitmap b = RenderTextToBitmap(text, fDebug, c); - textSheet.Texture.SetData(b); - rgbaRenderer.DrawSprite(textSprite, pos.ToFloat2(), "chrome"); - rgbaRenderer.Flush(); + pos.Y += (int)(emHeight); + + Gl.glMatrixMode(Gl.GL_MODELVIEW); + 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) - { - return; - using (new PerfSample("text")) - { - Bitmap b = RenderTextToBitmap(text, fTitle, c); - textSheet.Texture.SetData(b); - rgbaRenderer.DrawSprite(textSprite, pos.ToFloat2(), "chrome"); - rgbaRenderer.Flush(); - } - } + 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); } 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) { - return new int2(0,0);// GetTextSize(text, fTitle); + return new int2((int)(boldFont.ftExtent(ref text) / 3), (int)emHeight); } } } diff --git a/OpenRa.Game/OpenRa.Game.csproj b/OpenRa.Game/OpenRa.Game.csproj index f2f2ab62d5..2f12f4c531 100644 --- a/OpenRa.Game/OpenRa.Game.csproj +++ b/OpenRa.Game/OpenRa.Game.csproj @@ -1,7 +1,8 @@ - + + Debug - AnyCPU + x86 9.0.30729 2.0 {0DFB103F-2962-400F-8C6D-E2C28CCBA633} @@ -30,8 +31,6 @@ false true v3.5 - - OpenRA.ico @@ -43,6 +42,8 @@ x86 false prompt + 4 + false bin\Release\ @@ -53,6 +54,7 @@ x86 false prompt + 4 @@ -64,6 +66,14 @@ + + False + ..\thirdparty\Tao\Tao.OpenGl.dll + + + False + ..\thirdparty\ISE.FreeType.dll + diff --git a/thirdparty/ISE.FreeType.dll b/thirdparty/ISE.FreeType.dll new file mode 100755 index 0000000000..7a7b7a7587 Binary files /dev/null and b/thirdparty/ISE.FreeType.dll differ diff --git a/thirdparty/ISE.FreeType.dll.config b/thirdparty/ISE.FreeType.dll.config new file mode 100644 index 0000000000..2512bdc4a0 --- /dev/null +++ b/thirdparty/ISE.FreeType.dll.config @@ -0,0 +1,7 @@ + + + + + + + \ No newline at end of file diff --git a/thirdparty/Tao.Externals.dll b/thirdparty/Tao.Externals.dll new file mode 100755 index 0000000000..81ecf2e1aa Binary files /dev/null and b/thirdparty/Tao.Externals.dll differ diff --git a/thirdparty/Tao.Externals.dll.config b/thirdparty/Tao.Externals.dll.config new file mode 100644 index 0000000000..b6745059fe --- /dev/null +++ b/thirdparty/Tao.Externals.dll.config @@ -0,0 +1,12 @@ + + + + + + + + + + + + \ No newline at end of file diff --git a/thirdparty/Tao/Tao.FreeType.dll b/thirdparty/Tao/Tao.FreeType.dll new file mode 100755 index 0000000000..15ccb306d2 Binary files /dev/null and b/thirdparty/Tao/Tao.FreeType.dll differ diff --git a/thirdparty/Tao/Tao.FreeType.dll.config b/thirdparty/Tao/Tao.FreeType.dll.config new file mode 100644 index 0000000000..f16cbf2616 --- /dev/null +++ b/thirdparty/Tao/Tao.FreeType.dll.config @@ -0,0 +1,7 @@ + + + + + + +