mirror of
https://github.com/Ryujinx/Opentk.git
synced 2025-01-24 08:31:07 +00:00
Moved Begin/End to ITextOutputProvider.
Fixed text location.
This commit is contained in:
parent
3dd42ada72
commit
2abc0461b0
|
@ -25,11 +25,8 @@
|
||||||
//
|
//
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Text;
|
|
||||||
using System.Drawing;
|
using System.Drawing;
|
||||||
|
|
||||||
using OpenTK.Math;
|
using OpenTK.Math;
|
||||||
|
|
||||||
namespace OpenTK.Graphics.Text
|
namespace OpenTK.Graphics.Text
|
||||||
|
@ -41,6 +38,7 @@ namespace OpenTK.Graphics.Text
|
||||||
// Triangle lists, sorted by texture.
|
// Triangle lists, sorted by texture.
|
||||||
Dictionary<Texture2D, List<Vector2>> active_lists = new Dictionary<Texture2D, List<Vector2>>();
|
Dictionary<Texture2D, List<Vector2>> active_lists = new Dictionary<Texture2D, List<Vector2>>();
|
||||||
Queue<List<Vector2>> inactive_lists = new Queue<List<Vector2>>();
|
Queue<List<Vector2>> inactive_lists = new Queue<List<Vector2>>();
|
||||||
|
float[] viewport = new float[4];
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
|
@ -55,27 +53,12 @@ namespace OpenTK.Graphics.Text
|
||||||
|
|
||||||
#region ITextOutputProvider Members
|
#region ITextOutputProvider Members
|
||||||
|
|
||||||
|
#region Print
|
||||||
|
|
||||||
public void Print(TextBlock block, PointF location, Color color, IGlyphRasterizer rasterizer, GlyphCache cache)
|
public void Print(TextBlock block, PointF location, Color color, IGlyphRasterizer rasterizer, GlyphCache cache)
|
||||||
{
|
{
|
||||||
using (TextExtents extents = rasterizer.MeasureText(block, location))
|
using (TextExtents extents = rasterizer.MeasureText(block, location))
|
||||||
{
|
{
|
||||||
//GL.BindTexture(TextureTarget.Texture2D, 2);
|
|
||||||
|
|
||||||
//GL.Begin(BeginMode.Quads);
|
|
||||||
|
|
||||||
//GL.TexCoord2(0, 0);
|
|
||||||
//GL.Vertex2(0, 0);
|
|
||||||
//GL.TexCoord2(1, 0);
|
|
||||||
//GL.Vertex2(256, 0);
|
|
||||||
//GL.TexCoord2(1, 1);
|
|
||||||
//GL.Vertex2(256, 256);
|
|
||||||
//GL.TexCoord2(0, 1);
|
|
||||||
//GL.Vertex2(0, 256);
|
|
||||||
|
|
||||||
//GL.End();
|
|
||||||
|
|
||||||
//GL.Translate(0, 256, 0);
|
|
||||||
|
|
||||||
// Build layout
|
// Build layout
|
||||||
int current = 0;
|
int current = 0;
|
||||||
foreach (Glyph glyph in block)
|
foreach (Glyph glyph in block)
|
||||||
|
@ -124,6 +107,9 @@ namespace OpenTK.Graphics.Text
|
||||||
List<Vector2> list = active_lists[key];
|
List<Vector2> list = active_lists[key];
|
||||||
|
|
||||||
key.Bind();
|
key.Bind();
|
||||||
|
|
||||||
|
GL.Translate(location.X, location.Y, 0);
|
||||||
|
|
||||||
GL.Begin(BeginMode.Triangles);
|
GL.Begin(BeginMode.Triangles);
|
||||||
|
|
||||||
for (int i = 0; i < list.Count; i += 2)
|
for (int i = 0; i < list.Count; i += 2)
|
||||||
|
@ -146,5 +132,61 @@ namespace OpenTK.Graphics.Text
|
||||||
}
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
|
#region Begin
|
||||||
|
|
||||||
|
public void Begin()
|
||||||
|
{
|
||||||
|
if (GraphicsContext.CurrentContext == null)
|
||||||
|
throw new GraphicsContextException("No GraphicsContext is current in the calling thread.");
|
||||||
|
|
||||||
|
GL.GetFloat(GetPName.Viewport, viewport);
|
||||||
|
|
||||||
|
// Prepare to draw text. We want pixel perfect precision, so we setup a 2D mode,
|
||||||
|
// with size equal to the window (in pixels).
|
||||||
|
// While we could also render text in 3D mode, it would be very hard to get
|
||||||
|
// pixel-perfect precision.
|
||||||
|
GL.MatrixMode(MatrixMode.Projection);
|
||||||
|
GL.PushMatrix();
|
||||||
|
GL.LoadIdentity();
|
||||||
|
GL.Ortho(viewport[0], viewport[2], viewport[3], viewport[1], -1.0, 1.0);
|
||||||
|
|
||||||
|
GL.MatrixMode(MatrixMode.Modelview);
|
||||||
|
GL.PushMatrix();
|
||||||
|
GL.LoadIdentity();
|
||||||
|
|
||||||
|
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); // For grayscale
|
||||||
|
GL.BlendFunc(BlendingFactorSrc.One, BlendingFactorDest.OneMinusSrcColor); // For subpixel
|
||||||
|
//GL.BlendFunc(BlendingFactorSrc.ConstantColorExt, BlendingFactorDest.OneMinusSrcColor); // For subpixel with color
|
||||||
|
|
||||||
|
|
||||||
|
GL.Disable(EnableCap.DepthTest);
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
#region End
|
||||||
|
|
||||||
|
public void End()
|
||||||
|
{
|
||||||
|
GL.PopAttrib();
|
||||||
|
|
||||||
|
GL.MatrixMode(MatrixMode.Modelview);
|
||||||
|
GL.PopMatrix();
|
||||||
|
|
||||||
|
GL.MatrixMode(MatrixMode.Projection);
|
||||||
|
GL.PopMatrix();
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
#endregion
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -136,7 +136,7 @@ namespace OpenTK.Graphics.Text
|
||||||
return block_cache[block];
|
return block_cache[block];
|
||||||
|
|
||||||
// If this block is not cached, we have to measure it and (potentially) place it in the cache.
|
// If this block is not cached, we have to measure it and (potentially) place it in the cache.
|
||||||
TextExtents extents = MeasureTextExtents(block, location);
|
TextExtents extents = MeasureTextExtents(block);
|
||||||
|
|
||||||
if ((block.Options & TextPrinterOptions.NoCache) == 0)
|
if ((block.Options & TextPrinterOptions.NoCache) == 0)
|
||||||
block_cache.Add(block, extents);
|
block_cache.Add(block, extents);
|
||||||
|
@ -185,7 +185,7 @@ namespace OpenTK.Graphics.Text
|
||||||
|
|
||||||
#region MeasureTextExtents
|
#region MeasureTextExtents
|
||||||
|
|
||||||
TextExtents MeasureTextExtents(TextBlock block, PointF location)
|
TextExtents MeasureTextExtents(TextBlock block)
|
||||||
{
|
{
|
||||||
// Todo: Parse layout options:
|
// Todo: Parse layout options:
|
||||||
//StringFormat format = default_string_format;
|
//StringFormat format = default_string_format;
|
||||||
|
@ -193,7 +193,7 @@ namespace OpenTK.Graphics.Text
|
||||||
|
|
||||||
TextExtents extents = text_extents_pool.Acquire();
|
TextExtents extents = text_extents_pool.Acquire();
|
||||||
|
|
||||||
RectangleF rect = new RectangleF(location, block.Bounds);
|
RectangleF rect = new RectangleF(PointF.Empty, block.Bounds);
|
||||||
// Work around Mono/GDI+ bug, which causes incorrect
|
// Work around Mono/GDI+ bug, which causes incorrect
|
||||||
// text wraping when block.Bounds == SizeF.Empty.
|
// text wraping when block.Bounds == SizeF.Empty.
|
||||||
if (block.Bounds == SizeF.Empty)
|
if (block.Bounds == SizeF.Empty)
|
||||||
|
|
|
@ -35,5 +35,7 @@ namespace OpenTK.Graphics.Text
|
||||||
interface ITextOutputProvider
|
interface ITextOutputProvider
|
||||||
{
|
{
|
||||||
void Print(TextBlock block, PointF location, Color color, IGlyphRasterizer rasterizer, GlyphCache cache);
|
void Print(TextBlock block, PointF location, Color color, IGlyphRasterizer rasterizer, GlyphCache cache);
|
||||||
|
void Begin();
|
||||||
|
void End();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -34,8 +34,6 @@ namespace OpenTK.Graphics
|
||||||
IGlyphRasterizer glyph_rasterizer;
|
IGlyphRasterizer glyph_rasterizer;
|
||||||
ITextOutputProvider text_output;
|
ITextOutputProvider text_output;
|
||||||
|
|
||||||
float[] viewport = new float[4];
|
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region Constructors
|
#region Constructors
|
||||||
|
@ -70,39 +68,10 @@ namespace OpenTK.Graphics
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Sets up OpenGL state for drawing text.
|
/// Sets up OpenGL state for drawing text.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
[Obsolete]
|
||||||
public void Begin()
|
public void Begin()
|
||||||
{
|
{
|
||||||
if (GraphicsContext.CurrentContext == null)
|
text_output.Begin();
|
||||||
throw new GraphicsContextException("No GraphicsContext is current in the calling thread.");
|
|
||||||
|
|
||||||
GL.GetFloat(GetPName.Viewport, viewport);
|
|
||||||
|
|
||||||
// Prepare to draw text. We want pixel perfect precision, so we setup a 2D mode,
|
|
||||||
// with size equal to the window (in pixels).
|
|
||||||
// While we could also render text in 3D mode, it would be very hard to get
|
|
||||||
// pixel-perfect precision.
|
|
||||||
GL.MatrixMode(MatrixMode.Projection);
|
|
||||||
GL.PushMatrix();
|
|
||||||
GL.LoadIdentity();
|
|
||||||
GL.Ortho(viewport[0], viewport[2], viewport[3], viewport[1], -1.0, 1.0);
|
|
||||||
|
|
||||||
GL.MatrixMode(MatrixMode.Modelview);
|
|
||||||
GL.PushMatrix();
|
|
||||||
GL.LoadIdentity();
|
|
||||||
|
|
||||||
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); // For grayscale
|
|
||||||
GL.BlendFunc(BlendingFactorSrc.One, BlendingFactorDest.OneMinusSrcColor); // For subpixel
|
|
||||||
//GL.BlendFunc(BlendingFactorSrc.ConstantColorExt, BlendingFactorDest.OneMinusSrcColor); // For subpixel with color
|
|
||||||
|
|
||||||
|
|
||||||
GL.Disable(EnableCap.DepthTest);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
@ -112,15 +81,10 @@ namespace OpenTK.Graphics
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Restores OpenGL state.
|
/// Restores OpenGL state.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
[Obsolete]
|
||||||
public void End()
|
public void End()
|
||||||
{
|
{
|
||||||
GL.PopAttrib();
|
text_output.End();
|
||||||
|
|
||||||
GL.MatrixMode(MatrixMode.Modelview);
|
|
||||||
GL.PopMatrix();
|
|
||||||
|
|
||||||
GL.MatrixMode(MatrixMode.Projection);
|
|
||||||
GL.PopMatrix();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
@ -145,7 +109,9 @@ namespace OpenTK.Graphics
|
||||||
if (font == null)
|
if (font == null)
|
||||||
throw new ArgumentNullException("font");
|
throw new ArgumentNullException("font");
|
||||||
|
|
||||||
|
text_output.Begin();
|
||||||
text_output.Print(new TextBlock(text, font, options, layoutRectangle.Size), layoutRectangle.Location, color, glyph_rasterizer, glyph_cache);
|
text_output.Print(new TextBlock(text, font, options, layoutRectangle.Size), layoutRectangle.Location, color, glyph_rasterizer, glyph_cache);
|
||||||
|
text_output.End();
|
||||||
}
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
Loading…
Reference in a new issue