简体   繁体   English

OpenTK多线程?

[英]OpenTK multithreading?

Is there a way to draw to the screen using OpenTK/OpenGL in another thread? 有没有办法在另一个线程中使用OpenTK / OpenGL绘制到屏幕上? The code I'm trying to use is 我正在尝试使用的代码是

GL.Clear(ClearBufferMask.ColorBufferBit);
GL.ClearColor(Color.Black);

GL.Begin(PrimitiveType.Quads);

GL.Color3(Color.FromArgb(255, 0, 0));
GL.Vertex2(-1, 1);
GL.Color3(Color.FromArgb(0, 255, 0));
GL.Vertex2(1, 1);
GL.Color3(Color.FromArgb(0, 0, 255));
GL.Vertex2(1, -1);
GL.Color3(Color.FromArgb(0, 255, 255));
GL.Vertex2(-1, -1f);

GL.End();
SwapBuffers();

The code above works in the same thread the GameWindow was created in but not when called from another thread. 上面的代码在与GameWindow创建所在的线程相同的线程中工作,但从另一个线程调用时无效。

I was able to swap the thread OpenGL accepts with this code 我可以用此代码交换OpenGL接受的线程

thread = new Thread(() =>
{
    IGraphicsContext context = new GraphicsContext(GraphicsMode.Default, window.WindowInfo);
    context.MakeCurrent(window.WindowInfo);
    //Render code here
}).Start();

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM