この文書の現在のバージョンと選択したバージョンの差分を表示します。
— |
c.sharp:opentk_graphics_textprinter [2018/04/27 22:41] (現在) fifi 作成 |
||
---|---|---|---|
ライン 1: | ライン 1: | ||
+ | OpenTK.Comtibility.dllを使用した | ||
+ | OpenTK.Graphics.TextPrinterは | ||
+ | メモリリークの可能性があるため使用を中断 | ||
+ | |||
+ | |||
+ | 備忘録としてコードは残す | ||
+ | |||
+ | ```c | ||
+ | using OpenTK.Graphics.OpenGL; | ||
+ | using System; | ||
+ | using System.Drawing; | ||
+ | |||
+ | namespace TapVisualizer1.Views | ||
+ | { | ||
+ | class FrontTextView | ||
+ | { | ||
+ | string BaseText = ""; | ||
+ | OpenTK.Graphics.TextPrinter text = new OpenTK.Graphics.TextPrinter(OpenTK.Graphics.TextQuality.High); | ||
+ | |||
+ | |||
+ | public void AddTxt(string txt) | ||
+ | { | ||
+ | this.BaseText += txt; | ||
+ | } | ||
+ | |||
+ | public void ClearTxt() | ||
+ | { | ||
+ | this.BaseText = ""; | ||
+ | |||
+ | } | ||
+ | |||
+ | public void Render(int Width, int Height, RectangleF drawRect) | ||
+ | { | ||
+ | // ******** Font settings | ||
+ | float size1 = Height / 50f; | ||
+ | size1 = (float)Math.Min(size1, 15); | ||
+ | Font printerFont1 = new Font(FontFamily.GenericMonospace, size1); | ||
+ | |||
+ | //******** Camera | ||
+ | GL.MatrixMode(MatrixMode.Projection); | ||
+ | GL.PushMatrix(); // 上書きするなら必要 | ||
+ | GL.LoadIdentity(); | ||
+ | GL.MatrixMode(MatrixMode.Modelview); | ||
+ | GL.PushMatrix(); // 上書きするために必要 | ||
+ | GL.LoadIdentity(); | ||
+ | |||
+ | GL.Viewport(0, 0, Width, Height); // 画面内に描画するサイズ | ||
+ | GL.Ortho(0, Width, Height, 0, -1, 1); // 画面内の座標 | ||
+ | |||
+ | // ******** Text Rendering | ||
+ | text.Begin(); | ||
+ | text.Print(this.BaseText, printerFont1, Color.DimGray, drawRect, OpenTK.Graphics.TextPrinterOptions.NoCache); | ||
+ | text.End(); | ||
+ | |||
+ | // ******** This is equivalent: | ||
+ | GL.MatrixMode(MatrixMode.Modelview); | ||
+ | GL.PopMatrix(); | ||
+ | GL.MatrixMode(MatrixMode.Projection); | ||
+ | GL.PopMatrix(); | ||
+ | // ******** End | ||
+ | |||
+ | printerFont1.Dispose(); | ||
+ | } | ||
+ | } | ||
+ | } | ||
+ | |||
+ | |||
+ | ``` |