Friday, 6 November 2009

WPF and Direct2D

Seems to us to be the most obvious thing in the world to want to hit Direct2D from WPF but there's a severe scarcity of doc about how to do it.

We spent many happy hours hosting a C++ HWND in a WPF app and pinging messages to it, but then we stumbled on Mahmoud's piece about the Windows API Code Pack and our lives changed for the better.

In case you're interested, WPF has a retained mode model, so if you draw something it remembers what you drew for you, so when the window's repainted or resized it knows how to redraw. All of which is fine, but there are circumstances where you want immediate-mode graphics, so you own the display list and take ownership of the drawing.

Why might that be? Well, if your display list (i.e. the list of stuff you want to draw) is coming from somewhere else - a CAD system maybe, or a database - you don't want to keep it twice, and if it's hundreds of thousands of elements you're trying to do something WPF wasn't designed for. Direct2D, on the other hand, most definitely was.

But why do us Vixerer's care? Suffice to say Vixer's going to have a little sister sometime soon....

0 comments:

Post a Comment