luca-piccioni / OpenGL.Net

Modern OpenGL bindings for C#.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Transparent background in WPF+WinFormsHost

bigboynaruto opened this issue · comments

Hi! I was wondering if it's possible to make GlControl's background transparent, so the parent WPF-control would be visible through it? Setting BackColor to something with alpha=0 doesn't seem to work.

commented

Short answer is no due to the Airgap issue. Long answer: https://blogs.msdn.microsoft.com/dwayneneed/2013/02/26/mitigating-airspace-issues-in-wpf-applications/

Alternative solution: Use FBO's to render to a WritableBitmap used an an ImageSource in an Image element within WPF.
See here for a basic POC: https://gist.github.com/DanFTRX/504be5c6e17098b86ef12342cd50c32d

Using a WriteableBitmap allows you to overlay things on top of it and otherwise manipulate the control the same as any other WPF Control. It does come at the cost of some performance though, but should be negligable in most cases.

Thanks a lot, I'll look into it.