刚开始学习OpenTK,在浏览this tutorial的时候发现了一个问题.
这是我尝试过的:
using System;
using OpenTK;
using OpenTK.Graphics;
using OpenTK.Windowing.Desktop;
using OpenTK.Windowing.GraphicsLibraryFramework;
namespace Testing
{
public class GraphicsWindow : GameWindow
{
public GraphicsWindow(int width, int height, string title) : base(width, height, GraphicsMode.Default, title)
{
}
}
}
由于某种原因找不到 Enum GraphicsMode(应该在命名空间 OpenTK.Graphics 中找到)。另一个是 GameWindow 没有带 4 个参数的构造函数。我已经安装了最新版本的 OpenTK Nuget 包 (4.0.6)。我创建的项目面向 .NET Core。
有任何想法吗?
最佳答案
本教程基于为 .NET 框架编写的 OpenTK 3.x。 OpenTK 4.x 是为 .NET 核心编写的。在 3.x 中 GameWindow
是 OpenTK.Graphics
的一部分命名空间。现在该类包含在 OpenTK.Windowing.Desktop
中并且行为不同。构造函数有 2 个参数,GameWindowSettings
和 NativeWindowSettings
.
namespace Testing
{
public class GraphicsWindow : GameWindow
{
public GraphicsWindow(int width, int height, string title)
: base(
new GameWindowSettings(),
new NativeWindowSettings()
{
Size = new OpenTK.Mathematics.Vector2i(width, height),
Title = title
})
{ }
}
}
或者创建一个静态工厂方法:namespace Testing
{
public class GraphicsWindow : GameWindow
{
public static GraphicsWindow New(int width, int height, string title)
{
GameWindowSettings setting = new GameWindowSettings();
NativeWindowSettings nativeSettings = new NativeWindowSettings();
nativeSettings.Size = new OpenTK.Mathematics.Vector2i(width, height);
nativeSettings.Title = title;
return new GraphicsWindow(setting, nativeSettings);
}
public GraphicsWindow(GameWindowSettings setting, NativeWindowSettings nativeSettings)
: base(setting, nativeSettings)
{}
}
}
var myGraphicsWindow = GraphicsWindow.New(800, 600);
另见 OpenTK_hello_triangle
关于c# - OpenTK:为什么 GraphicsMode 不可用?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64534969/