Display WPF controls over OpenGL window in Windows desktop application - c#

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?

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.

Related

OpenGL control overlays WPF elements

I have rich client application developed in WPF using DevExpress controls library.
In one of the panels I render some visual elements using OpenTK (OpenGL's wrapper library for .net).
The problem is, OpenGL rendering surface seems to be Top Most within the application. So if I move one panel on to another, OpenGL's control overlays WPF elements:
I'm not sure is it general problem with WPF, or something with DevExpress or OpenTK.
I would like to know, is there anything I can do, to solve this problem?
Edit: I'm using WindowsFormsHost control to put OpenTK's GLControl into WPF UserControl. And I'm using .Net 4.5.
The DockLayoutManager has known limitations when working with WindowsFormsHost. These limitations are general for WPF platform and they are powered by the current implementation of HwndHost (see WPF and Win32 Interoperation MSDN-article for details).
You can try to overcome possible issues with dock panels overlapped by your OpenGL (WinForms) controls, by setting the DockLayoutManager.EnableWin32Compatibility property to true and the DockLayoutManager.FloatingMode property to FloatingMode.Desktop.

Embed button control into existing Direct3D application

I would like to overlay own content above a Direct3D v9 game (made by a third party).
Overlay Interactive Button
Specifically, I would like to overlay a clickable button control, like Steam does, for instance, though I'm attempting a much simpler interface.
Ideally, I would be able to overlay a WPF button or a Windows Form button or whole UserControl, but if that is not possible then creating a functioning button from primitives would suffice as well.
Text Overlay Working with SharpDX
I have a working sample of overlaying text based on the work of Justin Stenning
Namely with the help of SharpDX.Direct3D9.Font DrawText method
How to Overlay a Button or UserControl with SharpDX
I looked through relevant samples in https://github.com/sharpdx/SharpDX-Samples but was not able to find a way to include or draw native controls with SharpDX
Is it possible?
If not, are there any samples of drawing a clickable button from scratch?
Please bear in mind I'm a novice in the DirectX world :)
Your biggest problem isn't going to be getting the controls to render on top of a DX scene; it's going to be getting them to respond to input afterwards. You can probably rig up a way to get the visuals copied to a DX surface, but I have no idea how you would capture input, translate it, and deliver it back to the WPF components. If it's even possible, it's almost certainly more trouble than it's worth.
There are a couple game-oriented Xaml solutions out there that you may want to check out. WPF for Games is a partial C++ implementation of WPF based on Direct3D, and there's also the proprietary Noesis GUI.

Switching layout dynamically depending on aspect ratio

I've been searching for a long time without finding a proper answer to this question. Maybe because it can come up with the right keywords to search for.
However, I have a WinForm with a ElementHost containing some WPF (A UserControl). In WinForm can be resized and I want the WPF to have a different layout/view depending on if the window is in landscape or portrait mode.
What is the best way to design a layout like this in WPF?
I will do the detection of the window aspect ration in my winform OnResize(System.EventArgs e) and send the signal downwards into my ElementHost. The layout should be switched and replaced at runtime.
Pardon me if the terminology is not correct but I'm a bit new to the .NET framework.

Touch capable webbrowser control for WPF

I am having a problem with embedding webbrowser in WPF application.
As you may know the standard webbrowser is not really a WPF component.
When you embed the control you cannot apply any transforms on it and is displayed on the topmost layer as it is just wrapper for winforms control.
I have to create app with webbrowser included; the app should rotate to face all four edges of the touch capable screen that will be built into the restaurant table.
I've tried Awesomium and CefSharp but touch scrolling works only in winforms components (which is weird cause WPF was designed with touch in mind).
Any ideas? Alternative WPF browser components? The component has to WPF control, be touch responsive and preferably free or cheap.
If it is still relevant, there is a way to make WPF WebBrowser control touch-friendly (IE10+), here is how.

Vector Graphics in C# WinForms - should I interoperate with WPF?

I have a video camera that I'm interfacing with a C# app. The camera actually comes with a .NET WinForms control. It supports drawing on it with GDI+ functions.
When I zoom in, I need <1 pixel accuracy i.e. I want to draw a circle with a radius of less than two pixels. How can I draw vector graphics in WinForms? Is my best bet to overlay a WPF Canvas? I know I can use WPF controls in WinForm apps, but is it possible to make the background of a ElementHost/WPF canvas transparent and overlay it onto my video feed? Am I better off creating a WPF app, and only using this video control on the WindowsFormsHost provider?
Any other solutions of drawing vector graphics in C# apps?
Thanks in advance.
Well, unfortunately you won't be able to use WPF to overlay anything on your WinForms control due to airspace issues. Winforms and WPF content is not allowed to overlap inside the same window. You're stuck using vanilla GDI or another custom Winforms vector library.
MSDN Link to explanation of interoperability issues.

Categories

Resources