XNA Basics C# Sample

Kinect for Windows 1.5, 1.6, 1.7, 1.8


To open this sample in Visual Studio 2010, you must have XNA Game Studio 4 installed, which you can find on the Software Requirements page. XNA Game Studio 4 is not supported in Visual Studio 2012.


When you run this sample, you see the following:

  • At startup, the background window displays color data.
  • At startup, the small picture in picture (PIP) window displays depth data.
  • Use the spacebar to swap the contents of the windows.

This sample uses XNA APIs to display the color, depth, and skeleton data. This is a more advanced sample that uses an effect with pixel shaders to display the data streams.

This sample builds on basic Kinect for Windows topics, such as enumerating sensors, setting up data streams, and getting and displaying color, depth, and skeleton data, which are demonstrated in these other examples: Color Basics-WPF C# Sample, Depth Basics-WPF C# Sample, and Skeleton Basics-WPF C# Sample.

This sample adds three rendering classes: ColorStreamRenderer.cs, DepthStreamRenderer.cs, and SkeletonStreamRenderer.cs. Each of these classes renders its appropriate data type by calling the appropriate Kinect for Windows APIs. In addition, the color and depth classes each use an effect file containing a pixel shader to render color or depth data. This table contains the XNA APIs that are implemented.

The Sample Uses the Following APIsTo Do This
ContentManager.Load.<Effect> methodLoad two effect files: KinectColorVisualizer.fx to render the color data and KinectDepthVisualizer.fx to render the depth data.
ContentManager.Load.<Texture2D> methodLoad a texture for rendering.
Texture2D class, Texture2D.SetData methodCreate a 2D texture and initialize the texture data with color data.
RenderTarget2D classCreates an XNA render target, which is used as a back buffer to render into.
GraphicsDevice.SetRenderTarget methodSet the render target to the device.
GraphicsDevice.Clear methodClear the back buffer.
SpriteBatch.Begin, SpriteBatch.Draw, and SpriteBatch.End methodsRender a sprite to the back buffer; the sprite contains either a 2D texture or text depending on the sprite.
GraphicsDevice.SetRenderTargets methodReset the device's render target to do additional rendering.

To run a sample you must have the Kinect for Windows SDK installed. To compile a sample, you must have the developer toolkit installed. The latest SDK and developer toolkit are available on the developer download page. If you need help installing the toolkit, look on this page: To Install the SDK and Toolkit. The toolkit includes a sample browser, which you can use to launch a sample or download it to your machine. To open the sample browser, click Start > All Programs > Kinect for Windows SDK [version number] > Developer Toolkit Browser.

If you need help loading a sample in Visual Studio or using Visual Studio to compile, run, or debug, see Opening, Building, and Running Samples in Visual Studio.

Community Additions