2014-01-10 55 views
0

我试图用Tao.FreeGlut 2.1.0到初始化的窗口,并与OpenTK 1.1 drawind,所以我做简单的程序:我可以让OpenTK和Tao.FreeGlut一起工作吗?

public static void Main() 
{ 
    Glut.glutInit(); 
    Glut.glutInitDisplayMode(Glut.GLUT_DOUBLE | Glut.GLUT_RGBA); 
    Glut.glutInitWindowSize(1024, 768); 
    Glut.glutInitWindowPosition(100, 100); 
    Glut.glutCreateWindow("Test"); 
    Glut.glutDisplayFunc(RenderScene); 

    GL.ClearColor(0.0f, 0.0f, 0.0f, 0.0f); 

    Glut.glutMainLoop(); 
} 

public static void RenderScene() 
{ 
    GL.Clear(ClearBufferMask.ColorBufferBit); 
    Glut.glutSwapBuffers(); 
} 

但在GL.ClearColor调用它与空REF异常崩溃。 我认为,发生这种情况是因为OpenTK存储了它自己的OpenGL上下文,并且它不等于由Glut创建的上下文并且没有正确初始化。我没有发现任何方式从转运蛋白获取上下文,然后我试着这样做:

IWindowInfo window = Utilities.CreateWindowsWindowInfo(Glut.glutGetWindowData()); 
GraphicsContext context = new GraphicsContext(GraphicsMode.Default, window); 
context.MakeCurrent(window); 
context.LoadAll(); 

而现在它崩溃的背景下创作的,反正窗口不正确的OpenTK。

那么有没有办法解决它,并使用谷歌与OpenTK?或者我不能使用Glut并使用OpenTK方法创建窗口和上下文?

回答

0

是的,这是可能的。从documentation

Glut.glutCreateWindow("Test"); 

// Initialize OpenTK using the current GLUT context 
var opentk_context = new GraphicsContext(ContextHandle.Zero, null); 

// You can now call GL functions freely 
GL.ClearColor(0.0f, 0.0f, 0.0f, 0.0f); 

注意过剩背景下,必须创建和电流,当你调用new GraphicsContext()。根据freeglut documentation,这是glutCreateWindow()返回后的情况。

相关问题