OpenTK:为什么 GraphicsMode 不可用? [英] OpenTK: Why is GraphicsMode not available?

查看:101
本文介绍了OpenTK:为什么 GraphicsMode 不可用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚开始学习 OpenTK,在浏览 本教程.

I just started to learn OpenTK and stumbled upon a problem when going through 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 个参数的构造函数.

The Enum GraphicsMode is not found for some reason (should be found in namespace OpenTK.Graphics). Another one is that GameWindow does not have a constructor taking 4 arguments.

我已经安装了最新版本的 OpenTK Nuget 包 (4.0.6).我创建的项目面向 .NET Core.

I have installed the latest version of the OpenTK Nuget package (4.0.6). The project I created targets .NET Core.

有什么想法吗?

推荐答案

本教程基于 OpenTK 3.x,它是为 .NET 框架编写的.OpenTK 4.x 是为 .NET 核心编写的.在 3.x 中,GameWindowOpenTK.Graphics 命名空间的一部分.现在该类包含在 OpenTK.Windowing.Desktop 中并且表现不同.构造函数有 2 个参数,GameWindowSettingsNativeWindowSettings.

The tutorial is based on OpenTK 3.x, which was written for .NET framwork. OpenTK 4.x is written for .NET core. In 3.x the GameWindow was part of the OpenTK.Graphics namespace. Now the class is contained in OpenTK.Windowing.Desktop and behaves different. The constructor has 2 arguments, GameWindowSettings and 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
                  })
            { }
    }
}

或者创建一个静态工厂方法:

Alternatively create a static factory method:

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

这篇关于OpenTK:为什么 GraphicsMode 不可用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆