1.安裝套件nuget Silk.NET套件
2.創建物件管理視窗
Silk_Player player=new Silk_Player();
Rect r=new (0,0,400,400);player.show(r);
程式碼:
using System.Threading; using Silk.NET.Input; using Silk.NET.Maths; using Silk.NET.Windowing; using Window = Silk.NET.Windowing.Window; using Silk.NET.OpenGL; public class Silk_Player { private IWindow window; private static GL Gl; //System.Drawing.Rectangle rect ==>left top width height public void show(System.Drawing.Rectangle rect) { var options = WindowOptions.Default; options.Position = new Vector2D<int>(rect.Left, rect.Top); //隱藏tilebar options.WindowBorder = WindowBorder.Hidden; options.Size = new Vector2D<int>(rect.Width, rect.Height); options.Title = "Silk.NET"; options.TopMost = true; window = Window.Create(options); window.Load += Window_Load; window.Render += Window_Render; window.Update += Window_Update; window.Run(); window.Dispose(); } private void Window_Load() { //鍵盤輸入設定 IInputContext input = window.CreateInput(); for (int i = 0; i < input.Keyboards.Count; i++) { input.Keyboards[i].KeyDown += Silk_Player_KeyDown; } Gl = GL.GetApi(window); Gl.ClearColor(1, 0, 0, 1); } private void Silk_Player_KeyDown(IKeyboard arg1, Key arg2, int arg3) { if (arg2 == Key.Escape) { window.Close(); } } private void Window_Update(double obj) { } private void Window_Render(double obj) { Gl.Clear(ClearBufferMask.ColorBufferBit); } }
沒有留言:
張貼留言