From 878dd4394c33a7cf4bd08db7bc71930600f19374 Mon Sep 17 00:00:00 2001 From: the_fiddler Date: Mon, 17 Aug 2009 09:32:50 +0000 Subject: [PATCH] Disabled TextPrinter samples. Removed TextPrinter references. --- .../OpenTK/Fonts/FontRenderingAdvanced.cs | 3 +- .../OpenTK/Fonts/FontRenderingBasic.cs | 8 +- .../Examples/OpenTK/Test/GameWindowStates.cs | 98 +++++++++++-------- 3 files changed, 65 insertions(+), 44 deletions(-) diff --git a/Source/Examples/OpenTK/Fonts/FontRenderingAdvanced.cs b/Source/Examples/OpenTK/Fonts/FontRenderingAdvanced.cs index f7e2f1b4..c81a1180 100644 --- a/Source/Examples/OpenTK/Fonts/FontRenderingAdvanced.cs +++ b/Source/Examples/OpenTK/Fonts/FontRenderingAdvanced.cs @@ -12,12 +12,12 @@ using System.Drawing; using System.Diagnostics; using OpenTK; -using OpenTK.Graphics; using OpenTK.Graphics.OpenGL; using OpenTK.Input; namespace Examples.Tutorial { +#if false /// /// Shows how to render and scroll large amounts of text. /// @@ -159,4 +159,5 @@ namespace Examples.Tutorial #endregion } +#endif } diff --git a/Source/Examples/OpenTK/Fonts/FontRenderingBasic.cs b/Source/Examples/OpenTK/Fonts/FontRenderingBasic.cs index 4c5e8695..34ee3170 100644 --- a/Source/Examples/OpenTK/Fonts/FontRenderingBasic.cs +++ b/Source/Examples/OpenTK/Fonts/FontRenderingBasic.cs @@ -38,7 +38,7 @@ using OpenTK.Graphics.OpenGL; namespace Examples.WinForms { - [Example("Font rendering (basic)", ExampleCategory.OpenTK, "Fonts", Difficulty = 1, Documentation = "FontRenderingBasic")] + [Example("Font rendering (basic)", ExampleCategory.OpenTK, "Fonts", Difficulty = 1, Documentation = "FontRenderingBasic", Visible=false)] public partial class FontRenderingBasic : Form { #region Fields @@ -46,7 +46,7 @@ namespace Examples.WinForms float[] sizes = new float[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 12, 14, 16, 18, 20, 24 }; List fonts = new List(); - TextPrinter printer = new TextPrinter(); + //TextPrinter printer = new TextPrinter(); #endregion @@ -70,7 +70,7 @@ namespace Examples.WinForms void UpdateFontList(Font base_font) { - printer.Clear(); + //printer.Clear(); foreach (Font font in fonts) font.Dispose(); @@ -116,7 +116,7 @@ namespace Examples.WinForms foreach (Font font in fonts) { - printer.Print(textBox1.Text, font, Color.White); + //printer.Print(textBox1.Text, font, Color.White); GL.Translate(0, font.Height + 5, 0); } diff --git a/Source/Examples/OpenTK/Test/GameWindowStates.cs b/Source/Examples/OpenTK/Test/GameWindowStates.cs index a20592db..c5f69843 100644 --- a/Source/Examples/OpenTK/Test/GameWindowStates.cs +++ b/Source/Examples/OpenTK/Test/GameWindowStates.cs @@ -12,7 +12,6 @@ using System.Drawing; using System.Threading; using OpenTK; -using OpenTK.Graphics; using OpenTK.Graphics.OpenGL; using OpenTK.Input; @@ -21,70 +20,91 @@ namespace Examples.Tests [Example("GameWindow states", ExampleCategory.OpenTK, "Test", Documentation="GameWindowStates")] public class GameWindowStates : GameWindow { - Font font = new Font(FontFamily.GenericSansSerif, 16.0f); - TextPrinter printer = new TextPrinter(); + readonly Font TextFont = new Font(FontFamily.GenericSansSerif, 16); + readonly Bitmap TextBitmap = new Bitmap(512, 512); + int texture; public GameWindowStates() : base(800, 600) { - this.VSync = VSyncMode.On; - this.Keyboard.KeyRepeat = true; - this.Keyboard.KeyUp += new OpenTK.Input.KeyUpEvent(Keyboard_KeyUp); + VSync = VSyncMode.On; + Keyboard.KeyUp += KeyUpHandler; - GL.ClearColor(System.Drawing.Color.MidnightBlue); + WindowBorderChanged += WindowBorderOrStateChangedHandler; + WindowStateChanged += WindowBorderOrStateChangedHandler; } - void Keyboard_KeyUp(KeyboardDevice sender, Key key) + void KeyUpHandler(KeyboardDevice sender, Key key) { switch (key) { - case OpenTK.Input.Key.Escape: - this.Exit(); - break; + case OpenTK.Input.Key.Escape: this.Exit(); break; - case Key.Number1: - WindowState = WindowState.Normal; - break; - case Key.Number2: - WindowState = WindowState.Maximized; - break; - case Key.Number3: - WindowState = WindowState.Fullscreen; - break; - case Key.Number4: - WindowState = WindowState.Minimized; - break; + case Key.Number1: WindowState = WindowState.Normal; break; + case Key.Number2: WindowState = WindowState.Maximized; break; + case Key.Number3: WindowState = WindowState.Fullscreen; break; + case Key.Number4: WindowState = WindowState.Minimized; break; - case Key.Number5: - WindowBorder = WindowBorder.Resizable; - break; - case Key.Number6: - WindowBorder = WindowBorder.Fixed; - break; - case Key.Number7: - WindowBorder = WindowBorder.Hidden; - break; + case Key.Number5: WindowBorder = WindowBorder.Resizable; break; + case Key.Number6: WindowBorder = WindowBorder.Fixed; break; + case Key.Number7: WindowBorder = WindowBorder.Hidden; break; } } + void WindowBorderOrStateChangedHandler(object sender, EventArgs e) + { + using (Graphics gfx = Graphics.FromImage(TextBitmap)) + { + gfx.Clear(Color.MidnightBlue); + gfx.TextRenderingHint = System.Drawing.Text.TextRenderingHint.ClearTypeGridFit; + + gfx.DrawString(String.Format("[1 - 4]: change WindowState (current: {0}).", this.WindowState), TextFont, Brushes.White, new PointF(0, 0)); + gfx.DrawString(String.Format("[5 - 7]: change WindowBorder (current: {0}).", this.WindowBorder), TextFont, Brushes.White, new PointF(0, TextFont.Height)); + } + + System.Drawing.Imaging.BitmapData data = TextBitmap.LockBits(new Rectangle(0, 0, TextBitmap.Width, TextBitmap.Height), + System.Drawing.Imaging.ImageLockMode.ReadOnly, System.Drawing.Imaging.PixelFormat.Format32bppArgb); + GL.TexSubImage2D(TextureTarget.Texture2D, 0, 0, 0, TextBitmap.Width, TextBitmap.Height, PixelFormat.Bgra, PixelType.UnsignedByte, data.Scan0); + TextBitmap.UnlockBits(data); + } + + public override void OnLoad(EventArgs e) + { + GL.ClearColor(Color.MidnightBlue); + + GL.Enable(EnableCap.Texture2D); + + texture = GL.GenTexture(); + GL.BindTexture(TextureTarget.Texture2D, texture); + GL.TexImage2D(TextureTarget.Texture2D, 0, PixelInternalFormat.Rgba, TextBitmap.Width, TextBitmap.Height, 0, PixelFormat.Bgra, PixelType.UnsignedByte, IntPtr.Zero); + GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMagFilter, (int)All.Nearest); + GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMinFilter, (int)All.Nearest); + + // Make sure text is displayed when the application starts. + WindowBorderOrStateChangedHandler(this, EventArgs.Empty); + } + protected override void OnResize(EventArgs e) { GL.Viewport(0, 0, Width, Height); + + Matrix4 ortho_projection = Matrix4.CreateOrthographicOffCenter(0, Width, Height, 0, -1, 1); + GL.MatrixMode(MatrixMode.Projection); + GL.LoadMatrix(ref ortho_projection); } protected override void OnRenderFrame(FrameEventArgs e) { GL.Clear(ClearBufferMask.ColorBufferBit); - printer.Begin(); + GL.Begin(BeginMode.Quads); - printer.Print("Instructions:", font, Color.White); - GL.Translate(0, font.Height, 0); - printer.Print(String.Format("[1 - 4]: change WindowState (current: {0}).", this.WindowState), font, Color.White, RectangleF.Empty); - GL.Translate(0, font.Height, 0); - printer.Print(String.Format("[5 - 7]: change WindowBorder (current: {0}).", this.WindowBorder), font, Color.White, RectangleF.Empty); + GL.TexCoord2(0, 0); GL.Vertex2(0, 0); + GL.TexCoord2(1, 0); GL.Vertex2(TextBitmap.Width, 0); + GL.TexCoord2(1, 1); GL.Vertex2(TextBitmap.Width, TextBitmap.Height); + GL.TexCoord2(0, 1); GL.Vertex2(0, TextBitmap.Height); - printer.End(); + GL.End(); SwapBuffers(); Thread.Sleep(5);