4

Im working on a program which should have multiple views of a model. I would like to use multipleGLControls` 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.

Rabbid76
  • 202,892
  • 27
  • 131
  • 174
bitQUAKE
  • 473
  • 1
  • 8
  • 19

1 Answers1

6

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.

Rabbid76
  • 202,892
  • 27
  • 131
  • 174
bitQUAKE
  • 473
  • 1
  • 8
  • 19
  • Please comment my answer if there is something wrong. If everything is fine, I´ll mark it as the answer. – bitQUAKE Nov 13 '16 at 21:33
  • 1
    can you please help me on this, I have already used above line of code. But still only one glcontrol is working at a time – nsds May 27 '19 at 08:52