我刚开始学习 OpenTK,在阅读本教程时偶然发现了一个问题。
这是我尝试过的:
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)
{
}
}
}
Run Code Online (Sandbox Code Playgroud)
由于某种原因找不到 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
})
{ }
}
}
Run Code Online (Sandbox Code Playgroud)
或者创建一个静态工厂方法:
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)
{}
}
}
Run Code Online (Sandbox Code Playgroud)
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
})
{ }
}
}
Run Code Online (Sandbox Code Playgroud)