目前,我一直在制作C#-WPF-OpenGL应用程序。我遵循了此http://www.codeproject.com/Articles/265903/Using-OpenGL-in-a-WPF-Application教程,并且能够运行示例项目。但是,第一次调用不属于OpenGL 1.1.0的函数失败,即我的代码如下所示

private void OpenGLControl_OpenGLInitialized(object Sender, OpenGLEventArgs args)
{
OpenGL gl = args.OpenGL;

GLuint glError;
while ( (glError = gl.GetError()) != OpenGL.GL_NO_ERROR )
{
    Console.WriteLine( gl.GetErrorDescription(glError) );
}

Console.WriteLine( gl.GetString(OpenGL.Version) ); //Prints out 1.1.0

GLuint hVertexShader;
hVertexShader = gl.CreateShader(OpenGL.GL_VERTEX_SHADER);//Compiles, but raises an exception, also would gl.CreateProgramm() or other functions



}


不知何故,此链接https://github.com/dwmkerr/sharpgl/wiki/Specifying-OpenGL-Version不能帮助我将Version设置为4.2。
那么我该如何实现呢?

最佳答案

解决了!我在MainWindow.xaml中缺少RenderingContext =“ FBO”,就像这样

<sharpGL:OpenGLControl
        Name="openGLControl"
        OpenGLDraw="OpenGLControl_OpenGLDraw"
        OpenGLInitialized="openGLControl_OpenGLInitialized"
        Resized="openGLControl_Resized"
        KeyDown="OnKeyDownHandler"
        Mouse.MouseWheel="MouseWheelEventHandler"
        DrawFPS="True" RenderContextType="FBO" FrameRate="20"/>

10-08 03:37