2014-01-10 35 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()返回後的情況。

相關問題