Category Archives: Xaml/DX Interop

How To: Use XAML and DirectX with C++ and create a compelling Windows Store app

One of the great benefits of using C++ to write Windows Store apps is the ability to mix and match various components and create compelling user experiences. There are a variety of apps that use XAML and DirectX together and have built delightful user experiences. For example, there is the FreshPaint app in the Windows Store that allows free form panting using touch or the OneNote app which allows for, as you know, note taking using a stylus (along with keyboard support).

However, if you want to take a look at code and learn from the experts and masters who have built such apps, there are very few options. One such code base is Project Austin which is a sample built by the C++ team to demonstrate using C++ (and CX) along with XAML and DirectX to build a great note taking app. Today’s post, however, is not about Project Austin. It is about a cool sample built by a colleague and C++ enthusiast, Thomas Petchel. Tom built a cool app named Weathr, which he describes as “3D weather app for Windows 8.1 using C++, DirectX, and XAML“. I cannot agree more. This is the best weather app I have seen in a long time and it shows in the user experience. Tom has also made the sources available for anyone to check out and play with. If you are serious about learning how to build such great experiences in your Windows Store apps, please check out the code. And if you make changes to the code, please ensure you contribute back the changes. This ensures that all the folks get the new stuff!!

I can talk about code and design, but I would leave that out for fellow programmers. The app is not on the Store though. So if you want to get the app, you have to build the sources J

Cheers and Happy Holidays!

-Sridhar

Will there be an update for “Modern C++ and Windows Store apps” for Windows 8.1?

With Windows 8.1 now released as a Consumer Preview enabling developers to try out and begin building apps for the new Operating System, I wanted to let folks know if there is an updated version of my book, “Modern C++ and Windows Store apps” under development.

When I began contemplating writing a book about Windows 8, I did not want to just show how to build Windows Store apps using C++ /CX and XAML. That would probably have been a great disservice to C++ developers since it would have restricted the scope of the book to just XAML. Don’t get me wrong. XAML is a great UX framework but I wanted to show how the power and flexibility of C++ and C++ /CX can be used to build a vide variety of apps that could be run both on the Desktop and Modern.

The more I thought about what to talk about in the book, the more my ideas began to crystallize around narrating the “C++ Renaissance” at Microsoft and in the industry. Discussing the “C++ Renaissance” is a vast topic in itself and I had to make a few hard decisions on the list of topics. After multiple deliberations, I ended up discussing the following topics:

  • Show the simplicity of developing Windows Store apps using C++ /CX
  • Important concepts of C++11
  • Introduction to C++ /CX
  • A High level tour of XAML
  • Using C++ /CX to combine XAML and DirectX
  • Advanced GPGPU Programming by using C++AMP in Desktop and Windows Store apps.
      • Under the covers of the Windows Runtime and the Windows Runtime Library (WRL)
      • Introducing the new native unit test support in VS2012.
      • Debugging tips for Windows Store apps
      • Performance tips for using XAML
      • Introduction to Windows Azure Mobile Services
      • A sneak preview of Windows Phone 8 “shared code”.

One of the ideas that I steadfastly took while developing samples and the narration was to focus explaining how C++ developers should be using XAML/DirectX interop techniques to make their apps stand apart from pure XAML or WWA counterparts. XAML/DirectX interop is really the “super pill” that can help C++ developers take full advantage of both the retained mode benefits of XAML and the immediate mode rendering provided by DirectX. When coupled with C++AMP, this has the added advantage of eking out maximum performance from the available hardware for all of your workloads.

With Windows 8.1, while XAML got a host of new controls, using those controls by itself is not an impossible task if you have already worked your way through my book. There simply is no point creating a new version of the book, when the fundamentals have already been discussed. All of the new updates are important but they are not breaking changes or stuff that is hard to incorporate. What is really interesting is the changes to the XAML/DirectX interop types. Does it warrant the creation of a new version of the book to explain 4 new interop types? I don’t think so. It, however, does merit explanation. So, going forward, I will begin posting content about the updated XAML/DirectX interop types. I will also update the samples from my book to show how to move code from Windows 8 to Windows 8.1. I hope that is of more value to readers instead of coming up with a new version of the book. What do you think? Please do let me know.

If you have noticed the topics I discussed in my book, attentive readers must have noticed that I did not discuss any communications or network API in the book. Is it a harbinger for things to come in future? Stay tuned for updates Smile

-Sridhar

What’s new in XAML for Windows 8.1?

//BUILD 2013 concluded last week and there was a ton of stuff to assimilate. I will attempt to summarize a few important changes for C++/XAML/DirectX developers in this blog post., focusing exclusively on the XAML/DirectX Interop scenarios.

If you are interested in knowing what is new with just the XAML framework (new controls, binding features etc), check out this great video from Tim Heuer.

New Stuff for XAML/DirectX interop scenarios using SwapChainPanel

1. A new SwapChainPanel control present in the Windows::UI::Xaml::Controls class.

2. In Windows 8, you were restricted to creating a full screen SwapChainBackgroundPanel and the swap chain had to be present at the root of your control hierarchy. The new SwapChainPanel controls removes these restrictions.

3. This does not mean you can have hundreds of SwapChainPanel controls in your app (Well, not even in the low double digits). Turns out using too many SwapChainPanel controls incurs a heavy cost. So restrict them to at the most 3 or 4. Do not go beyond that.

4. It is composable like any normal XAML element. You can have text layered below or above the control and have the XAML framework render content.

5. A Size Changed notification event provides for crisp re-drawing of content.

New Stuff for XAML/DirectX interop scenarios using the new SiS/VSiS

1. Has updated methods for faster D2D drawing by using drawing with a Direct2D DeviceContext.

2. Using the D2D DeviceContext allows the framework to batch the drawing requests.

3. Supports multi-threaded drawing.

4. Has new methods, SuspendDraw and ResumeDraw to enable you to suspend drawing operations and resume them later.

5. No longer needed to call BeginDraw on the XAML UI thread. In fact, BeginDraw, SuspendDraw and ResumeDraw can be called from any thread.

6. EndDraw should still be called on the UI thread. This allows the XAML framework to update the scene.

SwapChainPanel with Independent Input

1. The new SwapChainPanel now has support for processing touch, pen and mouse input on a background thread. This provides a path for low latency interactivity and high performance.

These are some of the high level changes. I encourage all of you to check out the excellent //BUILD 2013 talk by Bede Jordan,  a Senior Development Lead on the XAML team.

Enjoy the new C++/XAML/DirectX interop stuff in Windows 8.1

-Sridhar