diff --git a/Source/OpenTK/Fonts/DisplayListTextPrinter.cs b/Source/OpenTK/Fonts/DisplayListTextPrinter.cs index 9e8951ff..4e36c973 100644 --- a/Source/OpenTK/Fonts/DisplayListTextPrinter.cs +++ b/Source/OpenTK/Fonts/DisplayListTextPrinter.cs @@ -9,6 +9,7 @@ using System.Collections.Generic; using System.Text; using OpenTK.Graphics.OpenGL; +using OpenTK.Math; namespace OpenTK.Fonts { @@ -19,21 +20,14 @@ namespace OpenTK.Fonts { #region IPrinter Members - public TextHandle Load(OpenTK.Math.Vector2[] vertices, ushort[] indices, int index_count) + public TextHandle Load(Vector2[] vertices, ushort[] indices, int index_count) { DisplayListTextHandle handle = new DisplayListTextHandle(GL.GenLists(1)); GL.NewList(handle.Handle, ListMode.Compile); - GL.Begin(BeginMode.Triangles); - for (int i = 0; i < index_count; i++) - //foreach (ushort index in indices) - { - GL.TexCoord2(vertices[indices[i] + 1]); - GL.Vertex2(vertices[indices[i]]); - } + this.Draw(vertices, indices, index_count); - GL.End(); GL.EndList(); return handle; @@ -44,6 +38,20 @@ namespace OpenTK.Fonts GL.CallList(handle.Handle); } + public void Draw(Vector2[] vertices, ushort[] indices, int index_count) + { + GL.Begin(BeginMode.Triangles); + + for (int i = 0; i < index_count; i++) + //foreach (ushort index in indices) + { + GL.TexCoord2(vertices[indices[i] + 1]); + GL.Vertex2(vertices[indices[i]]); + } + + GL.End(); + } + #endregion } } diff --git a/Source/OpenTK/Fonts/IPrinterImplementation.cs b/Source/OpenTK/Fonts/IPrinterImplementation.cs index be1e9e8d..cf608008 100644 --- a/Source/OpenTK/Fonts/IPrinterImplementation.cs +++ b/Source/OpenTK/Fonts/IPrinterImplementation.cs @@ -19,6 +19,6 @@ namespace OpenTK.Fonts { TextHandle Load(Vector2[] vertices, ushort[] indices, int index_count); void Draw(TextHandle handle); - //void Draw(Vector2[] vertices, ushort[] indices, int index_count); + void Draw(Vector2[] vertices, ushort[] indices, int index_count); } } diff --git a/Source/OpenTK/Fonts/TextPrinter.cs b/Source/OpenTK/Fonts/TextPrinter.cs index 64cc437d..eb7854a2 100644 --- a/Source/OpenTK/Fonts/TextPrinter.cs +++ b/Source/OpenTK/Fonts/TextPrinter.cs @@ -149,7 +149,6 @@ namespace OpenTK.Fonts #endregion - #region void PerformLayout(string text, TextureFont font, float width, bool wordWarp, StringAlignment alignment, bool rightToLeft, ref Vector2[] vertices, ref ushort[] indices, out int num_indices) // Performs layout on the given string. @@ -227,7 +226,7 @@ namespace OpenTK.Fonts indices[index_count++] = (ushort)(vertex_count - 8); - font.MeasureString(text.Substring(i, 1), out measured_width, out measured_height); + font.MeasureString(text.Substring(i, 1), out measured_width, out measured_height, false); x_pos += measured_width; } else if (c == '\n') @@ -275,7 +274,9 @@ namespace OpenTK.Fonts /// The OpenTK.Fonts.TextureFont to draw the text in. public void Draw(string text, TextureFont font) { - //printer.Draw(text); + int num_indices; + PerformLayout(text, font, 0, false, StringAlignment.Near, false, ref vertices, ref indices, out num_indices); + printer.Draw(vertices, indices, num_indices); } #endregion @@ -296,7 +297,7 @@ namespace OpenTK.Fonts GL.MatrixMode(MatrixMode.Projection); GL.PushMatrix(); GL.LoadIdentity(); - GL.Ortho(viewport[0], viewport[2], viewport[3], viewport[1], 0.0, 1.0); + GL.Ortho(viewport[0], viewport[2], viewport[3], viewport[1], -1.0, 1.0); GL.MatrixMode(MatrixMode.Modelview); GL.PushMatrix(); @@ -324,10 +325,10 @@ namespace OpenTK.Fonts GL.PopAttrib(); GL.PopAttrib(); - GL.MatrixMode(MatrixMode.Projection); + GL.MatrixMode(MatrixMode.Modelview); GL.PopMatrix(); - GL.MatrixMode(MatrixMode.Modelview); + GL.MatrixMode(MatrixMode.Projection); GL.PopMatrix(); } diff --git a/Source/OpenTK/Fonts/TextureFont.cs b/Source/OpenTK/Fonts/TextureFont.cs index 8b38e69c..52e7d732 100644 --- a/Source/OpenTK/Fonts/TextureFont.cs +++ b/Source/OpenTK/Fonts/TextureFont.cs @@ -270,6 +270,42 @@ namespace OpenTK.Fonts #endregion + #region public void MeasureString(string str, out float width, out float height, bool accountForOverhangs) + + /// + /// Measures the width of the specified string. + /// + /// The string to measure. + /// The measured width. + /// The measured height. + /// If true, adds space to account for glyph overhangs. Set to true if you wish to measure a complete string. Set to false if you wish to perform layout on adjacent strings. + public void MeasureString(string str, out float width, out float height, bool accountForOverhangs) + { + System.Drawing.StringFormat format = accountForOverhangs ? System.Drawing.StringFormat.GenericDefault : System.Drawing.StringFormat.GenericTypographic; + format.FormatFlags |= StringFormatFlags.MeasureTrailingSpaces; + + System.Drawing.SizeF size = gfx.MeasureString(str, font, 16384, format); + height = size.Height; + width = size.Width; + + // width = 0; + // height = 0; + // int i = 0; + // foreach (char c in str) + // { + // if (c != '\n' && c != '\r') + // { + // SizeF size = gfx.MeasureString(str.Substring(i, 1), font, 16384, System.Drawing.StringFormat.GenericTypographic); + // width += size.Width == 0 ? font.SizeInPoints * 0.5f : size.Width; + // if (height < size.Height) + // height = size.Height; + // } + // ++i; + // } + } + + #endregion + #region public void MeasureString(string str, out float width, out float height) /// @@ -278,30 +314,10 @@ namespace OpenTK.Fonts /// The string to measure. /// The measured width. /// The measured height. + /// public void MeasureString(string str, out float width, out float height) { - //System.Drawing.SizeF size = gfx.MeasureString(str, font, 16384, System.Drawing.StringFormat.GenericTypographic); - //height = size.Height; - - //if (size.Width == 0) - // width = font.SizeInPoints * 0.5f; - //else - // width = size.Width; - - width = 0; - height = 0; - int i = 0; - foreach (char c in str) - { - if (c != '\n' && c != '\r') - { - SizeF size = gfx.MeasureString(str.Substring(i, 1), font, 16384, System.Drawing.StringFormat.GenericTypographic); - width += size.Width == 0 ? font.SizeInPoints * 0.5f : size.Width; - if (height < size.Height) - height = size.Height; - } - ++i; - } + MeasureString(str, out width, out height, true); } #endregion diff --git a/Source/OpenTK/Fonts/VboTextPrinter.cs b/Source/OpenTK/Fonts/VboTextPrinter.cs index 96ce695f..6b85b970 100644 --- a/Source/OpenTK/Fonts/VboTextPrinter.cs +++ b/Source/OpenTK/Fonts/VboTextPrinter.cs @@ -71,6 +71,11 @@ namespace OpenTK.Fonts //GL.PopClientAttrib(); } + public void Draw(Vector2[] vertices, ushort[] indices, int index_count) + { + throw new NotImplementedException(); + } + #endregion }