Win2D/README.md

4.7 KiB

Win2D

Win2D is an easy-to-use Windows Runtime API for immediate mode 2D graphics rendering with GPU acceleration. It is available to C# and C++ developers writing Windows Store apps for Windows 8.1 and Windows Phone 8.1. It utilizes the power of Direct2D, and integrates seamlessly with XAML and ICoreWindow.

Win2D is work in progress and evolving rapidly. The goal of releasing this code in an early, incomplete state is to solicit early developer feedback.

Code Example

To give you a flavor of what the code looks like, here is a snippet of XAML:

xmlns:canvas="using:Microsoft.Graphics.Canvas"

<Grid>
    <canvas:CanvasControl x:Name="canvasControl" />
</Grid>

and C#:

canvasControl.Draw += canvasControl_Draw; 
void canvasControl_Draw(CanvasControl sender, CanvasDrawEventArgs args)
{
    args.DrawingSession.Clear(Colors.BlueViolet);
}

Setup

Visual Studio

  • Download here
  • Requires Visual Studio 2013 Update 2 or greater
  • If using Visual Studio Express, requires the 'for Windows' version (not 'for Windows Desktop')

Clone Repository

Build NuGet Packages

  • In Windows search, type 'Visual Studio Tools', and select that folder to open it
  • Launch 'Developer Command Prompt for VS2013'
  • Change directory to your cloned Win2D repository and run 'build'
  • Point Visual Studio at the resulting 'bin' directory:
    • In Visual Studio, go to 'Tools' -> 'NuGet Package Manager' -> 'Package Manager Settings'
    • Choose 'Package Sources'
    • Click the '+' button to add a new source
    • Set 'Name' to 'Win2D' (or a name of your choosing)
    • Set 'Source' to the full path to the 'bin' directory (inside your cloned Win2D repository)
    • Click the 'Update' button
    • Click 'OK'

Quickstart

Follow the steps below to get started on writing your own apps.

  • Go to 'File' -> 'New' -> 'Project...'
  • Select 'Visual C#' -> 'Store Apps' -> 'Universal Apps'
  • Create a 'Blank App (Universal Apps)'
  • Set a 'Name' of your choosing
  • Click 'OK'
  • Go to 'Tools' -> 'NuGet Package Manager' -> 'Manage NuGet Packages for Solution...'
  • Select 'Win2D' package and click 'Install'
  • Click 'Close'
  • Change Solution platform from 'Any CPU' to x86
  • You are now ready to hit F5 (Build)

A working sample can be found in the Samples directory.

Source Directory Structure

Note: For the bulk of interesting product code, go to /winrt/lib.

/bin - Binary files generated by the build

/build - Shared, build-related resources that are common across projects

  • /Assets - Common Windows Store assets used for tests and samples
  • /nuget - Resources needed for building the NuGet package

/numerics - Cross-platform vector and matrix math library. There are three implementations:

  • /Cpp
  • /DotNet
  • /WinRT

/obj - Intermediate files generated by the build

/samples - Example projects showing how to use Win2D

/tests - Test projects that consume Win2D in a similar way to how an external customer would. Each one is a Windows Store app. These tests are run for manual verification.

/tools - Standalone utilities, separate from Win2D product code

  • /codegen - Generates headers+IDL from XML resource files (you don't have to build this to build Win2D)
  • /copyright - Verifies the right copyright banner appears at the top of each source file
  • /docs - Tools and scripts for building API reference documentation

/winrt - Win2D product code and automated tests

  • /dll - Build resources for the product dll
  • /docsrc - Source files used to create the reference documentation
  • /inc - Common includes
  • /lib - All the projected IDL and runtime class implementations!
    • /WinRTDirectX - projections for D3D/DXGI types
  • /published - Headers that are included directly in the NuGet package for 3rd part consumption
  • /test.external - Automated tests that use only the public WinRT interface
  • /test.internal - Automated tests that link directly with winrt.lib to access internals of the implementation
  • /test.managed - Automated tests written in C#
  • /test.nativecomponent - C++/CX component that exposes native functionality for use by test.managed