Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Multiple GL Controls #31

Open
sdreb3421 opened this issue Dec 28, 2022 · 10 comments
Open

Multiple GL Controls #31

sdreb3421 opened this issue Dec 28, 2022 · 10 comments
Labels
4.0 needs verification question Further information is requested
Milestone

Comments

@sdreb3421
Copy link

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
Copy link
Member

What version of GLControl are you using?

@NogginBops NogginBops added the question Further information is requested label Dec 29, 2022
@sdreb3421
Copy link
Author

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
Copy link
Member

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

@sdreb3421
Copy link
Author

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

@NogginBops
Copy link
Member

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
Copy link
Member

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 NogginBops added this to the 4.0 milestone Oct 10, 2023
@sdreb3421
Copy link
Author

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

@NogginBops
Copy link
Member

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
Copy link
Author

sdreb3421 commented Oct 10, 2023

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
Copy link
Member

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
4.0 needs verification question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants