Soundbomber's picture

Multiple OpenTK.GLControls

I would like to produce a control with 3, possibly 4 OpenTK.GLControls to replicate different view ports.
For example, a plan view of my objects in control1, a front elevation in control2 etc.
I have set up my custom control with 4 OpenTK.GLControls but am having difficulty displaying anything on all but one.
How would I set up multiple viewpoints when I only have one OpenGL class to use when setting views with the GL.Ortho command?
Could anyone recommend if this is the correct approach?


Comments

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
the Fiddler's picture
Quote:

How would I set up multiple viewpoints when I only have one OpenGL class to use when setting views with the GL.Ortho command?

I am not sure what you mean by this.

In OpenGL, all commands are directed to the "current" context. Only one context can be current on a single thread and each GLControl comes with its own context. What you have to do, is call GLControl.MakeCurrent any time you wish to use OpenGL commands.

A rough outline would look like this:

class MainForm : Form
{
    // Assume you have created 4 GLControls through the designer:
    // glControl1, glControl2, glControl3, glControl4;
 
    public MainForm()
    {
        InitializeComponents();
    }
 
    void glControl1_Resize(object sender, EventArgs e)
    {
        glControl1.MakeCurrent();
        GL.MatrixMode(MatrixMode.Projection);
        GL.LoadIdentity();
        GL.Ortho(...);
    }
 
    void glControl2_Resize(object sender, EventArgs e)
    {
        glControl2.MakeCurrent();
        GL.MatrixMode(MatrixMode.Projection);
        GL.LoadIdentity();
        GL.Ortho(...);
    }
    ...
    void glControl1_Paint(object sender, PaintEventArgs e)
    {
        glControl1.MakeCurrent();
        ...
        glControl1.SwapBuffers();
    }
 
    void glControl2_Paint(object sender, PaintEventArgs e)
    {
        glControl2.MakeCurrent();
        ...
        glControl2.SwapBuffers();
    }
    ...
}
Soundbomber's picture

Thanks for the (very) swift reply!
That is exactly it. I have just been skimming through a few web searches, would another solution possibly be to use a single control and render 4 different views?
Are either of these solutions preferable?

the Fiddler's picture

It depends on your approach to the interface. If you are planning to implement an MDI approach, where each viewport is a different window, then multiple GLControls are the easiest way.

On the other hand, if all 4 viewports will be side by side then it's simpler to use a single GLControl and render using four different viewports.

Soundbomber's picture

Thanks for your help.
Think I will go with multiple controls. I like the added control I have over the interface.