1

We're developing Windows desktop app with full-screen OpenGL graphics. Now we want to display a bunch of controls over the OpenGL (arrows, buttons, etc.) It turns out it is very difficult to do that.

The majority of tutorials suggest using WindowsFormsHost for OpenGL rendering, and we did so: http://www.codeproject.com/Articles/23736/Creating-OpenGL-Windows-in-WPF

Unfortunately now we cannot draw WPF controls over WindowsFormsHost, there's a lot of discussion about this all over the internet too: WindowsFormsHost is always the most top from WPF element Render WPF control on top of WindowsFormsHost

There are some hacks that can work around this, but they all seem very dirty. Is there a proper way to draw OpenGL directly in WPF without messing with Windows Forms? (I just have no idea why you cannot have this in WPF directly).

In short: is there a known solution for drawing UI over OpenGL in WPF applications?

Community
  • 1
  • 1
Aleksei Petrenko
  • 6,698
  • 10
  • 53
  • 87
  • 1
    How about rendering your control to a bitmap target and then updating a GL texture from that? – GlGuru May 22 '15 at 13:57
  • You mean render all my buttons, labels etc. to bitmaps and then render them in OpenGL with the rest of my graphics? That's what I usually call "dirty hacks" :) If there is a way to avoid this I'd be happy. – Aleksei Petrenko May 22 '15 at 14:37
  • 1
    Dwayne Need managed to resolve this problem. I haven't looked at his solution though. Also, what we do is to simply popup a borderless WPF `Window` above the GL content, and track it's position so the window's location is always "on top of" the GL content. – Federico Berasategui May 22 '15 at 14:48
  • Yeah, that's what we will most likely end up with. Can you share a link to Dwayne Need's work? – Aleksei Petrenko May 22 '15 at 15:34
  • 1
    It's not a hack. This is a fairly standard way of displaying stuff on graphics windows. This is very similar to how it's actually done as well. – GlGuru May 22 '15 at 18:32
  • 1
    Why not to use Qt SDK ? – Michael IV May 22 '15 at 19:06
  • We've considered Qt, but ended up with C# tools because customer required Win8 Metro look and native feel, which is hard to achieve with Qt. Actually I like Qt and would love to use it instead of WPF but unfortunately I cannot in this case. – Aleksei Petrenko May 23 '15 at 22:30
  • Has any solution to this been found? I am trying to find a way to embed an OpenGL window inside a main WPF window so that I can have some dialog controls. Would love to hear if there is a way to do this. – Fra Dec 03 '15 at 22:56

1 Answers1

1

Create a wpf window. Render your opengl viewport in background. Get the Snapshot of the opengl viewport and display the image in the WPF. Transfer all UI Events on the WPF Image to the opengl viewport.

EDIT: There is a way to host win32 window inside WPF window. You can refer this video https://www.youtube.com/watch?v=JO4uW8Xb230. If you are using GLFW for creating win32 window, you just need to use the underlying handle or just cast the window to HWND that WPF needs to host the window.