WPF D3D Interop C++ and C# Sample
Kinect for Windows 1.6, 1.7, 1.8
Note
To compile this sample, you must have the DirectX SDK installed. To run this sample, you must have the DirectX End-User Runtime installed. (To download the DirectX SDK and DirectX End-User Runtime, see Software Requirements.) If you do NOT have these packages installed, launching this sample results in a warning that the DirectX Runtime must be installed, and the sample will NOT work.
Overview
When you run this sample, you see the following:
The sample loads a background image. As you move the mouse over the background, the mouse cursor is rendered as a magnifier glass over the background image.
After a few moments, a depth visualization of the people in front of the camera is rendered semi-transparently over the background image.
Use the Magnifier controls to turn the magnifier on or off, adjust its size, or scale the magnification.
The Camera controls position and rotate the depth visualization to view it from different distances and angles. The center of the image that you rotate around is calculated as the midpoint between the farthest point and the nearest point displayed. The camera movement is smoothed using depth values that are averaged over the last few frames.
- Use the radius slider to move the depth visualization closer or farther away.
- Use the theta slider to rotate the depth visualization in the horizontal (xz) plane.
- Use the phi slider to rotate the depth visualization in the vertical (yz) plane.
To Open the Sample in Visual Studio
- Click the Start button, select All Programs > Kinect for Windows SDK version number > Developer Toolkit Browser version number (Kinect for Windows). You can also click the Start button and type kinect toolkit.
- In the list of samples, find this sample and click the Install button.
- Select a location to install the sample to.
- Double-click the Solution file (.sln) that was installed.
To Build the Sample
In Visual Studio 2010 Ultimate:
- Start Visual Studio and from the menu, select File > Open > Open Project/Solution.
- Browse to the directory that contains the unzipped sample files. Double-click the Visual Studio Solution (.sln) file.
- From the menu, select Build > Build Solution.
In Visual C# 2010 Express:
- Start Visual C# and from the menu, select File > Open Project.
- Browse to the directory that contains the unzipped sample files. Double-click the Visual Studio Solution (.sln) file.
- From the menu, select Debug > Build Solution.
In Visual C++ 2010 Express:
- Start Visual C++ and from the menu, select File > Open > Project/Solution.
- Browse to the directory that contains the unzipped sample files. Double-click the Visual Studio Solution (.sln) file.
- From the menu, select Debug > Build Solution.
In Visual Studio 2012 Ultimate:
- Start Visual 2012 and from the menu, select File > Open > Project/Solution.
- Browse to the directory that contains the unzipped sample files. Double-click the Visual Studio Solution (.sln) file.
- From the menu, select Build > Build Solution.
To Run the Sample
To run the sample in the Visual Studio debugger, from the menu select Debug > Start Debugging. To run the sample in Visual Studio 2010 Ultimate without debugging, from the menu select Debug > Start Without Debugging.
Depth Visualization using DirectX 11
This Windows Presentation Foundation (WPF) sample demonstrates interoperability between a C#/WPF Kinect for Windows application and a C++ project for DirectX rendering. That is, the sample demonstrates rendering using DirectX 11 and HLSL shaders in a WFP sample using D3DImage. The sample builds on the WPF functionality shown in the Depth Basics-WPF C# Sample by adding the D3DVisualization project to implement depth rendering via DirectX using shaders.
The D3DVisualization Project requires both native and managed code. The native code implements a Direct3D device, a render target, and some shaders to render using DirectX 11 while the managed code responds to WPF events and manages the calls to the native code. Here is a brief description of some of the key files.
Native Code Files
- D3DVisualization.cpp - Creates a CDepthD3D class that implements a Direct3D device for rendering and sets the camera parameters.
- D3DVisualization.fx - The shader file that contains a vertex, pixel, and geometry shader. The vertex shader passes through data to the geometry shader, the geometry shader creates a quad (two triangles) for each Kinect depth pixel, and the pixel shader outputs the color passed in from the geometry shader.
- D3DXUtils.cpp - Contains a helper function, CompileShaderFromFile, for compiling the shader (HLSL) code.
Managed Code Files
- MainWindow.xaml.cs - Creates the MainWindow class, which handles user events, the interaction between user events and WPF events, and calls into the native code.
- D3D11D3DImage.cs - Creates a Microsoft.Windows.Media.SurfaceQueueInteropHelper, which is a WPF control that creates a DirectX 11 context in WPF and provides APIs for D3DImage updating, resizing, surface lost/regained, and rendering callbacks.