Table of contents
WPF (Windows Presentation Foundation) is a modern SDK created by Microsoft for building GUIs in Windows. Many powerful Windows applications today, including Visual Studio 2010 and later, are built using WPF. WPF makes it easy to create sophisticated GUI controls that are composed of other controls. It also has support for animation, styling, and data binding. It optionally supports a declarative UI layout through a XML format called XAML.
UI toolkits for games are often simpler and less featureful than desktop-grade UI toolkits. Incorporating WPF into a Mogre application allows a developer to have a sophisticated UI and leverage the vast wealth of WPF resources available.
There are several ways of using WPF and Mogre together. Note that most are in an experimental state.
Here are the possibilities:
D3DImage is a WPF control that shows a Direct3D texture inside WPF. It can be set to use a texture that Mogre renders to.
- The result is a fully interactive WPF application with all WPF features supported.
- The Mogre scene can be partially transparent, with WPF elements behind it. Partially transparent WPF elements can be placed on top of the Mogre scene.
- WPF controls the rendering loop
- WPF’s rendering loop is locked at Vsync (e.g. 60FPS)
Approaches to implementation:
- Single vs Double buffering
- Timing of Ogre rendering
- CompositionTarget.Rendering event
- DispatcherInactive event
- Loop in separate thread
This approach takes two Windows windows: the top is mostly transparent and contains some WPF controls, while the bottom is a typical Mogre window. The positions of the two windows are synced, and input from the user can go to either window.
- Mogre Rendering rate is not constrained to WPF rendering, as it is in the ‘Mogre In WPF’ approach.
- It can be tricky to cleanly keep two windows in sync, with input working nicely between the two.
Capture a screenshot of individual WPF visuals and render them as textures onto entities in Ogre or Mogre.
- You can position GUI elements in 3D space as Ogre Scene Nodes
- You have full control over when WPF is rendered to an Ogre scene, which might facilitate high performance scenarios.
- It is up to you to arrange WPF controls on the screen. (Perhaps this is simpler if you capture an entire WPF window.)
- It is up to you to handle input to make the WPF elements interactive. (Not an issue if you only use WPF as a HUD that requires no input.)
- No open source implementation is known that provides interactivity.
... how interaction works (Add both ways, which was describes by Hormis) ...
- Mogre In WPF:
- Article with sample: Blend the OGRE Graphics Engine into your WPF projects
- Project: MogreInWpf
- Project: Double buffered D3DImage technique. D3DImage based Mogre and WPF interop at high FPS.
- WPF On Mogre (Overlay technique): A WPF window is layered on top of a standard WinForms window.
- Project: Windowsinput by Hormis
- WPF In Mogre:
- Article: Taking WPF Screenshots
- Article with sample: Use a screenshot of a WPF visual as a texture in Mogre
- Article with sample: How to get access to WPF’s internal Direct3D guts
- Article: Generating images using WPF on the Server
- Article: Rendering a WPF Container to Bitmap
- Mogre with WPF GUI
- Blending OGRE (via MOGRE) into a WPF application
- Ogre with wpf client
- Deciding on MOgre ... about WPF, alternative C# engines, etc
WPF + Direct3D Performance Tips
- Performance Considerations for Direct3D9 and WPF Interoperability (MSDN)
- WPF and Direct3D9 Interoperation (MSDN)
WPF Performance Tips
- Optimizing WPF Application Performance
- WPF in Visual Studio 2010 – Part 2 : Performance tuning
- New WPF Features: Cached Composition - (Idea to consider: use this approach to capture interactive WPF entities?)
- WPF Drawing Performance - Great benchmarks and discussion of pens, brushes, freezable, and antialiasing within WPF
- A critical deep dive into the WPF rendering system (This was a great article, but it looks like the domain is gone. If you find a cached version please post it here.)
Other Technical Information
- Howto lock texture created as render target (D3DUSAGE_RENDERTARGET)?
- C++/VB - No textures with D3DPOOL_MANAGED under Vista?
- OGRE Direct3D 9Ex plugin - important for improving rendering performance for the Mogre in WPF approach.
- Prototype steps of GUI development