merged beedee's text renderer. shows up some texel-offset issues
This commit is contained in:
@@ -3,6 +3,7 @@ using System.Windows.Forms;
|
|||||||
using OpenRa.GlRenderer;
|
using OpenRa.GlRenderer;
|
||||||
using OpenRa.FileFormats;
|
using OpenRa.FileFormats;
|
||||||
using OpenRa.Support;
|
using OpenRa.Support;
|
||||||
|
using System.Drawing.Drawing2D;
|
||||||
|
|
||||||
namespace OpenRa.Graphics
|
namespace OpenRa.Graphics
|
||||||
{
|
{
|
||||||
@@ -19,8 +20,11 @@ namespace OpenRa.Graphics
|
|||||||
|
|
||||||
public Texture PaletteTexture;
|
public Texture PaletteTexture;
|
||||||
|
|
||||||
//readonly SpriteHelper sh;
|
readonly Font fDebug, fTitle;
|
||||||
//readonly FontHelper fhDebug, fhTitle;
|
|
||||||
|
Sheet textSheet;
|
||||||
|
SpriteRenderer rgbaRenderer;
|
||||||
|
Sprite textSprite;
|
||||||
|
|
||||||
public Renderer(Control control, Size resolution, bool windowed)
|
public Renderer(Control control, Size resolution, bool windowed)
|
||||||
{
|
{
|
||||||
@@ -36,9 +40,28 @@ namespace OpenRa.Graphics
|
|||||||
WorldSpriteShader = new Shader(device, FileSystem.Open("chrome-shp.fx"));
|
WorldSpriteShader = new Shader(device, FileSystem.Open("chrome-shp.fx"));
|
||||||
WorldSpriteShader.Quality = ShaderQuality.High;
|
WorldSpriteShader.Quality = ShaderQuality.High;
|
||||||
|
|
||||||
//sh = new SpriteHelper(device);
|
fDebug = new Font("Tahoma", 10, FontStyle.Regular);
|
||||||
//fhDebug = new FontHelper(device, "Tahoma", 10, false);
|
fTitle = new Font("Tahoma", 10, FontStyle.Bold);
|
||||||
//fhTitle = new FontHelper(device, "Tahoma", 10, true);
|
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);
|
||||||
|
}
|
||||||
|
|
||||||
|
Bitmap RenderTextToBitmap(string s, Font f, Color c)
|
||||||
|
{
|
||||||
|
Bitmap b = new Bitmap(256, 256);
|
||||||
|
System.Drawing.Graphics g = System.Drawing.Graphics.FromImage(b);
|
||||||
|
g.DrawString(s, f, new SolidBrush(c), 0, 0);
|
||||||
|
g.Flush();
|
||||||
|
g.Dispose();
|
||||||
|
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 GraphicsDevice Device { get { return device; } }
|
public GraphicsDevice Device { get { return device; } }
|
||||||
@@ -101,26 +124,28 @@ namespace OpenRa.Graphics
|
|||||||
|
|
||||||
public void DrawText(string text, int2 pos, Color c)
|
public void DrawText(string text, int2 pos, Color c)
|
||||||
{
|
{
|
||||||
//sh.Begin();
|
Bitmap b = RenderTextToBitmap(text, fDebug, c);
|
||||||
//fhDebug.Draw(sh, text, pos.X, pos.Y, c.ToArgb());
|
textSheet.Texture.SetData(b);
|
||||||
//sh.End();
|
rgbaRenderer.DrawSprite(textSprite, pos.ToFloat2(), "chrome");
|
||||||
|
rgbaRenderer.Flush();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void DrawText2(string text, int2 pos, Color c)
|
public void DrawText2(string text, int2 pos, Color c)
|
||||||
{
|
{
|
||||||
//sh.Begin();
|
Bitmap b = RenderTextToBitmap(text, fTitle, c);
|
||||||
//fhTitle.Draw(sh, text, pos.X, pos.Y, c.ToArgb());
|
textSheet.Texture.SetData(b);
|
||||||
//sh.End();
|
rgbaRenderer.DrawSprite(textSprite, pos.ToFloat2(), "chrome");
|
||||||
|
rgbaRenderer.Flush();
|
||||||
}
|
}
|
||||||
|
|
||||||
public int2 MeasureText(string text)
|
public int2 MeasureText(string text)
|
||||||
{
|
{
|
||||||
return new int2(20,20);//fhDebug.MeasureText(sh, text));
|
return GetTextSize(text, fDebug);
|
||||||
}
|
}
|
||||||
|
|
||||||
public int2 MeasureText2(string text)
|
public int2 MeasureText2(string text)
|
||||||
{
|
{
|
||||||
return new int2(20,20);//fhTitle.MeasureText(sh, text));
|
return GetTextSize(text, fTitle);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -34,7 +34,7 @@
|
|||||||
</StartupObject>
|
</StartupObject>
|
||||||
<ApplicationIcon>OpenRA.ico</ApplicationIcon>
|
<ApplicationIcon>OpenRA.ico</ApplicationIcon>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
|
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|x86' ">
|
||||||
<DebugSymbols>true</DebugSymbols>
|
<DebugSymbols>true</DebugSymbols>
|
||||||
<OutputPath>bin\Debug\</OutputPath>
|
<OutputPath>bin\Debug\</OutputPath>
|
||||||
<DefineConstants>TRACE;DEBUG;SANITY_CHECKS</DefineConstants>
|
<DefineConstants>TRACE;DEBUG;SANITY_CHECKS</DefineConstants>
|
||||||
@@ -44,13 +44,13 @@
|
|||||||
<UseVSHostingProcess>false</UseVSHostingProcess>
|
<UseVSHostingProcess>false</UseVSHostingProcess>
|
||||||
<ErrorReport>prompt</ErrorReport>
|
<ErrorReport>prompt</ErrorReport>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
|
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|x86' ">
|
||||||
<OutputPath>bin\Release\</OutputPath>
|
<OutputPath>bin\Release\</OutputPath>
|
||||||
<DefineConstants>TRACE</DefineConstants>
|
<DefineConstants>TRACE</DefineConstants>
|
||||||
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
|
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
|
||||||
<Optimize>true</Optimize>
|
<Optimize>true</Optimize>
|
||||||
<DebugType>pdbonly</DebugType>
|
<DebugType>pdbonly</DebugType>
|
||||||
<PlatformTarget>AnyCPU</PlatformTarget>
|
<PlatformTarget>x86</PlatformTarget>
|
||||||
<UseVSHostingProcess>false</UseVSHostingProcess>
|
<UseVSHostingProcess>false</UseVSHostingProcess>
|
||||||
<ErrorReport>prompt</ErrorReport>
|
<ErrorReport>prompt</ErrorReport>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|||||||
@@ -27,10 +27,9 @@ Global
|
|||||||
{BDAEAB25-991E-46A7-AF1E-4F0E03358DAA}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
{BDAEAB25-991E-46A7-AF1E-4F0E03358DAA}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||||
{BDAEAB25-991E-46A7-AF1E-4F0E03358DAA}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
{BDAEAB25-991E-46A7-AF1E-4F0E03358DAA}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||||
{BDAEAB25-991E-46A7-AF1E-4F0E03358DAA}.Release|Any CPU.Build.0 = Release|Any CPU
|
{BDAEAB25-991E-46A7-AF1E-4F0E03358DAA}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||||
{0DFB103F-2962-400F-8C6D-E2C28CCBA633}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
{0DFB103F-2962-400F-8C6D-E2C28CCBA633}.Debug|Any CPU.ActiveCfg = Debug|x86
|
||||||
{0DFB103F-2962-400F-8C6D-E2C28CCBA633}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
{0DFB103F-2962-400F-8C6D-E2C28CCBA633}.Debug|Any CPU.Build.0 = Debug|x86
|
||||||
{0DFB103F-2962-400F-8C6D-E2C28CCBA633}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
{0DFB103F-2962-400F-8C6D-E2C28CCBA633}.Release|Any CPU.ActiveCfg = Release|x86
|
||||||
{0DFB103F-2962-400F-8C6D-E2C28CCBA633}.Release|Any CPU.Build.0 = Release|Any CPU
|
|
||||||
{230F65CE-A6DE-4235-8B38-13A3D606C7F7}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
{230F65CE-A6DE-4235-8B38-13A3D606C7F7}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||||
{230F65CE-A6DE-4235-8B38-13A3D606C7F7}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
{230F65CE-A6DE-4235-8B38-13A3D606C7F7}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||||
{230F65CE-A6DE-4235-8B38-13A3D606C7F7}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
{230F65CE-A6DE-4235-8B38-13A3D606C7F7}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||||
|
|||||||
Reference in New Issue
Block a user