OpenTK: Why is GraphicsMode not available?

后端 未结 1 924
青春惊慌失措
青春惊慌失措 2021-01-22 13:10

I just started to learn OpenTK and stumbled upon a problem when going through this tutorial.

This is what I tried:

using System;
using OpenTK;
using OpenTK         


        
相关标签:
1条回答
  • 2021-01-22 14:11

    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);
    
    0 讨论(0)
提交回复
热议问题