mirror of
https://github.com/Ryujinx/Opentk.git
synced 2025-01-23 04:11:01 +00:00
Initial work on new interface.
Use subpixel antialiasing.
This commit is contained in:
parent
a5c733774a
commit
baf3247afe
|
@ -237,7 +237,7 @@ namespace Examples.Tutorial
|
|||
GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit);
|
||||
|
||||
text.Begin();
|
||||
text.Print((1.0 / e.Time).ToString("F2"), sans);
|
||||
text.Print((1.0 / e.Time).ToString("F2"), sans, Color.White);
|
||||
text.End();
|
||||
|
||||
GL.PushMatrix();
|
||||
|
|
|
@ -289,8 +289,7 @@ namespace Examples.Tutorial
|
|||
// Then, render the fps:
|
||||
GL.UseProgram(0);
|
||||
printer.Begin();
|
||||
GL.Color3(Color.PaleGoldenrod);
|
||||
printer.Print((1 / e.Time).ToString("F2"), font, TextPrinterOptions.NoCache);
|
||||
printer.Print((1 / e.Time).ToString("F2"), font, Color.PaleGoldenrod, RectangleF .Empty, TextPrinterOptions.NoCache);
|
||||
printer.End();
|
||||
|
||||
SwapBuffers();
|
||||
|
|
|
@ -118,13 +118,12 @@ namespace Examples.Tests
|
|||
|
||||
printer.Begin();
|
||||
|
||||
printer.Print("Instructions:", font); GL.Translate(0, font.Height, 0);
|
||||
printer.Print(String.Format("1 - cycle through window styles (current: {0}).", this.WindowState), font);
|
||||
GL.Translate(0, font.Height, 0);
|
||||
printer.Print(String.Format("2 - cycle through window borders (current: {0}).", this.WindowBorder), font);
|
||||
printer.Print("Instructions:", font, Color.White);
|
||||
printer.Print(String.Format("1 - cycle through window styles (current: {0}).", this.WindowState), font, Color.White, new RectangleF(0, font.Height, 0, 0));
|
||||
printer.Print(String.Format("2 - cycle through window borders (current: {0}).", this.WindowBorder), font, Color.White, new RectangleF(0, 2 * font.Height, 0, 0));
|
||||
GL.Translate(0, font.Height, 0);
|
||||
printer.Print(String.Format("3 - toggle fullscreen (current: {0}).",
|
||||
this.WindowState == WindowState.Fullscreen ? "enabled" : "disabled"), font);
|
||||
this.WindowState == WindowState.Fullscreen ? "enabled" : "disabled"), font, Color.White, new RectangleF(0, 2 * font.Height, 0, 0));
|
||||
|
||||
|
||||
printer.End();
|
||||
|
|
|
@ -162,7 +162,7 @@ namespace Examples.Tutorial
|
|||
// Print using the first font.
|
||||
for (int i = 0; i < fonts.Length / 2; i++)
|
||||
{
|
||||
printer.Print(text, fonts[i]);
|
||||
printer.Print(text, fonts[i], Color.White);
|
||||
GL.Translate(0, fonts[i].Height, 0);
|
||||
}
|
||||
|
||||
|
@ -174,7 +174,7 @@ namespace Examples.Tutorial
|
|||
GL.Translate(rect.Width + 32.0f, 0, 0);
|
||||
for (int i = fonts.Length / 2; i < fonts.Length; i++)
|
||||
{
|
||||
printer.Print(text, fonts[i]);
|
||||
printer.Print(text, fonts[i], Color.White);
|
||||
GL.Translate(0, fonts[i].Height, 0);
|
||||
}
|
||||
|
||||
|
|
|
@ -129,13 +129,10 @@ namespace Examples.Tutorial
|
|||
|
||||
// Print FPS counter. Since the counter changes per frame,
|
||||
// it shouldn't be cached (TextPrinterOptions.NoCache).
|
||||
GL.Color3(Color.LightYellow);
|
||||
text.Print((1.0 / e.Time).ToString("F2"), sans, TextPrinterOptions.NoCache);
|
||||
text.Print((1.0 / e.Time).ToString("F2"), sans, Color.LightYellow, RectangleF.Empty, TextPrinterOptions.NoCache);
|
||||
|
||||
// Print the actual text.
|
||||
GL.Translate(0.0f, current_position, 0.0f);
|
||||
GL.Color3(Color.White);
|
||||
text.Print(poem, serif);
|
||||
text.Print(poem, serif, Color.White, new RectangleF(0, current_position, 0, 0), TextPrinterOptions.Default);
|
||||
|
||||
text.End();
|
||||
|
||||
|
|
|
@ -62,6 +62,8 @@
|
|||
//
|
||||
// textBox1
|
||||
//
|
||||
this.textBox1.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
|
||||
| System.Windows.Forms.AnchorStyles.Right)));
|
||||
this.textBox1.Location = new System.Drawing.Point(12, 11);
|
||||
this.textBox1.Name = "textBox1";
|
||||
this.textBox1.Size = new System.Drawing.Size(550, 22);
|
||||
|
|
|
@ -14,7 +14,7 @@ namespace Examples.WinForms
|
|||
{
|
||||
#region Fields
|
||||
|
||||
float[] sizes = new float[] { 8, 9, 10, 11, 12, 13, 14, 16, 18, 20, 22, 24, 26, 28, 32, 36, 48 };
|
||||
float[] sizes = new float[] { 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 20, 22, 24, 28, 32, 36, 42, 48 };
|
||||
List<Font> fonts = new List<Font>();
|
||||
|
||||
TextPrinter text = new TextPrinter();
|
||||
|
@ -70,15 +70,18 @@ namespace Examples.WinForms
|
|||
|
||||
private void glControl1_Paint(object sender, PaintEventArgs e)
|
||||
{
|
||||
GL.ClearColor(Color.Red);
|
||||
glControl1.MakeCurrent();
|
||||
//GL.ClearColor(Color.Gainsboro);
|
||||
GL.Clear(ClearBufferMask.ColorBufferBit);
|
||||
GL.Color3(Color.White);
|
||||
//GL.Color4(Color.Blue);
|
||||
//GL.BlendColor(0, 0, 0, 0);
|
||||
|
||||
text.Begin();
|
||||
|
||||
foreach (Font font in fonts)
|
||||
{
|
||||
text.Print(textBox1.Text, font);
|
||||
text.Print(textBox1.Text, font, Color.White);
|
||||
GL.Translate(0, font.Height, 0);
|
||||
}
|
||||
|
||||
|
|
|
@ -59,6 +59,8 @@ namespace Examples.WinForms
|
|||
|
||||
private void glControl1_Paint(object sender, PaintEventArgs e)
|
||||
{
|
||||
glControl1.MakeCurrent();
|
||||
|
||||
GL.Clear(ClearBufferMask.ColorBufferBit);
|
||||
glControl1.SwapBuffers();
|
||||
}
|
||||
|
|
|
@ -38,10 +38,6 @@ namespace OpenTK.Graphics
|
|||
/// </summary>
|
||||
class AlphaTexture2D : Texture2D
|
||||
{
|
||||
#region Fields
|
||||
|
||||
#endregion
|
||||
|
||||
#region Constructors
|
||||
|
||||
/// <summary>
|
||||
|
@ -53,10 +49,6 @@ namespace OpenTK.Graphics
|
|||
|
||||
#endregion
|
||||
|
||||
#region Public Members
|
||||
|
||||
#endregion
|
||||
|
||||
#region Protected Members
|
||||
|
||||
protected override PixelInternalFormat InternalFormat
|
||||
|
|
|
@ -19,12 +19,12 @@ namespace OpenTK.Graphics
|
|||
{
|
||||
void Begin();
|
||||
void End();
|
||||
void Print(string text, Font font);
|
||||
void Print(string text, Font font, TextPrinterOptions options);
|
||||
void Print(string text, Font font, TextPrinterOptions options, RectangleF layoutRectangle);
|
||||
void Print(string text, Font font, Color color);
|
||||
void Print(string text, Font font, Color color, RectangleF layoutRectangle);
|
||||
void Print(string text, Font font, Color color, RectangleF layoutRectangle, TextPrinterOptions options);
|
||||
TextExtents Measure(string text, Font font);
|
||||
TextExtents Measure(string text, Font font, TextPrinterOptions options);
|
||||
TextExtents Measure(string text, Font font, TextPrinterOptions options, RectangleF layoutRectangle);
|
||||
TextExtents Measure(string text, Font font, RectangleF layoutRectangle);
|
||||
TextExtents Measure(string text, Font font, RectangleF layoutRectangle, TextPrinterOptions options);
|
||||
|
||||
[Obsolete("Use TextPrinter.Print instead")]
|
||||
void Draw(TextHandle handle);
|
||||
|
|
18
Source/Utilities/Graphics/RgbaTexture2D.cs
Normal file
18
Source/Utilities/Graphics/RgbaTexture2D.cs
Normal file
|
@ -0,0 +1,18 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace OpenTK.Graphics
|
||||
{
|
||||
class RgbaTexture2D : Texture2D
|
||||
{
|
||||
public RgbaTexture2D(int width, int height)
|
||||
: base(width, height)
|
||||
{ }
|
||||
|
||||
protected override PixelInternalFormat InternalFormat
|
||||
{
|
||||
get { return PixelInternalFormat.CompressedRgba; }
|
||||
}
|
||||
}
|
||||
}
|
|
@ -55,9 +55,9 @@ namespace OpenTK.Graphics.Text
|
|||
|
||||
#region ITextOutputProvider Members
|
||||
|
||||
public void Print(TextBlock block, IGlyphRasterizer rasterizer, GlyphCache cache)
|
||||
public void Print(TextBlock block, PointF location, Color color, IGlyphRasterizer rasterizer, GlyphCache cache)
|
||||
{
|
||||
using (TextExtents extents = rasterizer.MeasureText(block))
|
||||
using (TextExtents extents = rasterizer.MeasureText(block, location))
|
||||
{
|
||||
//GL.BindTexture(TextureTarget.Texture2D, 2);
|
||||
|
||||
|
|
|
@ -79,7 +79,11 @@ namespace OpenTK.Graphics.Text
|
|||
|
||||
public Bitmap Rasterize(Glyph glyph)
|
||||
{
|
||||
RectangleF r = MeasureText(new TextBlock(glyph.Character.ToString(), glyph.Font, TextPrinterOptions.NoCache, RectangleF.Empty)).BoundingBox;
|
||||
RectangleF r = MeasureText(
|
||||
new TextBlock(
|
||||
glyph.Character.ToString(), glyph.Font,
|
||||
TextPrinterOptions.NoCache, SizeF.Empty),
|
||||
PointF.Empty).BoundingBox;
|
||||
|
||||
EnsureSurfaceSize(ref glyph_surface, ref glyph_renderer, glyph.Font);
|
||||
|
||||
|
@ -102,9 +106,15 @@ namespace OpenTK.Graphics.Text
|
|||
{
|
||||
SetTextRenderingOptions(gfx, glyph.Font);
|
||||
|
||||
gfx.Clear(Color.Transparent);
|
||||
gfx.DrawString(glyph.Character.ToString(), glyph.Font, Brushes.White, PointF.Empty,
|
||||
glyph.Font.Style == FontStyle.Italic ? load_glyph_string_format : default_string_format);
|
||||
//gfx.Clear(Color.Transparent);
|
||||
//gfx.Clear(Color.FromArgb(255, 0, 0, 0));
|
||||
//gfx.DrawString(glyph.Character.ToString(), glyph.Font, Brushes.White, PointF.Empty,
|
||||
// glyph.Font.Style & FontStyle.Italic != 0 ? load_glyph_string_format : default_string_format);
|
||||
System.Windows.Forms.TextRenderer.DrawText(gfx, glyph.Character.ToString(), glyph.Font, Point.Empty, Color.White);
|
||||
//,
|
||||
// (glyph.Font.Style & FontStyle.Italic) != 0 ?
|
||||
// System.Windows.Forms.TextFormatFlags.GlyphOverhangPadding :
|
||||
// System.Windows.Forms.TextFormatFlags.Default);
|
||||
rect = FindEdges(bmp);
|
||||
}
|
||||
}
|
||||
|
@ -113,7 +123,7 @@ namespace OpenTK.Graphics.Text
|
|||
|
||||
#region MeasureText
|
||||
|
||||
public TextExtents MeasureText(TextBlock block)
|
||||
public TextExtents MeasureText(TextBlock block, PointF location)
|
||||
{
|
||||
// First, check if we have cached this text block. Do not use block_cache.TryGetValue, to avoid thrashing
|
||||
// the user's TextBlockExtents struct.
|
||||
|
@ -121,7 +131,8 @@ namespace OpenTK.Graphics.Text
|
|||
return block_cache[block];
|
||||
|
||||
// If this block is not cached, we have to measure it and (potentially) place it in the cache.
|
||||
TextExtents extents = MeasureTextExtents(block);
|
||||
TextExtents extents = MeasureTextExtents(block, location);
|
||||
|
||||
if ((block.Options & TextPrinterOptions.NoCache) == 0)
|
||||
block_cache.Add(block, extents);
|
||||
|
||||
|
@ -158,29 +169,25 @@ namespace OpenTK.Graphics.Text
|
|||
void SetTextRenderingOptions(System.Drawing.Graphics gfx, Font font)
|
||||
{
|
||||
// Small sizes look blurry without gridfitting, so turn that on.
|
||||
if (font.Size <= 18.0f)
|
||||
gfx.TextRenderingHint = TextRenderingHint.AntiAliasGridFit;
|
||||
else
|
||||
gfx.TextRenderingHint = TextRenderingHint.AntiAlias;
|
||||
//if (font.Size <= 18.0f)
|
||||
// gfx.TextRenderingHint = TextRenderingHint.ClearTypeGridFit;
|
||||
//else
|
||||
gfx.TextRenderingHint = TextRenderingHint.ClearTypeGridFit;
|
||||
//gfx.TextRenderingHint = TextRenderingHint.AntiAliasGridFit;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region MeasureTextExtents
|
||||
|
||||
TextExtents MeasureTextExtents(TextBlock block)
|
||||
TextExtents MeasureTextExtents(TextBlock block, PointF location)
|
||||
{
|
||||
// Todo: Parse layout options:
|
||||
StringFormat format = default_string_format;
|
||||
//if (block.Font.Style != FontStyle.Regular)
|
||||
// format = load_glyph_string_format;
|
||||
//else
|
||||
// format = default_string_format;
|
||||
|
||||
TextExtents extents = text_extents_pool.Acquire();
|
||||
|
||||
PointF origin = PointF.Empty;
|
||||
SizeF size = SizeF.Empty;
|
||||
RectangleF rect = new RectangleF(location, block.Bounds);
|
||||
|
||||
SetTextRenderingOptions(graphics, block.Font);
|
||||
|
||||
|
@ -203,7 +210,7 @@ namespace OpenTK.Graphics.Text
|
|||
{
|
||||
extents.AddRange(MeasureGlyphExtents(
|
||||
s, height, 0, s.Length,
|
||||
block.LayoutRectangle,
|
||||
rect,
|
||||
native_graphics, native_font, native_string_format));
|
||||
height += block.Font.Height;
|
||||
}
|
||||
|
|
|
@ -36,27 +36,25 @@ namespace OpenTK.Graphics.Text
|
|||
{
|
||||
#region Fields
|
||||
|
||||
AlphaTexture2D texture;
|
||||
GlyphPacker packer;
|
||||
//AlphaTexture2D texture;
|
||||
RgbaTexture2D texture = new RgbaTexture2D(512, 512);
|
||||
GlyphPacker packer = new GlyphPacker(512, 512);
|
||||
|
||||
#endregion
|
||||
|
||||
#region Constructors
|
||||
|
||||
public GlyphSheet()
|
||||
{
|
||||
Texture = new AlphaTexture2D(256, 256);
|
||||
Packer = new GlyphPacker(256, 256);
|
||||
}
|
||||
{ }
|
||||
|
||||
#endregion
|
||||
|
||||
#region Public Members
|
||||
|
||||
public AlphaTexture2D Texture
|
||||
public Texture2D Texture
|
||||
{
|
||||
get { return texture; }
|
||||
private set { texture = value; }
|
||||
private set { texture = (RgbaTexture2D)value; }
|
||||
}
|
||||
|
||||
public GlyphPacker Packer
|
||||
|
|
|
@ -37,7 +37,7 @@ namespace OpenTK.Graphics.Text
|
|||
interface IGlyphRasterizer
|
||||
{
|
||||
Bitmap Rasterize(Glyph glyph);
|
||||
TextExtents MeasureText(TextBlock block);
|
||||
TextExtents MeasureText(TextBlock block, PointF location);
|
||||
void Rasterize(Glyph glyph, ref Bitmap bmp, out Rectangle rect);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -28,11 +28,12 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using System.Drawing;
|
||||
|
||||
namespace OpenTK.Graphics.Text
|
||||
{
|
||||
interface ITextOutputProvider
|
||||
{
|
||||
void Print(TextBlock block, IGlyphRasterizer rasterizer, GlyphCache cache);
|
||||
void Print(TextBlock block, PointF location, Color color, IGlyphRasterizer rasterizer, GlyphCache cache);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -41,7 +41,7 @@ namespace OpenTK.Graphics.Text
|
|||
|
||||
public readonly Font Font;
|
||||
|
||||
public readonly RectangleF LayoutRectangle;
|
||||
public readonly SizeF Bounds;
|
||||
|
||||
public readonly TextPrinterOptions Options;
|
||||
|
||||
|
@ -51,11 +51,11 @@ namespace OpenTK.Graphics.Text
|
|||
|
||||
#region Constructors
|
||||
|
||||
public TextBlock(string text, Font font, TextPrinterOptions options, RectangleF layoutRectangle)
|
||||
public TextBlock(string text, Font font, TextPrinterOptions options, SizeF bounds)
|
||||
{
|
||||
Text = text;
|
||||
Font = font;
|
||||
LayoutRectangle = layoutRectangle;
|
||||
Bounds = bounds;
|
||||
Options = options;
|
||||
UsageCount = 0;
|
||||
}
|
||||
|
@ -74,7 +74,7 @@ namespace OpenTK.Graphics.Text
|
|||
|
||||
public override int GetHashCode()
|
||||
{
|
||||
return Text.GetHashCode() ^ Font.GetHashCode() ^ LayoutRectangle.GetHashCode() ^ Options.GetHashCode();
|
||||
return Text.GetHashCode() ^ Font.GetHashCode() ^ Bounds.GetHashCode() ^ Options.GetHashCode();
|
||||
}
|
||||
|
||||
public Glyph this[int i]
|
||||
|
@ -91,7 +91,7 @@ namespace OpenTK.Graphics.Text
|
|||
return
|
||||
Text == other.Text &&
|
||||
Font == other.Font &&
|
||||
LayoutRectangle == other.LayoutRectangle &&
|
||||
Bounds == other.Bounds &&
|
||||
Options == other.Options;
|
||||
}
|
||||
|
||||
|
|
|
@ -92,9 +92,15 @@ namespace OpenTK.Graphics
|
|||
|
||||
GL.PushAttrib(AttribMask.TextureBit | AttribMask.EnableBit | AttribMask.ColorBufferBit);
|
||||
|
||||
//GL.TexEnv(TextureEnvTarget.TextureEnv, TextureEnvParameter.TextureEnvMode, (int)TextureEnvMode.Modulate);
|
||||
|
||||
//GL.Enable(EnableCap.ColorMaterial);
|
||||
GL.Enable(EnableCap.Texture2D);
|
||||
GL.Enable(EnableCap.Blend);
|
||||
GL.BlendFunc(BlendingFactorSrc.SrcAlpha, BlendingFactorDest.OneMinusSrcAlpha);
|
||||
//GL.BlendFunc(BlendingFactorSrc.SrcAlpha, BlendingFactorDest.OneMinusSrcAlpha); // For grayscale
|
||||
GL.BlendFunc(BlendingFactorSrc.One, BlendingFactorDest.OneMinusSrcColor); // For subpixel
|
||||
//GL.BlendFunc(BlendingFactorSrc.ConstantColorExt, BlendingFactorDest.OneMinusSrcColor); // For subpixel with color
|
||||
|
||||
|
||||
GL.Disable(EnableCap.DepthTest);
|
||||
}
|
||||
|
@ -121,17 +127,17 @@ namespace OpenTK.Graphics
|
|||
|
||||
#region Print
|
||||
|
||||
public void Print(string text, Font font)
|
||||
public void Print(string text, Font font, Color color)
|
||||
{
|
||||
Print(text, font, 0, RectangleF.Empty);
|
||||
Print(text, font, color, RectangleF.Empty, TextPrinterOptions.Default);
|
||||
}
|
||||
|
||||
public void Print(string text, Font font, TextPrinterOptions options)
|
||||
public void Print(string text, Font font, Color color, RectangleF layoutRectangle)
|
||||
{
|
||||
Print(text, font, options, RectangleF.Empty);
|
||||
Print(text, font, color, layoutRectangle, TextPrinterOptions.Default);
|
||||
}
|
||||
|
||||
public void Print(string text, Font font, TextPrinterOptions options, RectangleF layoutRectangle)
|
||||
public void Print(string text, Font font, Color color, RectangleF layoutRectangle, TextPrinterOptions options)
|
||||
{
|
||||
if (String.IsNullOrEmpty(text))
|
||||
return;
|
||||
|
@ -139,7 +145,7 @@ namespace OpenTK.Graphics
|
|||
if (font == null)
|
||||
throw new ArgumentNullException("font");
|
||||
|
||||
text_output.Print(new TextBlock(text, font, options, layoutRectangle), glyph_rasterizer, glyph_cache);
|
||||
text_output.Print(new TextBlock(text, font, options, layoutRectangle.Size), layoutRectangle.Location, color, glyph_rasterizer, glyph_cache);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
@ -148,17 +154,17 @@ namespace OpenTK.Graphics
|
|||
|
||||
public TextExtents Measure(string text, Font font)
|
||||
{
|
||||
return Measure(text, font, 0, RectangleF.Empty);
|
||||
}
|
||||
|
||||
public TextExtents Measure(string text, Font font, TextPrinterOptions options)
|
||||
{
|
||||
return Measure(text, font, options, RectangleF.Empty);
|
||||
return Measure(text, font, RectangleF.Empty, TextPrinterOptions.Default);
|
||||
}
|
||||
|
||||
public TextExtents Measure(string text, Font font, TextPrinterOptions options, RectangleF layoutRectangle)
|
||||
public TextExtents Measure(string text, Font font, RectangleF layoutRectangle)
|
||||
{
|
||||
return glyph_rasterizer.MeasureText(new TextBlock(text, font, options, layoutRectangle));
|
||||
return Measure(text, font, layoutRectangle, TextPrinterOptions.Default);
|
||||
}
|
||||
|
||||
public TextExtents Measure(string text, Font font, RectangleF layoutRectangle, TextPrinterOptions options)
|
||||
{
|
||||
return glyph_rasterizer.MeasureText(new TextBlock(text, font, options, layoutRectangle.Size), layoutRectangle.Location);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
@ -168,13 +174,13 @@ namespace OpenTK.Graphics
|
|||
[Obsolete("Use TextPrinter.Print instead")]
|
||||
public void Draw(TextHandle handle)
|
||||
{
|
||||
Print(handle.Text, handle.GdiPFont);
|
||||
Print(handle.Text, handle.GdiPFont, Color.White);
|
||||
}
|
||||
|
||||
[Obsolete("Use TextPrinter.Print instead")]
|
||||
public void Draw(string text, TextureFont font)
|
||||
{
|
||||
Print(text, font.font);
|
||||
Print(text, font.font, Color.White);
|
||||
}
|
||||
|
||||
[Obsolete("Use TextPrinter.Print instead")]
|
||||
|
|
Loading…
Reference in a new issue