diff --git a/Source/Utilities/Graphics/ITextPrinter.cs b/Source/Utilities/Graphics/ITextPrinter.cs index 4f72e74a..e5cb68dc 100644 --- a/Source/Utilities/Graphics/ITextPrinter.cs +++ b/Source/Utilities/Graphics/ITextPrinter.cs @@ -128,14 +128,26 @@ namespace OpenTK.Graphics #endregion - #region Obsolete + #region Begin - [Obsolete] + /// + /// Sets up a resolution-dependent orthographic projection. + /// void Begin(); - [Obsolete] + #endregion + + /// + /// Restores the projection and modelview matrices to their previous state. + /// + #region End + void End(); + #endregion + + #region Obsolete + [Obsolete("Use TextPrinter.Print instead")] void Draw(TextHandle handle); diff --git a/Source/Utilities/Graphics/Text/GL1TextOutputProvider.cs b/Source/Utilities/Graphics/Text/GL1TextOutputProvider.cs index c93177a2..6731f35e 100644 --- a/Source/Utilities/Graphics/Text/GL1TextOutputProvider.cs +++ b/Source/Utilities/Graphics/Text/GL1TextOutputProvider.cs @@ -40,6 +40,12 @@ namespace OpenTK.Graphics.Text Dictionary> active_lists = new Dictionary>(); Queue> inactive_lists = new Queue>(); + #pragma warning disable 0649 + + struct Viewport { public float Left, Top, Right, Bottom; } + + #pragma warning restore 0649 + bool disposed; #endregion @@ -164,6 +170,62 @@ namespace OpenTK.Graphics.Text #endregion + #region Begin + + public void Begin() + { + if (disposed) + throw new ObjectDisposedException(this.GetType().ToString()); + + GraphicsContext.Assert(); + + int current_matrix; + GL.GetInteger(GetPName.MatrixMode, out current_matrix); + + Viewport viewport = new Viewport(); + GL.GetFloat(GetPName.Viewport, out viewport.Left); + + // 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.Left, viewport.Right, viewport.Bottom, viewport.Top, -1.0, 1.0); + + GL.MatrixMode(MatrixMode.Modelview); + GL.PushMatrix(); + GL.LoadIdentity(); + + GL.MatrixMode((MatrixMode)current_matrix); + } + + #endregion + + #region End + + public void End() + { + if (disposed) + throw new ObjectDisposedException(this.GetType().ToString()); + + GraphicsContext.Assert(); + + int current_matrix; + GL.GetInteger(GetPName.MatrixMode, out current_matrix); + + GL.MatrixMode(MatrixMode.Modelview); + GL.PopMatrix(); + + GL.MatrixMode(MatrixMode.Projection); + GL.PopMatrix(); + + GL.MatrixMode((MatrixMode)current_matrix); + } + + #endregion + #endregion #region Protected Members diff --git a/Source/Utilities/Graphics/Text/ITextOutputProvider.cs b/Source/Utilities/Graphics/Text/ITextOutputProvider.cs index ce1aaf93..826dc890 100644 --- a/Source/Utilities/Graphics/Text/ITextOutputProvider.cs +++ b/Source/Utilities/Graphics/Text/ITextOutputProvider.cs @@ -36,5 +36,7 @@ namespace OpenTK.Graphics.Text { void Print(TextBlock block, Color color, IGlyphRasterizer rasterizer); void Clear(); + void Begin(); + void End(); } } diff --git a/Source/Utilities/Graphics/TextPrinter.cs b/Source/Utilities/Graphics/TextPrinter.cs index a96757d0..defb3c02 100644 --- a/Source/Utilities/Graphics/TextPrinter.cs +++ b/Source/Utilities/Graphics/TextPrinter.cs @@ -214,7 +214,7 @@ namespace OpenTK.Graphics #endregion - #region Clear() + #region Clear public void Clear() { @@ -227,55 +227,32 @@ namespace OpenTK.Graphics #endregion - #region Obsolete + #region Begin /// - /// Sets up OpenGL state for drawing text. + /// Sets up a resolution-dependent orthographic projection. /// - [Obsolete] public void Begin() { - if (disposed) - throw new ObjectDisposedException(this.GetType().ToString()); - - GraphicsContext.Assert(); - - float[] viewport = new float[4]; - - 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(); + TextOutput.Begin(); } + #endregion + + #region Begin + /// - /// Restores OpenGL state. + /// Restores the projection and modelview matrices to their previous state. /// - [Obsolete] public void End() { - if (disposed) - throw new ObjectDisposedException(this.GetType().ToString()); - - GraphicsContext.Assert(); - - GL.MatrixMode(MatrixMode.Modelview); - GL.PopMatrix(); - - GL.MatrixMode(MatrixMode.Projection); - GL.PopMatrix(); + TextOutput.End(); } + #endregion + + #region Obsolete + [Obsolete("Use TextPrinter.Print instead")] public void Draw(TextHandle handle) {