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.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)
{
}
}
}
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.
I have installed the latest version of the OpenTK Nuget package (4.0.6). The project I created targets .NET Core.
Any ideas?
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);
See also OpenTK_hello_triangle
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With