问题
Im working on a program which should have multiple views of a model. I would like to use multiple
GLControls` for that.
Is there any possibility to create multiple GLControl which use the same GraphicsContext?
I successfully created this on a multithreaded enviroment, but the contexts are not shared then. So I have to load the model for each context, which is bad.
My pseudocode for a single threaded enviroment looks something like this:
glControl1.MakeCurrent();
// Render here
glControl1.SwapBuffers();
glControl2.MakeCurrent();
// Render here too
glControl2.SwapBuffers();
I tried this by creating multiple contexts on the thread but it crashed with
Error: 170" at "MakeCurrent()
of glControl2
. (Even glControl2.Context.MakeCurrent(null)
before switching the context didn`t work)
Maybe you have some hints which can help me.
回答1:
Right after I posted this question I found the solution.
I created a new GraphicsContext on the thread I want to render my stuff.
//Here does a new thread start->
IGraphicsContext control2Context = new GraphicsContext(GraphicsMode.Default,glControl2.WindowInfo);
while(true)
{
glControl1.MakeCurrent()
//render
GL.Flush();
glControl1.SwapBuffers();
control2Context.MakeCurrent(glControl2.WindowInfo);
//render
GL.Flush();
glControl2.SwapBuffers();
}
As you can see, I'm not using glControl2.MakeCurrent()
. Instead I created this new context control2Context
.
Maybe this can help someone who is facing the same problem.
来源:https://stackoverflow.com/questions/40578910/opentk-multiple-glcontrol-with-a-single-context