Dienstag, 21. April 2009

XNA + WPF = NotFuseable, yet... maybe in .Net 4.0 ?

XNA is really great for creating Computergames.
WPF is really great for Business Applications.

But what is if you plan to create a game that uses features that are
typically used in Business Apps.

Letz take this Screenshot from World of Warcraft

Wpf with its styles/effects allows you easily alow to create a screen like this.

If you build a 2D game you have the choice, this should be possible easy with both Frameworks.
Build a 3D game with WPF could become tricky, i think you will maybe need features that are simple not available in WPF. I think XNA Performe also better.

Note that both Frameworks rely on DirectX.
So why not use both Frameworks ?
Work that becomes easy in WPF is done in WPF,
Work that becomes easy in XNA are done in XNA.


Letz take this Example from World Of Warcfaft


You can even mix both technologies in game, so they can take advantage from each other.
You could define a WPF-Grid for Layouting purposes that contains "XNA Elements".
A XNA 3D Element could be Dragged/Dropped onto

Theres another thing where WPF is great: Supporting differend Themes.

I made an evaluation project that tries out this possibilities.
It should be an easy WPF screen that embedds 1 XNA Frame.
Note that there is no overlay of WPF-Elements and XNA-Elements.
The eval Project supports WPF-Themes and is build on the WPF Themes Project (for eval reasons only)





I ran into troubles trying to Paint direct in WPF, so i made a WindowsHost in a hurry that contains a Windows Forms Control that paints the output from XNA.
Argh - of course - this is really messy a pain for the CPU :D
result was that it was really slow and took 100% Cpu.


So heres a list of ideas to fuse WPF and XNA:

1. WPF creates a control where XNA Content is Rendered to (~ OnPaint)
{This was planned initially - but i dit not come this far - since WPF has not OnPaint events - i think this can be done with brushes ?? i dit not find anyone who has tried this before}
2. WPF hosts a WindowsForms Control that hosts XNA
{ that's the Solution i have build (very SLOW)}
3. WPF opens a Direct3D viewport where XNA is shown
{seems not to be 100% possible allthough both rely on directx...)
check this out: http://jmorrill.hjtcentral.com/Home/tabid/428/EntryId/259/XNA-Meet-WPF.aspx
4. WPF opens a Direct3D viewport where the content from XNA is drawn into. I don't know if everyone has ever tried this, or if it is even therical posible (i do not know so much about XNA/DirectX)

The next thing is that there a lot of voices out there who want simplyfied UI design in XNA - and most of them want a WPF/Silverlight integration because this seems to be the best option.


It seems that Microsoft has allready picked up this idea in .Net 4.0 (??)
check this presentation of WPF XNA interop,
but i do not think that they have released the source yet...
http://channel9.msdn.com/pdc2008/PC46/ (Jump to Minute 38)




People having the same idea/Problem:
--------------------------------------------------
People having the same problem / Demand:

Demand on Microsoft to provide this feature direct in XNA and community answers -> http://forums.xna.com/forums/p/1122/6527.aspx

Some critic voices on not programming a fusion of WPF and XNA
“Otherwise you risk splintering the game development community between WPF and XNA if left without a way to share these assets.” ->
http://social.msdn.microsoft.com/Forums/en-US/xnaframework/thread/0562aab0-029a-4aed-a59a-8b94b1f1ca2f

Same Problem here:
http://forums.xna.com/forums/p/29421/165307.aspx

Idea of exporting Expression Blend Stuff to XNA:
http://forums.xna.com/forums/p/29511/165847.aspx#165847
+ Tracker in Connect: https://connect.microsoft.com/feedback/ViewFeedback.aspx?FeedbackID=433623&SiteID=226