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

Is there any way set GLControl background Transparent? #27

Open
ToukiLiu opened this issue Aug 25, 2022 · 6 comments
Open

Is there any way set GLControl background Transparent? #27

ToukiLiu opened this issue Aug 25, 2022 · 6 comments
Labels
4.0 enhancement New feature or request
Milestone

Comments

@ToukiLiu
Copy link

I'm opengl beginer.
And I'm trying to let GLControl overlap on other UserControls, to show both of GLControl's element and bottom UserControl's element.
But GLContorl's background Transparent is not work.
Both of

m_glc = new GLControl();
winform.Child = m_glc;
winform.Child.BackColor = System.Drawing.Color.Transparent;

and

GL.ClearColor(0.0f, 0.0f, 0.0f, 0.0f);

didn't work.

Is there any way set GLControl background Transparent?

@NogginBops
Copy link
Member

I'm not sure if this is possible atm. It would at least require the backbuffer to have some alpha bits in the settings for the control. But I'm not sure if that is enough.

@seanofw
Copy link
Collaborator

seanofw commented Sep 5, 2022

This is hard, and in most cases it requires a lot of complicated code to interact directly with the underlying window system. On Windows, you'll need to write a number of Windows-specific DWM API calls to indicate how the window compositing should work, as described in the answers to this StackOverflow question. I'm not sure what's required on X (apparently a number of glXFBConfig calls?) or on MacOS, but I'd suspect its nontrivial.

Either way, it's way outside the scope of the OpenTK project, which currently exposes the underlying window system mostly as GLFW provides access to it. Even future versions of OpenTK are very unlikely to support this, given how complex and nonportable it is.

@seanofw seanofw closed this as completed Sep 5, 2022
@seanofw seanofw added the wontfix This will not be worked on label Sep 5, 2022
@NogginBops
Copy link
Member

Making a transparent OpenGL window on windows only requires talking to WGL from what I've read from WGL documentation. GLFW supports creating transparent framebuffers, though I'm unsure if this control uses the GLFW context or some other trickery.

I've not tried enabling the GLFW transparent framebuffer feature in combination with this control, but there is a slight chance it would work. I've not looked into the code for this control thoroughly enough to be able to judge this. But I think it's definitely worth a try.

This is something that will definitely be supported by the PAL 2.0 windowing system (at least as a platform specific windows feature enable). Though that is a long long time from being ready for release.

@NogginBops NogginBops reopened this Sep 5, 2022
@NogginBops NogginBops removed the wontfix This will not be worked on label Sep 5, 2022
@seanofw
Copy link
Collaborator

seanofw commented Sep 5, 2022

Reading through the GLFW source code, it does look like they attempt to call the appropriate DWM APIs if you use their transparency. I didn't check to see if it uses the correct PFD flags. I can't really place any bets about what would happen if you used them with this, though, given that there's an outer window that acts as a "container" for the GLFW window under WinForms, and the outer may need to have compositing enabled on it too.

Either way, it's more than just the WGL functions: The desktop compositor needs to get involved too if you want to be able to see what's behind your window on modern Windows.

The PAL in OpenTK 5 may be able to support transparency, but it'll still need a bunch of new code to wrap it to support WinForms, so the same issue may exist there too if we're not careful about how the PAL is implemented.

@NogginBops
Copy link
Member

Absolutely, I just think we shouldn't close the issue without trying.
And if it's not possible with OpenTK 4 we should still track this for OpenTK 5 so we know it's an issue we should consider at some point.

@NogginBops NogginBops added this to the 4.0 milestone Oct 10, 2023
@NogginBops NogginBops added enhancement New feature or request 4.0 labels Oct 10, 2023
@NogginBops
Copy link
Member

Will look into this for 4.0 but it'll likely not be very simple to achieve, so it's likely it won't get into 4.0.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
4.0 enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants