问题描述
我正在使用opentk在C#.Net Core中编写图形控制台应用程序。我这样继承了GameWindow
类:
class OpenGLWindow:GameWindow
{
public OpenGLWindow(GameWindowSettings gws,NativeWindowSettings nws):base(gws,nws)
{
}
//other overloaded methods here
}
然后我在main方法中创建了这样的窗口:
Console.WriteLine("Hello World!");
NativeWindowSettings settings = NativeWindowSettings.Default;
settings.Title = "Befiker";
settings.APIVersion = new Version(4,6);
GameWindowSettings gws = new GameWindowSettings();
gws.RenderFrequency = 60.0;
using(var win = new OpenGLWindow(gws,settings))
{
win.Run();
}
Console.ReadKey();
该窗口已创建,但我注意到它没有清除缓冲区位。我确定这是因为我尚未创建opengl上下文。 NativeWindowSettings
类采用SharedContext
,其类型为IGLFWGraphics上下文。这就是我卡住的地方。我在c ++上使用了glfw和opengl 4.6,并且窗口创建处理了上下文创建。所以我不知道如何创建上下文。有人可以帮忙吗?
解决方法
我在这里犯了一个错误。我忘了包括两个功能。一种是swapbuffer()。和 另一个是makecurrent()。包括所有这些之后,所有的opengl函数都可以正常工作。 这意味着GameWindow类自己创建了一个opengl上下文。我仍然不清楚nativewindowsettings类object.sharedcontext的用途。