C# 我一使用OpenGL OpenTK就崩溃了

C# 我一使用OpenGL OpenTK就崩溃了,c#,opengl,opentk,C#,Opengl,Opentk,我正在使用OpenTK制作一个C#OpenGL应用程序 我尝试不使用GameWindow类打开上下文-以下是我的类管理的window+上下文: using OpenTK; using OpenTK.Graphics; using OpenTK.Graphics.OpenGL4; using OpenTK.Platform; using OpenTK.Input; class Window { private INativeWindow window_; private IGra

我正在使用OpenTK制作一个C#OpenGL应用程序

我尝试不使用GameWindow类打开上下文-以下是我的类管理的window+上下文:

using OpenTK;
using OpenTK.Graphics;
using OpenTK.Graphics.OpenGL4;
using OpenTK.Platform;
using OpenTK.Input;

class Window
{
    private INativeWindow window_;
    private IGraphicsContext context_;

    private bool isExiting_;

    public Window(int width, int height, bool fullscreen, string title = "StormEngine application")
    {
        window_ = new NativeWindow(width, height, title, fullscreen ? GameWindowFlags.Fullscreen : GameWindowFlags.FixedWindow, GraphicsMode.Default, DisplayDevice.Default);
        context_ = new GraphicsContext(GraphicsMode.Default, window_.WindowInfo, 4, 4, GraphicsContextFlags.Default);
        context_.MakeCurrent(window_.WindowInfo);
        window_.Visible = true;

        window_.KeyDown += (sender, e) =>
        {
            if (e.Keyboard[Key.Escape])
                window_.Close();
        };

        isExiting_ = false;
    }

    public Window(int width, int height) : this(width, height, false) { }

    public bool EndFrame()
    {
        context_.SwapBuffers();
        window_.ProcessEvents();
        return (window_.Exists && !isExiting_);
    }
}
然后我调用
windoww=newwindow(800480)打开一个窗口

但是只要我调用OpenGL方法,在我的例子中,
intprogramid=GL.CreateProgram(),我收到一个AccessViolationException

我的猜测是OpenGL函数指针没有正确加载,但是我找不到问题发生的地方(我没有得到关于
GL.CreateProgam()
中发生了什么的信息)


你知道会发生什么,为什么,以及如何解决吗?:)

算了吧,我发现了我的错误:)

在OpenTK中,GraphicsContext一旦创建并成为当前文本,就需要加载。 要执行此操作,请在
context\u.MakeCurrent(window\u.WindowInfo)之后,我补充道:

(context_ as IGraphicsContextInternal).LoadAll()
我必须从Github上的GameWindow类源代码中找到它,因为这种创建窗口的方法根本没有文档记录^^


现在它就像一个符咒

这听起来确实是一个奇怪的问题;您是否尝试打印出
CreateProgram
地址的内容?