OpenTK 多线程?
OpenTK multithreading?
有没有办法在另一个线程中使用 OpenTK/OpenGL 绘制到屏幕上?
我尝试使用的代码是
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();
上面的代码在创建 GameWindow 的同一个线程中工作,但在从另一个线程调用时则不然。
我能够用这段代码交换 OpenGL 接受的线程
thread = new Thread(() =>
{
IGraphicsContext context = new GraphicsContext(GraphicsMode.Default, window.WindowInfo);
context.MakeCurrent(window.WindowInfo);
//Render code here
}).Start();
有没有办法在另一个线程中使用 OpenTK/OpenGL 绘制到屏幕上? 我尝试使用的代码是
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();
上面的代码在创建 GameWindow 的同一个线程中工作,但在从另一个线程调用时则不然。
我能够用这段代码交换 OpenGL 接受的线程
thread = new Thread(() =>
{
IGraphicsContext context = new GraphicsContext(GraphicsMode.Default, window.WindowInfo);
context.MakeCurrent(window.WindowInfo);
//Render code here
}).Start();