mirror of
https://github.com/Ryujinx/Opentk.git
synced 2024-12-24 17:45:37 +00:00
Updated examples to use the new TextPrinter.
This commit is contained in:
parent
5d1eda9289
commit
e1beaf3744
|
@ -8,6 +8,7 @@
|
|||
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
using System.Drawing;
|
||||
|
||||
using OpenTK;
|
||||
using OpenTK.Input;
|
||||
|
@ -25,7 +26,7 @@ namespace Examples.Tutorial
|
|||
{
|
||||
}
|
||||
|
||||
TextureFont sans = new TextureFont(new System.Drawing.Font(System.Drawing.FontFamily.GenericSansSerif, 14.0f));
|
||||
Font sans = new Font(System.Drawing.FontFamily.GenericSansSerif, 16.0f);
|
||||
ITextPrinter text = new TextPrinter();
|
||||
|
||||
uint ColorTexture;
|
||||
|
@ -236,7 +237,7 @@ namespace Examples.Tutorial
|
|||
GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit);
|
||||
|
||||
text.Begin();
|
||||
text.Draw((1.0 / e.Time).ToString("F2"), sans);
|
||||
text.Print((1.0 / e.Time).ToString("F2"), sans);
|
||||
text.End();
|
||||
|
||||
GL.PushMatrix();
|
||||
|
|
|
@ -55,7 +55,7 @@ namespace Examples.Tutorial
|
|||
|
||||
// Text drawing (for fps)
|
||||
TextPrinter printer = new TextPrinter();
|
||||
TextureFont font = new TextureFont(new Font(FontFamily.GenericSansSerif, 14.0f));
|
||||
Font font = new Font(FontFamily.GenericSansSerif, 16.0f);
|
||||
|
||||
#endregion private Fields
|
||||
|
||||
|
@ -290,7 +290,7 @@ namespace Examples.Tutorial
|
|||
GL.UseProgram(0);
|
||||
printer.Begin();
|
||||
GL.Color3(Color.PaleGoldenrod);
|
||||
printer.Draw((1 / e.Time).ToString("F2"), font);
|
||||
printer.Print((1 / e.Time).ToString("F2"), font, TextPrinterOptions.NoCache);
|
||||
printer.End();
|
||||
|
||||
SwapBuffers();
|
||||
|
|
|
@ -20,7 +20,7 @@ namespace Examples.Tests
|
|||
[Example("GameWindow states", ExampleCategory.Test)]
|
||||
public class GameWindowStates : GameWindow
|
||||
{
|
||||
TextureFont font = new TextureFont(new Font(FontFamily.GenericSansSerif, 16.0f));
|
||||
Font font = new Font(FontFamily.GenericSansSerif, 16.0f);
|
||||
TextPrinter printer = new TextPrinter();
|
||||
|
||||
#region GetNext and GetPrevious methods for enums.
|
||||
|
@ -118,12 +118,12 @@ namespace Examples.Tests
|
|||
|
||||
printer.Begin();
|
||||
|
||||
printer.Draw("Instructions:", font); GL.Translate(0, font.Height, 0);
|
||||
printer.Draw(String.Format("1 - cycle through window styles (current: {0}).", this.WindowState), font);
|
||||
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.Draw(String.Format("2 - cycle through window borders (current: {0}).", this.WindowBorder), font);
|
||||
printer.Print(String.Format("2 - cycle through window borders (current: {0}).", this.WindowBorder), font);
|
||||
GL.Translate(0, font.Height, 0);
|
||||
printer.Draw(String.Format("3 - toggle fullscreen (current: {0}).",
|
||||
printer.Print(String.Format("3 - toggle fullscreen (current: {0}).",
|
||||
this.WindowState == WindowState.Fullscreen ? "enabled" : "disabled"), font);
|
||||
|
||||
|
||||
|
|
|
@ -33,52 +33,50 @@ namespace Examples.Tutorial
|
|||
ITextPrinter printer = new TextPrinter();
|
||||
const string text = "Hello, world!";
|
||||
|
||||
TextHandle[] handles; // Used to cache the strings we want to print.
|
||||
|
||||
// Load some different TextureFont sizes to compare their quality.
|
||||
// You'll never need to load that many fonts in your application,
|
||||
// 3 or 4 should be more than enough.
|
||||
TextureFont[] fonts = new TextureFont[]
|
||||
Font[] fonts = new Font[]
|
||||
{
|
||||
new TextureFont(new Font(FontFamily.GenericSerif, 8.0f)),
|
||||
new TextureFont(new Font(FontFamily.GenericSerif, 10.0f)),
|
||||
new TextureFont(new Font(FontFamily.GenericSerif, 12.0f)),
|
||||
new TextureFont(new Font(FontFamily.GenericSerif, 14.0f)),
|
||||
new Font(FontFamily.GenericSerif, 8.0f),
|
||||
new Font(FontFamily.GenericSerif, 10.0f),
|
||||
new Font(FontFamily.GenericSerif, 12.0f),
|
||||
new Font(FontFamily.GenericSerif, 14.0f),
|
||||
|
||||
new TextureFont(new Font(FontFamily.GenericSerif, 16.0f)),
|
||||
new TextureFont(new Font(FontFamily.GenericSerif, 18.0f)),
|
||||
new TextureFont(new Font(FontFamily.GenericSerif, 20.0f)),
|
||||
new TextureFont(new Font(FontFamily.GenericSerif, 22.0f)),
|
||||
new Font(FontFamily.GenericSerif, 16.0f),
|
||||
new Font(FontFamily.GenericSerif, 18.0f),
|
||||
new Font(FontFamily.GenericSerif, 20.0f),
|
||||
new Font(FontFamily.GenericSerif, 22.0f),
|
||||
|
||||
new TextureFont(new Font(FontFamily.GenericSerif, 24.0f, FontStyle.Bold)),
|
||||
new TextureFont(new Font(FontFamily.GenericSerif, 26.0f)),
|
||||
new TextureFont(new Font(FontFamily.GenericSerif, 28.0f)),
|
||||
new TextureFont(new Font(FontFamily.GenericSerif, 30.0f)),
|
||||
new Font(FontFamily.GenericSerif, 24.0f, FontStyle.Bold),
|
||||
new Font(FontFamily.GenericSerif, 26.0f),
|
||||
new Font(FontFamily.GenericSerif, 28.0f),
|
||||
new Font(FontFamily.GenericSerif, 30.0f),
|
||||
|
||||
new TextureFont(new Font(FontFamily.GenericSerif, 32.0f, FontStyle.Italic)),
|
||||
new TextureFont(new Font(FontFamily.GenericSerif, 34.0f)),
|
||||
new TextureFont(new Font(FontFamily.GenericSerif, 36.0f)),
|
||||
new TextureFont(new Font(FontFamily.GenericSerif, 38.0f)),
|
||||
new Font(FontFamily.GenericSerif, 32.0f, FontStyle.Italic),
|
||||
new Font(FontFamily.GenericSerif, 34.0f),
|
||||
new Font(FontFamily.GenericSerif, 36.0f),
|
||||
new Font(FontFamily.GenericSerif, 38.0f),
|
||||
|
||||
new TextureFont(new Font(FontFamily.GenericSansSerif, 8.0f)),
|
||||
new TextureFont(new Font(FontFamily.GenericSansSerif, 10.0f)),
|
||||
new TextureFont(new Font(FontFamily.GenericSansSerif, 12.0f)),
|
||||
new TextureFont(new Font(FontFamily.GenericSansSerif, 14.0f)),
|
||||
new Font(FontFamily.GenericSansSerif, 8.0f),
|
||||
new Font(FontFamily.GenericSansSerif, 10.0f),
|
||||
new Font(FontFamily.GenericSansSerif, 12.0f),
|
||||
new Font(FontFamily.GenericSansSerif, 14.0f),
|
||||
|
||||
new TextureFont(new Font(FontFamily.GenericSansSerif, 16.0f)),
|
||||
new TextureFont(new Font(FontFamily.GenericSansSerif, 18.0f)),
|
||||
new TextureFont(new Font(FontFamily.GenericSansSerif, 20.0f)),
|
||||
new TextureFont(new Font(FontFamily.GenericSansSerif, 22.0f)),
|
||||
new Font(FontFamily.GenericSansSerif, 16.0f),
|
||||
new Font(FontFamily.GenericSansSerif, 18.0f),
|
||||
new Font(FontFamily.GenericSansSerif, 20.0f),
|
||||
new Font(FontFamily.GenericSansSerif, 22.0f),
|
||||
|
||||
new TextureFont(new Font(FontFamily.GenericSansSerif, 24.0f, FontStyle.Bold)),
|
||||
new TextureFont(new Font(FontFamily.GenericSansSerif, 26.0f)),
|
||||
new TextureFont(new Font(FontFamily.GenericSansSerif, 28.0f)),
|
||||
new TextureFont(new Font(FontFamily.GenericSansSerif, 30.0f)),
|
||||
new Font(FontFamily.GenericSansSerif, 24.0f, FontStyle.Bold),
|
||||
new Font(FontFamily.GenericSansSerif, 26.0f),
|
||||
new Font(FontFamily.GenericSansSerif, 28.0f),
|
||||
new Font(FontFamily.GenericSansSerif, 30.0f),
|
||||
|
||||
new TextureFont(new Font(FontFamily.GenericSansSerif, 32.0f, FontStyle.Italic)),
|
||||
new TextureFont(new Font(FontFamily.GenericSansSerif, 34.0f)),
|
||||
new TextureFont(new Font(FontFamily.GenericSansSerif, 36.0f)),
|
||||
new TextureFont(new Font(FontFamily.GenericSansSerif, 38.0f)),
|
||||
new Font(FontFamily.GenericSansSerif, 32.0f, FontStyle.Italic),
|
||||
new Font(FontFamily.GenericSansSerif, 34.0f),
|
||||
new Font(FontFamily.GenericSansSerif, 36.0f),
|
||||
new Font(FontFamily.GenericSansSerif, 38.0f),
|
||||
};
|
||||
|
||||
#endregion
|
||||
|
@ -99,10 +97,6 @@ namespace Examples.Tutorial
|
|||
public override void OnLoad(EventArgs e)
|
||||
{
|
||||
GL.ClearColor(Color.SteelBlue);
|
||||
|
||||
handles = new TextHandle[fonts.Length];
|
||||
for (int i = handles.Length; --i >= 0; )
|
||||
printer.Prepare(text, fonts[i], out handles[i]);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
@ -117,9 +111,7 @@ namespace Examples.Tutorial
|
|||
/// <param name="e"></param>
|
||||
public override void OnUnload(EventArgs e)
|
||||
{
|
||||
foreach (TextHandle h in handles)
|
||||
h.Dispose();
|
||||
foreach (TextureFont f in fonts)
|
||||
foreach (Font f in fonts)
|
||||
f.Dispose();
|
||||
}
|
||||
|
||||
|
@ -168,21 +160,21 @@ namespace Examples.Tutorial
|
|||
printer.Begin();
|
||||
|
||||
// Print using the first font.
|
||||
for (int i = 0; i < handles.Length / 2; i++)
|
||||
for (int i = 0; i < fonts.Length / 2; i++)
|
||||
{
|
||||
printer.Draw(handles[i]);
|
||||
printer.Print(text, fonts[i]);
|
||||
GL.Translate(0, fonts[i].Height, 0);
|
||||
}
|
||||
|
||||
// Move to the right, and print using the second font.
|
||||
//float width, height;
|
||||
//fonts[handles.Length / 2 - 1].MeasureString(text, out width, out height);
|
||||
RectangleF rect = fonts[handles.Length / 2 - 1].MeasureText(text);
|
||||
RectangleF rect = printer.Measure(text, fonts[fonts.Length / 2 - 1]).BoundingBox;
|
||||
GL.LoadIdentity();
|
||||
GL.Translate(rect.Width + 32.0f, 0, 0);
|
||||
for (int i = handles.Length / 2; i < handles.Length; i++)
|
||||
for (int i = fonts.Length / 2; i < fonts.Length; i++)
|
||||
{
|
||||
printer.Draw(handles[i]);
|
||||
printer.Print(text, fonts[i]);
|
||||
GL.Translate(0, fonts[i].Height, 0);
|
||||
}
|
||||
|
||||
|
|
|
@ -23,13 +23,12 @@ namespace Examples.Tutorial
|
|||
[Example("Text", ExampleCategory.Tutorial, 4)]
|
||||
public class Text : GameWindow
|
||||
{
|
||||
Font serif2 = new Font(FontFamily.GenericSerif, 16.0f);
|
||||
TextureFont serif = new TextureFont(new Font(FontFamily.GenericSerif, 12.0f));
|
||||
TextureFont sans = new TextureFont(new Font(FontFamily.GenericSansSerif, 14.0f));
|
||||
TextHandle poem_handle;
|
||||
Font serif = new Font(FontFamily.GenericSerif, 16.0f);
|
||||
Font sans = new Font(FontFamily.GenericSansSerif, 48.0f, FontStyle.Italic);
|
||||
TextPrinter text = new TextPrinter();
|
||||
|
||||
string poem = new StreamReader("Data/Poem.txt").ReadToEnd();
|
||||
//string poem = new StreamReader("Data/Poem.txt").ReadToEnd();
|
||||
string poem = "The quick brown fox jumped over the lazy dogs!\n\nKerning: Wo\nLigatures: ffi, fft";
|
||||
int lines; // How many lines the poem contains.
|
||||
|
||||
float scroll_speed;
|
||||
|
@ -49,7 +48,6 @@ namespace Examples.Tutorial
|
|||
|
||||
current_position = initial_position;
|
||||
scroll_speed = -1.0f;
|
||||
text.Prepare(poem, serif, out poem_handle);
|
||||
|
||||
// Count the amount of lines in the text, to find out the correct
|
||||
// warparound position. We want the text to scroll until the last
|
||||
|
@ -69,8 +67,10 @@ namespace Examples.Tutorial
|
|||
|
||||
public override void OnUnload(EventArgs e)
|
||||
{
|
||||
if (poem_handle != null) poem_handle.Dispose();
|
||||
if (serif != null) serif.Dispose();
|
||||
if (serif != null)
|
||||
serif.Dispose();
|
||||
if (sans != null)
|
||||
sans.Dispose();
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
@ -126,14 +126,17 @@ namespace Examples.Tutorial
|
|||
// used in 2d graphics, and is necessary for achieving pixel-perfect glyph rendering.
|
||||
// TextPrinter.End() restores your previous projection/modelview matrices.
|
||||
text.Begin();
|
||||
//GL.Color3(Color.LightBlue);
|
||||
//text.Draw((1.0 / e.Time).ToString("F2"), sans);
|
||||
|
||||
// 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);
|
||||
|
||||
// Print the actual text.
|
||||
GL.Translate(0.0f, current_position, 0.0f);
|
||||
GL.Color3(Color.White);
|
||||
//text.Draw(poem_handle);
|
||||
//text.Draw(poem, serif);
|
||||
//GL.BindTexture(TextureTarget.Texture2D, 1);
|
||||
text.Print(poem, serif2);
|
||||
text.Print(poem, serif);
|
||||
|
||||
text.End();
|
||||
|
||||
SwapBuffers();
|
||||
|
|
Loading…
Reference in a new issue