opentk / GLControl

WinForms control for OpenTK 4.x.
https://opentk.net
Other
54 stars 24 forks source link

Multiple GL Controls #31

Closed sdreb3421 closed 4 days ago

sdreb3421 commented 1 year ago

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.

NogginBops commented 1 year ago

What version of GLControl are you using?

sdreb3421 commented 1 year ago

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.

NogginBops commented 11 months ago

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

sdreb3421 commented 11 months ago

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

NogginBops commented 11 months ago

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 commented 11 months ago

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.

sdreb3421 commented 11 months ago

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

NogginBops commented 11 months ago

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);
}
sdreb3421 commented 11 months ago

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

NogginBops commented 11 months ago

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 commented 4 days ago

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!

sdreb3421 commented 4 days ago

Great work, thank you!