我正在使用OpenTK创建一个C# OpenGL应用程序。
我试图不使用GameWindow类打开上下文-下面是我的类管理一个窗口+上下文:
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_);
}
}然后我打电话给Window w = new Window(800, 480);来打开一个窗口。
但是,当我调用OpenGL方法(在我的例子中是int programId = GL.CreateProgram(); )时,就会得到一个AccessViolationException。
我的猜测是,OpenGL函数指针没有正确加载,但我找不到问题发生的地方(我没有得到关于GL.CreateProgam()内部发生什么的信息)。
知道会发生什么,为什么,以及如何解决这个问题吗?:)
发布于 2014-07-01 17:07:16
算了吧,我发现了我的错误:)
在OpenTK中,一旦创建并使GraphicsContext成为当前,就需要加载它。为了做到这一点,在context_.MakeCurrent(window_.WindowInfo);之后,我添加了:
(context_ as IGraphicsContextInternal).LoadAll()我不得不从Github,tho上的GameWindow类源代码中找出它,因为这种创建窗口的方法根本没有文档化^^
现在它就像一种魅力。:)
https://stackoverflow.com/questions/24508343
复制相似问题