c# - 使用 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 中。
关于可能支持一个窗口+输入系统或另一个的事实的任何警告或利弊?
解决方案
推荐阅读
- macos - 以 Root/SecurityAgent 用户身份运行/注册应用程序以使其可全局访问
- sql - MS Access 布尔字段和默认 (True) 值
- docker - 在本地和 K8S 中运行 Docker 容器中的 Azure Function Service Bus Trigger
- python - 如何从 python networkX 中的列表列表中访问元素?TypeError:“int”对象不可迭代
- node.js - 如何在 Django 中集成 Node JS?
- ruby-on-rails - 未定义的方法 strftime
- debugging - 在 VS Code 的调试控制台中输入防止自动完成选择
- visual-studio-2019 - Visual Studio Intellisense 无法识别 C#9 功能
- python - 仅在本地 GPU 上的低 CNN 精度
- python - 检查 Python 列表项是否在另一个字符串中包含一个字符串但有条件