GLControl icon indicating copy to clipboard operation
GLControl copied to clipboard

Multiple GL Controls

Open sdreb3421 opened this issue 3 years ago • 10 comments

I've been unable to get multiple GLControls to work in a single WinForms application. My goal is to have multiple tabs/windows that each show the same 3D scene but from different angles. Ideally they would share context/data, but separate contexts would be okay too. Is this possible? Not sure if this is a bug or intended behavior.

sdreb3421 avatar Dec 28 '22 01:12 sdreb3421

What version of GLControl are you using?

NogginBops avatar Dec 29 '22 14:12 NogginBops

I'm using 4.0.0-pre.6 with a Windows Forms NET 7 build for Windows. However, I believe I tried this unsuccessfully many years ago with version 3 as well.

sdreb3421 avatar Dec 29 '22 18:12 sdreb3421

Sorry for the very delayed answer, but have you tried looking at the multi-form example project that exists in this repo?

NogginBops avatar Oct 09 '23 22:10 NogginBops

Oh no i haven't. The example shows multiple GL controls on multiple forms I'm assuming? Thanks

sdreb3421 avatar Oct 09 '23 22:10 sdreb3421

Yeah, it does. If you run into any problems feel free to ask any questions here.

I've just recently fixed the build system for this repo so I'll be able to do some work on it, so I expect that I'll update the sample projects soon to use more modern OpenGL. There I can look at maybe making the multi-control sample better (if it isn't fine already).

NogginBops avatar Oct 09 '23 22:10 NogginBops

I've just updated the multi control sample to make use of modern OpenGL and context sharing (#35 ). This should help in getting multiple GLControls to run at the same time.

NogginBops avatar Oct 10 '23 18:10 NogginBops

Wow awesome, this is what I've always dreamed of!

sdreb3421 avatar Oct 10 '23 18:10 sdreb3421

The context sharing part isn't really possible to conveniently achieve without the change I made to GLControl in #35 so for that you'll have to wait for the next release.

A workaround until then would be to make your own subclass GLControl and override OnHandleCreated with the following code

protected override void OnHandleCreated(EventArgs e)
{
    if (SharedContext != null)
    {
        if (SharedContext._nativeWindow == null)
        {
            throw new InvalidOperationException("The GLControl set as the shared context to this GLControl is not yet initialized. Initialization order when sharing contexts is important.");
        }

        _glControlSettings.SharedContext = SharedContext.Context;
    }

    base.OnHandleCreated(e);
}

NogginBops avatar Oct 10 '23 18:10 NogginBops

Okay good to know. I just saw you did a prerelease of the winforms package. Is that what I need? Or the next release of opentk? Thanks

sdreb3421 avatar Oct 10 '23 18:10 sdreb3421

To get the multi control test working you either need to download the source as it is right now, or wait for the next version of GLControl. GLControl 4.0.0-pre.7 does not have the fix I implemented in #35 so the workaround is needed when using that package version.

NogginBops avatar Oct 10 '23 19:10 NogginBops

I have just released OpenTK.GLControl 4.0.0 which has this fix in it, and is the first stable release of OpenTK.GLControl (then OpenTK.WinForms) for OpenTK 4.x!

Closing this, if you have any problems with the released package feel free to repoen this issue!

NogginBops avatar Sep 03 '24 16:09 NogginBops

Great work, thank you!

sdreb3421 avatar Sep 03 '24 17:09 sdreb3421