OpenTK: 为什么无法使用GraphicsMode?

4

我刚开始学习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)
        {
            
        }
    }
}

出现了一些问题,未能找到Enum GraphicsMode(应该在OpenTK.Graphics命名空间中找到)。另外一个是GameWindow没有带有4个参数的构造函数。

我安装了最新版本的OpenTK Nuget包(4.0.6)。我创建的项目以.NET Core为目标。

有什么想法吗?

1个回答

7

该教程基于OpenTK 3.x,该版本是为.NET Framework编写的。OpenTK 4.x是为.NET Core编写的。在3.x中,GameWindowOpenTK.Graphics命名空间的一部分。现在该类包含在OpenTK.Windowing.Desktop中,并具有不同的行为。构造函数有2个参数:GameWindowSettingsNativeWindowSettings

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

1
OpenTK 4.x 有任何教程吗? - kirant400
@Justiciar 我在 GitHub 存储库 Rabbid76/c_sharp_opengl 中有一些示例。 - Rabbid76

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接