首页 > 解决方案 > 使用 GLFW 或 openTK GameWindow 创建窗口

问题描述

要创建一个窗口,我必须找到两种方法:

1.- 使用全新的基于 GLFW 的窗口和输入系统:

class Program {
    static unsafe void Main(string[] args) {
      GLFW.Init();
      Window* window = GLFW.CreateWindow(800, 800, "GLFW", null, null);

      while (!GLFW.WindowShouldClose(window)) {

        GLFW.SwapBuffers(window);
        GLFW.PollEvents();
      }
  }

2.- 使用此处的创建窗口教程方法,稍微更改代码。

class Program {
    static unsafe void Main(string[] args) {    
      using (Game game = new Game(800, 600, "LearnOpenTK"))  {
        //Run takes a double, which is how many frames per second it should strive to reach.
        //You can leave that out and it'll just update as fast as the hardware will allow it.
        game.Run();
      }
    }
  }

作为 Game 类(从教程源代码稍微更正了代码):

public class Game: GameWindow
{
  public Game(int width, int height, string title) : base(GameWindowSettings.Default, NativeWindowSettings.Default) { }
  protected override void OnUpdateFrame(FrameEventArgs e) {
    //KeyboardState input = Keyboard.GetState();

    if (IsKeyDown(Keys.Escape))
    {
      //Exit();
      Close();
    }
    base.OnUpdateFrame(e);
  }
}

一方面,我从一些 c++ 冒险中熟悉 GLFW 库和输入系统,但不知道处理不安全代码的想法。虽然我可能熟悉 c++ 内存管理和指针,但我不熟悉 c#。而且这是一个非常成熟的窗口+输入库。

另一方面,openTK 窗口 + 输入方法似乎非常简单,这是教程中建议的方法,显然更好地嵌入到 openTK 中。

关于可能支持一个窗口+输入系统或另一个的事实的任何警告或利弊?

标签: c#inputwindowglfwopentk

解决方案


推荐阅读