Graphics Reference
In-Depth Information
9.
The following screenshot shows an example of the output using
CubeRenderer
from the recipes in
Chapter 3
,
Rendering Meshes
, and overlaying the 2D text with
the
TextRenderer
class:
Output from the simple Hello World sample using the CoreWindow render target
How it works…
As mentioned, Visual Studio 2013 only provides templates for XAML-based Windows Store
apps in C#. Therefore, we started with the C# Blank App (XAML) and then removed the XAML
classes so that we could use our own view provider.
To create our own basic view provider, it is necessary for us to define a view provider factory
and a view provider class:
D3DAppViewProviderFactory
and
D3DAppViewProvider
,
respectively, in our sample. Within the static
Main
entry-point, we then create an instance
of our view provider factory and tell the application singleton to run our factory using
CoreApplication.Run
. Our custom view provider implements the four methods of
the
IFrameworkView
interface:
Initialize
,
SetWindow
,
Load
, and
Run
. Within
SetWindow
, we create a swap chain for the provided
CoreWindow
and initialize our
D3DAppCoreWindowTarget
concrete descendent class.
The
D3DAppCoreWindowTarget
class connects to the
SizeChanged
event of
CoreWindow
within the constructor, provides the size of
CoreWindow
through the
CurrentBounds
property, and finally creates a swap chain using the
SharpDX.DXGI.SwapChain1
constructor that accepts a
CoreWindow
instance. The equivalent in native code would
be to use the
IDXGIFactory2.CreateSwapChainForCoreWindow
method.
// Create the swap chain for the CoreWindow
using (var coreWindow = new ComObject(_window))
return new SwapChain1(factory, device, coreWindow, ref desc);