Disabled TextPrinter samples.

Removed TextPrinter references.
This commit is contained in:
the_fiddler 2009-08-17 09:32:50 +00:00
parent 14f963b257
commit 878dd4394c
3 changed files with 65 additions and 44 deletions

View file

@ -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
/// <summary>
/// Shows how to render and scroll large amounts of text.
/// </summary>
@ -159,4 +159,5 @@ namespace Examples.Tutorial
#endregion
}
#endif
}

View file

@ -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<Font> fonts = new List<Font>();
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);
}

View file

@ -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);