***DirectXGame*~GDC2013Game20%Templates~
{ Microsoft Core Windows**
& Core Windows & XAML & download..}!!!!!
**Microsoft Visual Studio Solution File,
Format Version 12.00
# Visual Studio 2012
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "ignore", "ignore.vcxproj", "{E49409F5-74F2-409A-89D3-6609EDC00A42}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|ARM = Debug|ARM
Debug|Win32 = Debug|Win32
Debug|x64 = Debug|x64
Release|ARM = Release|ARM
Release|Win32 = Release|Win32
Release|x64 = Release|x64
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{E49409F5-74F2-409A-89D3-6609EDC00A42}.Debug|ARM.ActiveCfg = Debug|ARM
{E49409F5-74F2-409A-89D3-6609EDC00A42}.Debug|ARM.Build.0 = Debug|ARM
{E49409F5-74F2-409A-89D3-6609EDC00A42}.Debug|ARM.Deploy.0 = Debug|ARM
{E49409F5-74F2-409A-89D3-6609EDC00A42}.Debug|Win32.ActiveCfg = Debug|Win32
{E49409F5-74F2-409A-89D3-6609EDC00A42}.Debug|Win32.Build.0 = Debug|Win32
{E49409F5-74F2-409A-89D3-6609EDC00A42}.Debug|Win32.Deploy.0 = Debug|Win32
{E49409F5-74F2-409A-89D3-6609EDC00A42}.Debug|x64.ActiveCfg = Debug|x64
{E49409F5-74F2-409A-89D3-6609EDC00A42}.Debug|x64.Build.0 = Debug|x64
{E49409F5-74F2-409A-89D3-6609EDC00A42}.Debug|x64.Deploy.0 = Debug|x64
{E49409F5-74F2-409A-89D3-6609EDC00A42}.Release|ARM.ActiveCfg = Release|ARM
{E49409F5-74F2-409A-89D3-6609EDC00A42}.Release|ARM.Build.0 = Release|ARM
{E49409F5-74F2-409A-89D3-6609EDC00A42}.Release|ARM.Deploy.0 = Release|ARM
{E49409F5-74F2-409A-89D3-6609EDC00A42}.Release|Win32.ActiveCfg = Release|Win32
{E49409F5-74F2-409A-89D3-6609EDC00A42}.Release|Win32.Build.0 = Release|Win32
{E49409F5-74F2-409A-89D3-6609EDC00A42}.Release|Win32.Deploy.0 = Release|Win32
{E49409F5-74F2-409A-89D3-6609EDC00A42}.Release|x64.ActiveCfg = Release|x64
{E49409F5-74F2-409A-89D3-6609EDC00A42}.Release|x64.Build.0 = Release|x64
{E49409F5-74F2-409A-89D3-6609EDC00A42}.Release|x64.Deploy.0 = Release|x64
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
EndGlobal**
*****IGNORE**
**<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup Label="ProjectConfigurations">
<ProjectConfiguration Include="Debug|Win32">
<Configuration>Debug</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|Win32">
<Configuration>Release</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Debug|x64">
<Configuration>Debug</Configuration>
<Platform>x64</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|x64">
<Configuration>Release</Configuration>
<Platform>x64</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Debug|ARM">
<Configuration>Debug</Configuration>
<Platform>ARM</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|ARM">
<Configuration>Release</Configuration>
<Platform>ARM</Platform>
</ProjectConfiguration>
</ItemGroup>
<PropertyGroup Label="Globals">
<ProjectGuid>{e49409f5-74f2-409a-89d3-6609edc00a42}</ProjectGuid>
<RootNamespace>ignore</RootNamespace>
<DefaultLanguage>en-US</DefaultLanguage>
<MinimumVisualStudioVersion>11.0</MinimumVisualStudioVersion>
<AppContainerApplication>true</AppContainerApplication>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>v110</PlatformToolset>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>v110</PlatformToolset>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|ARM'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>v110</PlatformToolset>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<WholeProgramOptimization>true</WholeProgramOptimization>
<PlatformToolset>v110</PlatformToolset>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<WholeProgramOptimization>true</WholeProgramOptimization>
<PlatformToolset>v110</PlatformToolset>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|ARM'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<WholeProgramOptimization>true</WholeProgramOptimization>
<PlatformToolset>v110</PlatformToolset>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
<ImportGroup Label="ExtensionSettings">
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<Import Project="$(UserRootDir)\Microsoft.
Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<Import Project="$(UserRootDir)\Microsoft.
Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|ARM'">
<Import Project="$(UserRootDir)\Microsoft.
Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|ARM'">
<Import Project="$(UserRootDir)\Microsoft.
Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label=
"LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<Import Project="$(UserRootDir)\Microsoft.
Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<Import Project="$(UserRootDir)\Microsoft.
Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<PropertyGroup Label="UserMacros" />
<ItemDefinitionGroup Condition="'$(Configuration)'=='Release'">
<ClCompile>
<PreprocessorDefinitions>NDEBUG;%(PreprocessorDefinitions)
</PreprocessorDefinitions>
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|ARM'">Use</PrecompiledHeader>
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">Use</PrecompiledHeader>
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|x64'">Use</PrecompiledHeader>
</ClCompile>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)'=='Debug'">
<ClCompile>
<PreprocessorDefinitions>_DEBUG;%(PreprocessorDefinitions)
</PreprocessorDefinitions>
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">Use</PrecompiledHeader>
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|ARM'">Use</PrecompiledHeader>
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">Use</PrecompiledHeader>
</ClCompile>
</ItemDefinitionGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
</ImportGroup>
</Project> *
**DIREXTXHELPER***
**//// THIS CODE AND INFORMATION IS PROVIDED "AS IS"
WITHOUT WARRANTY OF
//// ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING
BUT NOT LIMITED TO
//// THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR
FITNESS FOR A
//// PARTICULAR PURPOSE.
////
//// Copyright (c) Microsoft Corporation. All rights reserved
#pragma once
#include <wrl/client.h>
#include <ppl.h>
#include <ppltasks.h>
#include <d2d1_1.h>
namespace DX
{
inline void ThrowIfFailed(HRESULT hr)
{
if (FAILED(hr))
{
// Set a breakpoint on this line to catch Win32 API errors.
throw Platform::Exception::CreateException(hr);
}
}
// Function that reads from a binary file asynchronously.
inline Concurrency::task<Platform::Array<byte>^>
ReadDataAsync(Platform::String^ filename)
{
using namespace Windows::Storage;
using namespace Concurrency;
auto folder = Windows::ApplicationModel::Package::Current->
InstalledLocation;
return create_task(folder->GetFileAsync(filename)).then([]
(StorageFile^ file)
{
return FileIO::ReadBufferAsync(file);
}).then([] (Streams::IBuffer^ fileBuffer) -> Platform::Array<byte>^
{
auto fileData = ref new Platform::Array<byte>(fileBuffer->Length);
Streams::DataReader::FromBuffer(fileBuffer)->ReadBytes(fileData);
return fileData;
});
}
inline void WicBitmapLoader(
_In_ ID2D1DeviceContext* m_d2dContext,
_In_reads_bytes_(dataSize) byte* data,
_In_ uint32 dataSize,
_Out_opt_ ID2D1Bitmap1** bitmap,
_In_opt_ Platform::String^ debugName
)
{
using namespace Microsoft::WRL;
ComPtr<ID2D1Bitmap1> bitmap2D;
if (m_d2dContext == nullptr)
{
// A D2D context is required to create a D2D bitmap. If
// BasicLoader was not initialized with one, this operation
// cannot be completed.
if (bitmap != nullptr) *bitmap = nullptr;
return;
}
ComPtr<IWICImagingFactory2> wicFactory;
// A WIC factory object is required in order to load texture
// assets stored in non-DDS formats. If BasicLoader was not
// initialized with one, create one as needed.
DX::ThrowIfFailed(
CoCreateInstance(
CLSID_WICImagingFactory,
nullptr,
CLSCTX_INPROC_SERVER,
IID_PPV_ARGS(&wicFactory)
)
);
ComPtr<IWICStream> stream;
DX::ThrowIfFailed(
wicFactory->CreateStream(&stream)
);
DX::ThrowIfFailed(
stream->InitializeFromMemory(
data,
dataSize
)
);
ComPtr<IWICBitmapDecoder> bitmapDecoder;
DX::ThrowIfFailed(
wicFactory->CreateDecoderFromStream(
stream.Get(),
nullptr,
WICDecodeMetadataCacheOnDemand,
&bitmapDecoder
)
);
ComPtr<IWICBitmapFrameDecode> bitmapFrame;
DX::ThrowIfFailed(
bitmapDecoder->GetFrame(0, &bitmapFrame)
);
ComPtr<IWICFormatConverter> formatConverter;
DX::ThrowIfFailed(
wicFactory->CreateFormatConverter(&formatConverter)
);
DX::ThrowIfFailed(
formatConverter->Initialize(
bitmapFrame.Get(),
GUID_WICPixelFormat32bppPBGRA,
WICBitmapDitherTypeNone,
nullptr,
0.0,
WICBitmapPaletteTypeCustom
)
);
uint32 width;
uint32 height;
DX::ThrowIfFailed(
bitmapFrame->GetSize(&width, &height)
);
std::unique_ptr<byte[]> bitmapPixels(new byte[width * height * 4]);
DX::ThrowIfFailed(
formatConverter->CopyPixels(
nullptr,
width * 4,
width * height * 4,
bitmapPixels.get()
)
);
D2D1_BITMAP_PROPERTIES1 properties;
properties.pixelFormat.format = DXGI_FORMAT_B8G8R8A8_UNORM;
properties.pixelFormat.alphaMode = D2D1_ALPHA_
MODE_PREMULTIPLIED;
properties.dpiX = 96.0f;
properties.dpiY = 96.0f;
properties.bitmapOptions = D2D1_BITMAP_OPTIONS_TARGET;
properties.colorContext = nullptr;
DX::ThrowIfFailed(
m_d2dContext->CreateBitmap(
D2D1::SizeU(
static_cast<UINT32>(width * properties.dpiX / 96.0f),
static_cast<UINT32>(height * properties.dpiY / 96.0f)
),
(const void*)(bitmapPixels.get()),
width * 4,
&properties,
&bitmap2D
)
);
if (bitmap != nullptr)
{
*bitmap = bitmap2D.Detach();
}
}
} ***
***Package AppXmanifest**
**<?xml version="1.0" encoding="utf-8"?>
<Package xmlns="http://schemas.microsoft.com/appx/2010/manifest">
<Identity Name="$guid9$" Publisher=
"$XmlEscapedPublisherDistinguishedName$" Version="1.0.0.0" />
<Properties>
<DisplayName>$projectname$</DisplayName>
<PublisherDisplayName>$XmlEscapedPublisher$</PublisherDisplayName>
<Logo>Assets\StoreLogo.png</Logo>
</Properties>
<Prerequisites>
<OSMinVersion>6.2.1</OSMinVersion>
<OSMaxVersionTested>6.2.1</OSMaxVersionTested>
</Prerequisites>
<Resources>
<Resource Language="x-generate" />
</Resources>
<Applications>
<Application Id="App" Executable="$targetnametoken$.exe" EntryPoint="$safeprojectname$.App">
<VisualElements DisplayName=
"$projectname$" Logo="Assets\Logo.png" SmallLogo=
"Assets\SmallLogo.png" Description=
"$projectname$" ForegroundText=
"light" BackgroundColor="#464646">
<DefaultTile ShowName="allLogos" />
<SplashScreen Image="Assets\SplashScreen.png" />
<InitialRotationPreference>
<Rotation Preference="portrait" />
<Rotation Preference="landscape" />
<Rotation Preference="portraitFlipped" />
<Rotation Preference="landscapeFlipped" />
</InitialRotationPreference>
</VisualElements>
</Application>
</Applications>
</Package>***
***D2DOverlay**
***#include "pch.h"
#include "D2DOverlay.h"
#include "Common_DirectX\DirectXHelper.h"
using namespace Windows::UI::Core;
using namespace Windows::Foundation;
using namespace Microsoft::WRL;
using namespace Windows::UI::ViewManagement;
using namespace Windows::Graphics::Display;
using namespace D2D1;
D2DOverlay::D2DOverlay()
{
}
void D2DOverlay::Initialize(
_In_ ID2D1Device* d2dDevice,
_In_ ID2D1DeviceContext* d2dContext,
_In_ IDWriteFactory* dwriteFactory,
_In_ D2D1::Matrix3x2F displayOrientationTransform2D,
_In_ Windows::Foundation::Rect windowBounds
)
{
// Use the same D2D device, window properties, etc.
as the host rendering class
m_dwriteFactory = dwriteFactory;
m_d2dDevice = d2dDevice;
m_d2dContext = d2dContext;
m_displayOrientationTransform2D = displayOrientationTransform2D;
m_windowBounds = windowBounds;
ComPtr<ID2D1Factory> factory;
d2dDevice->GetFactory(&factory);
DX::ThrowIfFailed(
factory.As(&m_d2dFactory)
);
}
// Hud class
Hud::Hud() : D2DOverlay()
, m_loadingComplete(false)
, m_drawFrameInfo(true)
, m_inputDisplayStr("")
, m_fpsDisplayStr("")
{
ZeroMemory(&m_fpsMetrics, sizeof(DWRITE_TEXT_METRICS));
ZeroMemory(&m_inputCoordsMetrics, sizeof(DWRITE_TEXT_METRICS));
ZeroMemory(&m_titleMetrics, sizeof(DWRITE_TEXT_METRICS));
}
void Hud::Initialize(
_In_ ID2D1Device* d2dDevice,
_In_ ID2D1DeviceContext* d2dContext,
_In_ IDWriteFactory* dwriteFactory,
_In_ D2D1::Matrix3x2F displayOrientationTransform2D,
_In_ Windows::Foundation::Rect windowBounds,
_In_ Platform::String^ titleStr,
_In_ Platform::String^ bitmapFileNameStr
)
{
D2DOverlay::Initialize(d2dDevice,
d2dContext,
dwriteFactory,
displayOrientationTransform2D,
windowBounds);
m_title = titleStr;
m_bitmapFileName = bitmapFileNameStr;
m_textVerticalOffset = 5.0f;
m_loadingComplete = false;
ResetDirectXResources();
}
void Hud::Update(
Platform::String^ inputDisplayStr,
Platform::String^ fpsDisplayStr
)
{
if (inputDisplayStr != nullptr)
{
// Update input display text
m_inputDisplayStr = inputDisplayStr;
DX::ThrowIfFailed(
m_textFormat->SetTextAlignment(DWRITE_TEXT_
ALIGNMENT_LEADING)
);
DX::ThrowIfFailed(
m_dwriteFactory->CreateTextLayout(
m_inputDisplayStr->Data(),
m_inputDisplayStr->Length(),
m_textFormat.Get(),
400, // Max width of the input text.
50, // Max height of the input text.
&m_textLayoutInputCoordsDisplay
)
);
DX::ThrowIfFailed(
m_textLayoutInputCoordsDisplay->
GetMetrics(&m_inputCoordsMetrics)
);
}
if (fpsDisplayStr != nullptr)
{
// Update FPS display text
m_fpsDisplayStr = fpsDisplayStr;
DX::ThrowIfFailed(
m_textFormat->SetTextAlignment(DWRITE_TEXT_
ALIGNMENT_TRAILING)
);
DX::ThrowIfFailed(
m_dwriteFactory->CreateTextLayout(
m_fpsDisplayStr->Data(),
m_fpsDisplayStr->Length(),
m_textFormat.Get(),
240, // Max width of the FPS text.
50, // Max height of the FPS text.
&m_textLayoutFpsDisplay
)
);
DX::ThrowIfFailed(
m_textLayoutFpsDisplay->GetMetrics(&m_fpsMetrics)
);
}
}
void Hud::Render()
{
if (!m_loadingComplete)
{
return;
}
m_d2dContext->SaveDrawingState(m_stateBlock.Get());
m_d2dContext->BeginDraw();
// Position the title text.
D2D1::Matrix3x2F screenTranslationTitle =
D2D1::Matrix3x2F::Translation(
(m_windowBounds.Width - m_titleMetrics.layoutWidth) / 2,
m_textVerticalOffset
);
// Note that the transform matrix is post-multiplied here
// in order to correctly orient the text to match the display orientation.
// This post-multiplication step is required for any draw calls that are
// made to the swap chain's target bitmap. For draw calls to other targets,
// this transform should not be applied.
m_d2dContext->SetTransform(screenTranslationTitle * m_
displayOrientationTransform2D);
m_d2dContext->DrawTextLayout(
Point2F(0.f, 0.f),
m_textLayoutTitle.Get(),
m_whiteBrush.Get()
);
// Position the input text.
D2D1::Matrix3x2F screenTranslationInputCoords =
D2D1::Matrix3x2F::Translation(
0.f,
m_windowBounds.Height - m_inputCoordsMetrics.height
);
m_d2dContext->SetTransform(screenTranslationInputCoords * m_displayOrientationTransform2D);
m_d2dContext->DrawTextLayout(
Point2F(0.f, 0.f),
m_textLayoutInputCoordsDisplay.Get(),
m_whiteBrush.Get()
);
if (m_drawFrameInfo)
{
// Position the FPS text.
D2D1::Matrix3x2F screenTranslationFPS =
D2D1::Matrix3x2F::Translation(
m_windowBounds.Width - m_fpsMetrics.layoutWidth,
m_windowBounds.Height - m_fpsMetrics.height
);
m_d2dContext->SetTransform(screenTranslationFPS * m_
displayOrientationTransform2D);
m_d2dContext->DrawTextLayout(
Point2F(0.f, 0.f),
m_textLayoutFpsDisplay.Get(),
m_whiteBrush.Get()
);
}
if (m_bitmap != nullptr)
{
D2D1_RECT_F size = {0};
size.bottom = 2 * m_bitmap->GetSize().height;
size.right = 2 * m_bitmap->GetSize().width;
m_d2dContext->SetTransform(m_displayOrientationTransform2D);
m_d2dContext->DrawBitmap(
m_bitmap.Get(),
size,
1.0f,
D2D1_BITMAP_INTERPOLATION_MODE_LINEAR,
nullptr);
}
// We ignore D2DERR_RECREATE_TARGET here.
This error indicates that the device
// is lost. It will be handled during the next call to Present.
HRESULT hr = m_d2dContext->EndDraw();
if (hr != D2DERR_RECREATE_TARGET)
{
DX::ThrowIfFailed(hr);
}
m_d2dContext->RestoreDrawingState(m_stateBlock.Get());
}
void Hud::ResetDirectXResources()
{
DX::ThrowIfFailed(
m_d2dContext->CreateSolidColorBrush(ColorF(ColorF::White),
&m_whiteBrush)
);
double dpiX = 96.0f;
double dpiY = 96.0f;
DX::ThrowIfFailed(
m_dwriteFactory->CreateTextFormat(
L"Segoe UI",
nullptr,
DWRITE_FONT_WEIGHT_LIGHT,
DWRITE_FONT_STYLE_NORMAL,
DWRITE_FONT_STRETCH_NORMAL,
32.0f,
L"en-US",
&m_textFormat
)
);
DX::ThrowIfFailed(
m_textFormat->SetParagraphAlignment(DWRITE_PARAGRAPH_ALIGNMENT_NEAR)
);
DX::ThrowIfFailed(
m_textFormat->SetTextAlignment(DWRITE_TEXT_ALIGNMENT_CENTER)
);
DX::ThrowIfFailed(
m_dwriteFactory->CreateTextLayout(
m_title->Data(),
m_title->Length(),
m_textFormat.Get(),
500.f,
50.f,
&m_textLayoutTitle
)
);
DX::ThrowIfFailed(
m_textLayoutTitle->GetMetrics(&m_titleMetrics)
);
// TODO: Is the state block save/load still necessary?
DX::ThrowIfFailed(
m_d2dFactory->CreateDrawingStateBlock(&m_stateBlock)
);
auto readTextureTask = DX::ReadDataAsync(m_bitmapFileName);
readTextureTask.then([this](Platform::Array<unsigned char, 1U>^ data)
{
if (data->Length > 0)
{
DX::WicBitmapLoader(m_d2dContext.Get(), data->Data, data->
Length, &m_bitmap, "HUD");
}
m_loadingComplete = true;
});
}
// PauseScreen class
PauseScreen::PauseScreen() : D2DOverlay()
, m_pauseMessage("")
{
ZeroMemory(&m_pauseMessageMetrics, sizeof(DWRITE_
TEXT_METRICS));
}
void PauseScreen::Initialize(
_In_ ID2D1Device* d2dDevice,
_In_ ID2D1DeviceContext* d2dContext,
_In_ IDWriteFactory* dwriteFactory,
_In_ D2D1::Matrix3x2F displayOrientationTransform2D,
_In_ Windows::Foundation::Rect windowBounds,
_In_ Platform::String^ pauseMessage
)
{
D2DOverlay::Initialize(d2dDevice,
d2dContext,
dwriteFactory,
displayOrientationTransform2D,
windowBounds);
m_pauseMessage = pauseMessage;
m_textVerticalOffset = 5.0f;
ResetDirectXResources();
}
void PauseScreen::Update(
_In_ Platform::String^ pauseMessage
)
{
if (pauseMessage != nullptr)
{
// Update input display text
m_pauseMessage = pauseMessage;
}
else
{
m_pauseMessage = "APP PAUSED";
}
DX::ThrowIfFailed(
m_dwriteFactory->CreateTextLayout(
m_pauseMessage->Data(),
m_pauseMessage->Length(),
m_textFormat.Get(),
400, // Max width of the input text.
50, // Max height of the input text.
&m_textLayoutPauseMessage
)
);
DX::ThrowIfFailed(
m_textLayoutPauseMessage->GetMetrics(&m_pauseMessageMetrics)
);
}
void PauseScreen::Render()
{
m_d2dContext->SaveDrawingState(m_stateBlock.Get());
m_d2dContext->BeginDraw();
// Position the title text.
D2D1::Matrix3x2F translationTitle = D2D1::Matrix3x2F::Translation(
(m_windowBounds.Width - m_pauseMessageMetrics.layoutWidth) / 2,
m_textVerticalOffset
);
// Note that the transform matrix is post-multiplied here
// in order to correctly orient the text to match the display orientation.
// This post-multiplication step is required for any draw calls that are
// made to the swap chain's target bitmap. For draw calls to other targets,
// this transform should not be applied.
m_d2dContext->SetTransform(translationTitle * m_displayOrientationTransform2D);
m_d2dContext->DrawTextLayout(
Point2F(0.f, 0.f),
m_textLayoutPauseMessage.Get(),
m_whiteBrush.Get()
);
// We ignore D2DERR_RECREATE_TARGET here. This error indicates that the device
// is lost. It will be handled during the next call to Present.
HRESULT hr = m_d2dContext->EndDraw();
if (hr != D2DERR_RECREATE_TARGET)
{
DX::ThrowIfFailed(hr);
}
m_d2dContext->RestoreDrawingState(m_stateBlock.Get());
}
void PauseScreen::ResetDirectXResources()
{
DX::ThrowIfFailed(
m_d2dContext->CreateSolidColorBrush(ColorF(ColorF::White), &m_whiteBrush)
);
double dpiX = 96.0f;
double dpiY = 96.0f;
DX::ThrowIfFailed(
m_dwriteFactory->CreateTextFormat(
L"Segoe UI",
nullptr,
DWRITE_FONT_WEIGHT_LIGHT,
DWRITE_FONT_STYLE_NORMAL,
DWRITE_FONT_STRETCH_NORMAL,
32.0f,
L"en-US",
&m_textFormat
)
);
DX::ThrowIfFailed(
m_textFormat->SetParagraphAlignment(DWRITE_
PARAGRAPH_ALIGNMENT_NEAR)
);
DX::ThrowIfFailed(
m_textFormat->SetTextAlignment(DWRITE_TEXT_
ALIGNMENT_CENTER)
);
DX::ThrowIfFailed(
m_dwriteFactory->CreateTextLayout(
m_pauseMessage->Data(),
m_pauseMessage->Length(),
m_textFormat.Get(),
500.f,
50.f,
&m_textLayoutPauseMessage
)
);
DX::ThrowIfFailed(
m_textLayoutPauseMessage->GetMetrics(&m_pauseMessageMetrics)
);
// TODO: Is the state block save/load still necessary?
DX::ThrowIfFailed(
m_d2dFactory->CreateDrawingStateBlock(&m_stateBlock)
);
} **
**#include "pch.h"***
***//// THIS CODE AND INFORMATION IS PROVIDED "AS IS"
WITHOUT WARRANTY OF
//// ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING
BUT NOT LIMITED TO
//// THE IMPLIED WARRANTIES OF MERCHANTABILITY
AND/OR FITNESS FOR A
//// PARTICULAR PURPOSE.
////
//// Copyright (c) Microsoft Corporation. All rights reserved
#include "pch.h"
#include "RenderObject.h"
#include "Common_DirectX\StepTimer.h" // for TICKS_PER_SECOND
#include "Common_DirectX\DirectXHelper.h" // for ThrowifFailed()
#include <windows.ui.xaml.media.dxinterop.h>
using namespace D2D1;
using namespace DirectX;
using namespace Microsoft::WRL;
using namespace Windows::Foundation;
using namespace Windows::Graphics::Display;
using namespace Windows::UI::Core;
using namespace Windows::UI::Xaml::Controls;
RenderObject::RenderObject() :
m_loadingComplete(false),
m_degreesPerSecond(45),
m_usePanel(false),
m_projectDir(""),
m_indexCount(0),
m_dpi(-1.0f),
m_ticks(0)
{
}
// These resources can be created before the DirectX device(s)
are created. They persist
// even if the device has to be reset.
void RenderObject::CreateDeviceIndependentResources()
{
#ifdef TEMPLATE_USING_D2D
D2D1_FACTORY_OPTIONS options;
ZeroMemory(&options, sizeof(D2D1_FACTORY_OPTIONS));
#if defined(_DEBUG)
// If the project is in a debug build, enable Direct2D debugging
via SDK Layers.
options.debugLevel = D2D1_DEBUG_LEVEL_INFORMATION;
#endif
DX::ThrowIfFailed(
D2D1CreateFactory(
D2D1_FACTORY_TYPE_SINGLE_THREADED,
__uuidof(ID2D1Factory1),
&options,
&m_d2dFactory
)
);
DX::ThrowIfFailed(
DWriteCreateFactory(
DWRITE_FACTORY_TYPE_SHARED,
__uuidof(IDWriteFactory),
&m_dwriteFactory
)
);
DX::ThrowIfFailed(
CoCreateInstance(
CLSID_WICImagingFactory,
nullptr,
CLSCTX_INPROC_SERVER,
IID_PPV_ARGS(&m_wicFactory)
)
);
#endif
}
// These resources have to be re-initialized every time the DirectX
device(s) are recreated.
void RenderObject::CreateDeviceResources()
{
// This flag adds support for surfaces with a different color
channel ordering
// than the API default. It is required for compatibility with Direct2D.
UINT creationFlags = D3D11_CREATE_DEVICE_BGRA_SUPPORT;
ComPtr<IDXGIDevice> dxgiDevice;
#if defined(_DEBUG)
// If the project is in a debug build, enable debugging via SDK
Layers with this flag.
creationFlags |= D3D11_CREATE_DEVICE_DEBUG;
#endif
// This array defines the set of DirectX hardware feature levels
this app will support.
// Note the ordering should be preserved.
// Don't forget to declare your application's minimum required
feature level in its
// description. All applications are assumed to support 9.1
unless otherwise stated
// and 9.1 support is required for the ARM target platform.
D3D_FEATURE_LEVEL featureLevels[] =
{
D3D_FEATURE_LEVEL_11_1,
D3D_FEATURE_LEVEL_11_0,
D3D_FEATURE_LEVEL_10_1,
D3D_FEATURE_LEVEL_10_0,
D3D_FEATURE_LEVEL_9_3,
D3D_FEATURE_LEVEL_9_2,
D3D_FEATURE_LEVEL_9_1
};
// Create the Direct3D 11 API device object and a corresponding context.
ComPtr<ID3D11Device> device;
ComPtr<ID3D11DeviceContext> d3dContext;
DX::ThrowIfFailed(
D3D11CreateDevice(
nullptr, // Specify nullptr to use the default adapter.
D3D_DRIVER_TYPE_HARDWARE,
nullptr,
creationFlags, // Set set debug and Direct2D compatibility flags.
featureLevels, // List of feature levels this app can support.
ARRAYSIZE(featureLevels),
D3D11_SDK_VERSION, // Always set this to D3D11_SDK_
VERSION for Windows Store apps.
&device, // Returns the Direct3D device created.
&m_featureLevel, // Returns feature level of device created.
&d3dContext // Returns the device immediate context.
)
);
// Get the Direct3D 11.1 API device and context interfaces.
DX::ThrowIfFailed(
device.As(&m_d3dDevice)
);
DX::ThrowIfFailed(
d3dContext.As(&m_d3dContext)
);
// Get the underlying DXGI device of the Direct3D device.
DX::ThrowIfFailed(
m_d3dDevice.As(&dxgiDevice)
);
#ifdef TEMPLATE_USING_D2D
// Create the Direct2D device object and a corresponding context.
DX::ThrowIfFailed(
m_d2dFactory->CreateDevice(dxgiDevice.Get(), &m_d2dDevice)
);
DX::ThrowIfFailed(
m_d2dDevice->CreateDeviceContext(
D2D1_DEVICE_CONTEXT_OPTIONS_NONE,
&m_d2dContext
)
);
#endif
auto loadVSTask = DX::ReadDataAsync(m_projectDir +
"SimpleVertexShader.cso");
auto loadPSTask = DX::ReadDataAsync(m_projectDir +
"SimplePixelShader.cso");
auto createVSTask = loadVSTask.then([this](Platform::Array<byte>
^ fileData) {
DX::ThrowIfFailed(
m_d3dDevice->CreateVertexShader(
fileData->Data,
fileData->Length,
nullptr,
&m_vertexShader
)
);
const D3D11_INPUT_ELEMENT_DESC vertexDesc[] =
{
{ "POSITION", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, 0, D3D11_INPUT_PER_VERTEX_DATA, 0 },
{ "COLOR", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, 12, D3D11_INPUT_PER_VERTEX_DATA, 0 },
};
DX::ThrowIfFailed(
m_d3dDevice->CreateInputLayout(
vertexDesc,
ARRAYSIZE(vertexDesc),
fileData->Data,
fileData->Length,
&m_inputLayout
)
);
});
auto createPSTask = loadPSTask.then([this](Platform::Array
<byte>^ fileData) {
DX::ThrowIfFailed(
m_d3dDevice->CreatePixelShader(
fileData->Data,
fileData->Length,
nullptr,
&m_pixelShader
)
);
CD3D11_BUFFER_DESC constantBufferDesc(sizeof
(ModelViewProjectionConstantBuffer), D3D11_BIND_
CONSTANT_BUFFER);
DX::ThrowIfFailed(
m_d3dDevice->CreateBuffer(
&constantBufferDesc,
nullptr,
&m_constantBuffer
)
);
});
auto createCubeTask = (createPSTask && createVSTask).then([this] () {
VertexPositionColor cubeVertices[] =
{
{XMFLOAT3(-0.5f, -0.5f, -0.5f), XMFLOAT3(0.0f, 0.0f, 0.0f)},
{XMFLOAT3(-0.5f, -0.5f, 0.5f), XMFLOAT3(0.0f, 0.0f, 1.0f)},
{XMFLOAT3(-0.5f, 0.5f, -0.5f), XMFLOAT3(0.0f, 1.0f, 0.0f)},
{XMFLOAT3(-0.5f, 0.5f, 0.5f), XMFLOAT3(0.0f, 1.0f, 1.0f)},
{XMFLOAT3( 0.5f, -0.5f, -0.5f), XMFLOAT3(1.0f, 0.0f, 0.0f)},
{XMFLOAT3( 0.5f, -0.5f, 0.5f), XMFLOAT3(1.0f, 0.0f, 1.0f)},
{XMFLOAT3( 0.5f, 0.5f, -0.5f), XMFLOAT3(1.0f, 1.0f, 0.0f)},
{XMFLOAT3( 0.5f, 0.5f, 0.5f), XMFLOAT3(1.0f, 1.0f, 1.0f)},
};
D3D11_SUBRESOURCE_DATA vertexBufferData = {0};
vertexBufferData.pSysMem = cubeVertices;
vertexBufferData.SysMemPitch = 0;
vertexBufferData.SysMemSlicePitch = 0;
CD3D11_BUFFER_DESC vertexBufferDesc(sizeof(cubeVertices), D3D11_BIND_VERTEX_BUFFER);
DX::ThrowIfFailed(
m_d3dDevice->CreateBuffer(
&vertexBufferDesc,
&vertexBufferData,
&m_vertexBuffer
)
);
unsigned short cubeIndices[] =
{
0,2,1, // -x
1,2,3,
4,5,6, // +x
5,7,6,
0,1,5, // -y
0,5,4,
2,6,7, // +y
2,7,3,
0,4,6, // -z
0,6,2,
1,3,7, // +z
1,7,5,
};
m_indexCount = ARRAYSIZE(cubeIndices);
D3D11_SUBRESOURCE_DATA indexBufferData = {0};
indexBufferData.pSysMem = cubeIndices;
indexBufferData.SysMemPitch = 0;
indexBufferData.SysMemSlicePitch = 0;
CD3D11_BUFFER_DESC indexBufferDesc(sizeof(cubeIndices), D3D11_BIND_INDEX_BUFFER);
DX::ThrowIfFailed(
m_d3dDevice->CreateBuffer(
&indexBufferDesc,
&indexBufferData,
&m_indexBuffer
)
);
});
createCubeTask.then([this] () {
m_loadingComplete = true;
});
}
// These resources need to be recreated every time the
window size is changed.
void RenderObject::CreateWindowSizeDependentResources()
{
// Store the window bounds so the next time we get a
SizeChanged event we can
// avoid rebuilding everything if the size is identical.
m_windowBounds = m_window->Bounds;
// Calculate the necessary swap chain and render target size in pixels.
float windowWidth = ConvertDipsToPixels(m_windowBounds.Width);
float windowHeight = ConvertDipsToPixels(m_windowBounds.Height);
// The width and height of the swap chain must be based on the window's
// landscape-oriented width and height. If the window is in a portrait
// orientation, the dimensions must be reversed.
m_displayOrientation = DisplayProperties::CurrentOrientation;
bool swapDimensions =
m_displayOrientation == DisplayOrientations::Portrait ||
m_displayOrientation == DisplayOrientations::PortraitFlipped;
m_d3dRenderTargetSize.Width = swapDimensions ?
windowHeight : windowWidth;
m_d3dRenderTargetSize.Height = swapDimensions ?
windowWidth : windowHeight;
if ((m_swapChainCoreWindow != nullptr) &&
((m_swapChainComposition != nullptr) || !m_panel))
{
HRESULT hr = S_OK;
if (m_swapChainComposition != nullptr)
{
// If the swap chain already exists, resize it.
hr = m_swapChainComposition->ResizeBuffers(
2, // Double-buffered swap chain.
static_cast<UINT>(m_d3dRenderTargetSize.Width),
static_cast<UINT>(m_d3dRenderTargetSize.Height),
DXGI_FORMAT_B8G8R8A8_UNORM,
0
);
}
// If the swap chain already exists, resize it.
hr = m_swapChainCoreWindow->ResizeBuffers(
2, // Double-buffered swap chain.
static_cast<UINT>(m_d3dRenderTargetSize.Width),
static_cast<UINT>(m_d3dRenderTargetSize.Height),
DXGI_FORMAT_B8G8R8A8_UNORM,
0
);
if (hr == DXGI_ERROR_DEVICE_REMOVED)
{
HandleDeviceLost();
return;
}
else
{
DX::ThrowIfFailed(hr);
}
}
else
{
// Otherwise, create a new one using the same adapter as the
existing Direct3D device.
ComPtr<IDXGIDevice1> dxgiDevice;
DX::ThrowIfFailed(
m_d3dDevice.As(&dxgiDevice)
);
ComPtr<IDXGIAdapter> dxgiAdapter;
DX::ThrowIfFailed(
dxgiDevice->GetAdapter(&dxgiAdapter)
);
ComPtr<IDXGIFactory2> dxgiFactory;
DX::ThrowIfFailed(
dxgiAdapter->GetParent(
__uuidof(IDXGIFactory2),
&dxgiFactory
)
);
DXGI_SWAP_CHAIN_DESC1 swapChainDesc = {0};
swapChainDesc.Width = static_cast<UINT>
(m_d3dRenderTargetSize.Width); // Match the size of the window.
swapChainDesc.Height = static_cast<UINT>
(m_d3dRenderTargetSize.Height);
swapChainDesc.Format = DXGI_FORMAT_B8G8R8A8_
UNORM; // This is the most common swap chain format.
swapChainDesc.Stereo = false;
swapChainDesc.SampleDesc.Count = 1; // Don't use multi-sampling.
swapChainDesc.SampleDesc.Quality = 0;
swapChainDesc.BufferUsage = DXGI_USAGE_RENDER_
TARGET_OUTPUT;
swapChainDesc.BufferCount = 2; // Use double-buffering to
minimize latency.
swapChainDesc.SwapEffect = DXGI_SWAP_EFFECT_
FLIP_SEQUENTIAL; // All Windows Store apps must
use this SwapEffect.
swapChainDesc.Flags = 0;
if (m_panel)
{
// The following two values are important for
Direct3D to interoperate with XAML.
swapChainDesc.Scaling = DXGI_SCALING_STRETCH;
swapChainDesc.AlphaMode = DXGI_ALPHA_MODE_IGNORE;
DX::ThrowIfFailed(
dxgiFactory->CreateSwapChainForComposition(
m_d3dDevice.Get(),
&swapChainDesc,
nullptr, // Allow on all displays.
&m_swapChainComposition
)
);
// Associate the new swap chain with the
SwapChainBackgroundPanel element.
ComPtr<ISwapChainBackgroundPanelNative> panelNative;
DX::ThrowIfFailed(
reinterpret_cast<IUnknown*>(m_panel)->QueryInterface(IID_
PPV_ARGS(&panelNative))
);
DX::ThrowIfFailed(
panelNative->SetSwapChain(m_swapChainComposition.Get())
);
}
if (m_swapChainCoreWindow == nullptr)
{
// Also bind to the CoreWindow object. No scaling.
swapChainDesc.Scaling = DXGI_SCALING_NONE;
swapChainDesc.AlphaMode = DXGI_ALPHA_MODE_IGNORE;
Windows::UI::Core::CoreWindow^ window = m_window.Get();
DX::ThrowIfFailed(
dxgiFactory->CreateSwapChainForCoreWindow(
m_d3dDevice.Get(),
reinterpret_cast<IUnknown*>(window),
&swapChainDesc,
nullptr, // Allow on all displays.
&m_swapChainCoreWindow
)
);
}
// Ensure that DXGI does not queue more than one frame at a time.
This both reduces latency and
// ensures that the application will only render after each VSync,
minimizing power consumption.
DX::ThrowIfFailed(
dxgiDevice->SetMaximumFrameLatency(1)
);
}
// Set the proper orientation for the swap chain, and generate the
// 3D matrix transformation for rendering to the rotated swap chain.
DXGI_MODE_ROTATION rotation = DXGI_MODE_
ROTATION_UNSPECIFIED;
switch (m_displayOrientation)
{
case DisplayOrientations::Landscape:
rotation = DXGI_MODE_ROTATION_IDENTITY;
m_displayOrientationTransform3D = XMFLOAT4X4
( // 0-degree Z-rotation
1.0f, 0.0f, 0.0f, 0.0f,
0.0f, 1.0f, 0.0f, 0.0f,
0.0f, 0.0f, 1.0f, 0.0f,
0.0f, 0.0f, 0.0f, 1.0f
);
break;
case DisplayOrientations::Portrait:
rotation = DXGI_MODE_ROTATION_ROTATE270;
m_displayOrientationTransform3D = XMFLOAT4X4
( // 90-degree Z-rotation
0.0f, 1.0f, 0.0f, 0.0f,
-1.0f, 0.0f, 0.0f, 0.0f,
0.0f, 0.0f, 1.0f, 0.0f,
0.0f, 0.0f, 0.0f, 1.0f
);
break;
case DisplayOrientations::LandscapeFlipped:
rotation = DXGI_MODE_ROTATION_ROTATE180;
m_displayOrientationTransform3D = XMFLOAT4X4
( // 180-degree Z-rotation
-1.0f, 0.0f, 0.0f, 0.0f,
0.0f, -1.0f, 0.0f, 0.0f,
0.0f, 0.0f, 1.0f, 0.0f,
0.0f, 0.0f, 0.0f, 1.0f
);
break;
case DisplayOrientations::PortraitFlipped:
rotation = DXGI_MODE_ROTATION_ROTATE90;
m_displayOrientationTransform3D = XMFLOAT4X4
( // 270-degree Z-rotation
0.0f, -1.0f, 0.0f, 0.0f,
1.0f, 0.0f, 0.0f, 0.0f,
0.0f, 0.0f, 1.0f, 0.0f,
0.0f, 0.0f, 0.0f, 1.0f
);
break;
default:
throw ref new Platform::FailureException();
}
if (m_panel != nullptr)
{
DX::ThrowIfFailed(
m_swapChainComposition->SetRotation(rotation)
);
// Create a Direct3D render target view of the swap chain back buffer.
ComPtr<ID3D11Texture2D> backBuffer1;
DX::ThrowIfFailed(
m_swapChainComposition->GetBuffer(0, IID_PPV_
ARGS(&backBuffer1))
);
DX::ThrowIfFailed(
m_d3dDevice->CreateRenderTargetView(
backBuffer1.Get(),
nullptr,
&m_d3dRenderTargetViewComp
)
);
DX::ThrowIfFailed(
m_swapChainComposition->SetRotation(rotation)
);
}
if (m_d3dRenderTargetViewWin == nullptr)
{
DX::ThrowIfFailed(
m_swapChainCoreWindow->SetRotation(rotation)
);
// Create a Direct3D render target view of the swap chain back buffer.
ComPtr<ID3D11Texture2D> backBuffer2;
DX::ThrowIfFailed(
m_swapChainCoreWindow->GetBuffer(0, IID_PPV_
ARGS(&backBuffer2))
);
DX::ThrowIfFailed(
m_d3dDevice->CreateRenderTargetView(
backBuffer2.Get(),
nullptr,
&m_d3dRenderTargetViewWin
)
);
}
// Create a depth stencil view for use with 3D rendering if needed.
CD3D11_TEXTURE2D_DESC depthStencilDesc(
DXGI_FORMAT_D24_UNORM_S8_UINT,
static_cast<UINT>(m_d3dRenderTargetSize.Width),
static_cast<UINT>(m_d3dRenderTargetSize.Height),
1,
1,
D3D11_BIND_DEPTH_STENCIL
);
ComPtr<ID3D11Texture2D> depthStencil;
DX::ThrowIfFailed(
m_d3dDevice->CreateTexture2D(
&depthStencilDesc,
nullptr,
&depthStencil
)
);
CD3D11_DEPTH_STENCIL_VIEW_DESC depthStencilViewDesc(D3D11_DSV_DIMENSION_TEXTURE2D);
DX::ThrowIfFailed(
m_d3dDevice->CreateDepthStencilView(
depthStencil.Get(),
&depthStencilViewDesc,
&m_d3dDepthStencilView
)
);
// Set the 3D rendering viewport to target the entire window.
CD3D11_VIEWPORT viewport(
0.0f,
0.0f,
m_d3dRenderTargetSize.Width,
m_d3dRenderTargetSize.Height
);
m_d3dContext->RSSetViewports(1, &viewport);
float aspectRatio = m_windowBounds.Width / m_windowBounds.Height;
float fovAngleY = 70.0f * XM_PI / 180.0f;
// Note that the m_displayOrientationTransform3D matrix is
post-multiplied here
// in order to correctly orient the scene to match the display orientation.
// This post-multiplication step is required for any draw calls that are
// made to the swap chain render target. For draw calls to other targets,
// this transform should not be applied.
XMStoreFloat4x4(
&m_constantBufferData.projection,
XMMatrixTranspose(
XMMatrixMultiply(
XMMatrixPerspectiveFovRH(
fovAngleY,
aspectRatio,
0.01f,
100.0f
),
XMLoadFloat4x4(&m_displayOrientationTransform3D)
)
)
);
#ifdef TEMPLATE_USING_D2D
// Generate the2D matrix transformation for rendering overlays.
switch (rotation)
{
case DXGI_MODE_ROTATION_ROTATE270:
m_displayOrientationTransform2D =
Matrix3x2F::Rotation(270.0f) *
Matrix3x2F::Translation(0.0f, m_windowBounds.Width);
break;
case DXGI_MODE_ROTATION_ROTATE180:
m_displayOrientationTransform2D =
Matrix3x2F::Rotation(180.0f) *
Matrix3x2F::Translation(m_windowBounds.Width,
m_windowBounds.Height);
break;
case DXGI_MODE_ROTATION_ROTATE90:
m_displayOrientationTransform2D =
Matrix3x2F::Rotation(90.0f) *
Matrix3x2F::Translation(m_windowBounds.Height, 0.0f);
break;
case DXGI_MODE_ROTATION_IDENTITY:
default:
m_displayOrientationTransform2D = Matrix3x2F::Identity();
break;
}
// Create a Direct2D target bitmap associated with the
// swap chain back buffer and set it as the current target.
D2D1_BITMAP_PROPERTIES1 bitmapProperties =
BitmapProperties1(
D2D1_BITMAP_OPTIONS_TARGET | D2D1_BITMAP_
OPTIONS_CANNOT_DRAW,
PixelFormat(DXGI_FORMAT_B8G8R8A8_UNORM, D2D1_ALPHA_MODE_PREMULTIPLIED),
m_dpi,
m_dpi
);
if (m_swapChainComposition != nullptr)
{
ComPtr<IDXGISurface> dxgiBackBuffer;
DX::ThrowIfFailed(
m_swapChainComposition->GetBuffer(0, IID_PPV_
ARGS(&dxgiBackBuffer))
);
DX::ThrowIfFailed(
m_d2dContext->CreateBitmapFromDxgiSurface(
dxgiBackBuffer.Get(),
&bitmapProperties,
&m_d2dTargetBitmapComposition
)
);
}
if (m_swapChainCoreWindow != nullptr)
{
ComPtr<IDXGISurface> dxgiBackBuffer;
DX::ThrowIfFailed(
m_swapChainCoreWindow->GetBuffer(0, IID_PPV_
ARGS(&dxgiBackBuffer))
);
DX::ThrowIfFailed(
m_d2dContext->CreateBitmapFromDxgiSurface(
dxgiBackBuffer.Get(),
&bitmapProperties,
&m_d2dTargetBitmapCoreWindow
)
);
}
m_hud.Initialize(
m_d2dDevice.Get(),
m_d2dContext.Get(),
m_dwriteFactory.Get(),
m_displayOrientationTransform2D,
m_windowBounds,
"Direct3D with D2D/CoreWindow",
m_projectDir + "Assets\\sdklogo.png"
);
m_pause.Initialize(
m_d2dDevice.Get(),
m_d2dContext.Get(),
m_dwriteFactory.Get(),
m_displayOrientationTransform2D,
m_windowBounds,
"PAUSED"
);
#endif
}
void RenderObject::Update(
_In_ uint64 tickDelta,
_In_ float timeDelta,
_In_ float leftover,
_In_ float lastFrameTime)
{
m_fpsCounter.Update(timeDelta);
// Eye is at (0,0.7,1.5), looking at point (0,-0.1,0) with the
up-vector along the y-axis.
XMVECTOR eye = XMVectorSet(0.0f, 0.7f, 1.5f, 0.0f);
XMVECTOR at = XMVectorSet(0.0f, -0.1f, 0.0f, 0.0f);
XMVECTOR up = XMVectorSet(0.0f, 1.0f, 0.0f, 0.0f);
m_ticks += tickDelta;
float animTicks = m_ticks + leftover;
// ((convert degrees to radians) convert seconds to ticks)
float radiansPerTick = XMConvertToRadians(safe_cast<float>
(m_degreesPerSecond)) / TICKS_PER_SECOND;
float animRadians = animTicks * radiansPerTick;
// Prepare to pass the view matrix, and updated model matrix,
to the shader
XMStoreFloat4x4(&m_constantBufferData.view,
XMMatrixTranspose(XMMatrixLookAtRH(eye, at, up)));
XMStoreFloat4x4(&m_constantBufferData.model,
XMMatrixTranspose(XMMatrixRotationY(animRadians)));
#ifdef TEMPLATE_USING_D2D
Platform::String^ fps = " - ";
Platform::String^ frameTime = " - ";
if (m_fpsCounter.Ready())
{
// The frame time-to-render data is a float, so we need to truncate
it to something readable
frameTime = ref new Platform::String(lastFrameTime.
ToString()->Begin(), 5);
fps = (m_fpsCounter.FPS()).ToString();
}
m_hud.Update("Frame time:\n" + frameTime + " ms",
fps + " FPS");
#endif
}
void RenderObject::Render()
{
// Choose the swap chain for the current view
ComPtr<ID3D11RenderTargetView> d3dRenderTargetView;
if (m_usePanel) d3dRenderTargetView = m_d3dRenderTargetViewComp;
else d3dRenderTargetView = m_d3dRenderTargetViewWin;
// Clear the render target
XMVECTORF32 midnightBlue = DirectX::Colors::MidnightBlue;
m_d3dContext->ClearRenderTargetView(
d3dRenderTargetView.Get(),
midnightBlue
);
m_d3dContext->ClearDepthStencilView(
m_d3dDepthStencilView.Get(),
D3D11_CLEAR_DEPTH,
1.0f,
0
);
// Loading is asynchronous. Only draw geometry afeter it's loaded.
if (!m_loadingComplete)
{
return;
}
// Set the render target for the draw operation.
m_d3dContext->OMSetRenderTargets(
1,
d3dRenderTargetView.GetAddressOf(),
m_d3dDepthStencilView.Get()
);
// Only update shader resources that have changed since the last frame.
m_d3dContext->UpdateSubresource(
m_constantBuffer.Get(),
0,
NULL,
&m_constantBufferData,
0,
0
);
// Set up the IA stage corresponding to the current draw operation.
UINT stride = sizeof(VertexPositionColor);
UINT offset = 0;
m_d3dContext->IASetVertexBuffers(
0,
1,
m_vertexBuffer.GetAddressOf(),
&stride,
&offset
);
m_d3dContext->IASetIndexBuffer(
m_indexBuffer.Get(),
DXGI_FORMAT_R16_UINT,
0
);
m_d3dContext->IASetPrimitiveTopology(D3D11_PRIMITIVE_
TOPOLOGY_TRIANGLELIST);
m_d3dContext->IASetInputLayout(m_inputLayout.Get());
// Set up the vertex shader corresponding to the current draw operation.
m_d3dContext->VSSetShader(
m_vertexShader.Get(),
nullptr,
0
);
m_d3dContext->VSSetConstantBuffers(
0,
1,
m_constantBuffer.GetAddressOf()
);
// Set up the pixel shader corresponding to the current draw operation.
m_d3dContext->PSSetShader(
m_pixelShader.Get(),
nullptr,
0
);
m_d3dContext->DrawIndexed(
m_indexCount,
0,
0
);
}
#ifdef TEMPLATE_USING_D2D
void RenderObject::RenderHud(bool paused)
{
// Choose the swap chain for the current view.
if (m_usePanel) m_d2dContext->
SetTarget(m_d2dTargetBitmapComposition.Get());
else m_d2dContext->
SetTarget(m_d2dTargetBitmapCoreWindow.Get());
// Grayscale text anti-aliasing is recommended for
all Windows Store apps.
m_d2dContext->
SetTextAntialiasMode(D2D1_TEXT_ANTIALIAS_
MODE_GRAYSCALE);
// Render the correct overlay content.
if (paused) m_pause.Render();
else m_hud.Render();
}
#endif
// Initialize the Direct3D resources required to run.
void RenderObject::Initialize( _In_ CoreWindow^ window )
{
Initialize(window, nullptr);
}
// Initialize the Direct3D resources required to run.
void RenderObject::Initialize(
_In_ CoreWindow^ window,
_In_ SwapChainBackgroundPanel^ panel
)
{
m_window = window;
if (panel != nullptr)
{
m_panel = panel;
m_usePanel = true;
}
CreateDeviceIndependentResources();
CreateDeviceResources();
CreateWindowSizeDependentResources();
SetDpi(DisplayProperties::LogicalDpi);
}
void RenderObject::SetPanel( _In_
SwapChainBackgroundPanel^ panel )
{
m_panel = panel;
}
void RenderObject::SwitchToCoreWindow()
{
m_usePanel = false;
// Draw a frame on the CoreWindow so that the user doesn't notice the switch.
Render();
Present();
}
// Immediately switches to the SCBP swap chain and renders the current frame on it.
void RenderObject::SwitchToSCBP()
{
if (m_panel == nullptr) return;
m_usePanel = true;
if (m_swapChainComposition == nullptr)
{
CreateWindowSizeDependentResources();
}
// Draw a frame on the SCBP so that the user doesn't notice the switch.
Render();
Present();
}
// Recreate all device resources and set them back to the current state.
void RenderObject::HandleDeviceLost()
{
// Reset these member variables to ensure that
UpdateForWindowSizeChange recreates all resources.
float dpi = m_dpi;
m_dpi = -1.0f;
m_windowBounds.Width = 0;
m_windowBounds.Height = 0;
DiscardViews();
m_swapChainComposition = nullptr;
m_swapChainCoreWindow = nullptr;
m_d3dDevice = nullptr;
m_d3dContext = nullptr;
m_loadingComplete = false;
CreateDeviceResources();
SetDpi(dpi);
UpdateForWindowSizeChange();
}
// Discard view resources. This is done before resizing the
window and before recreating the Direct3D device.
void RenderObject::DiscardViews()
{
ID3D11RenderTargetView* nullViews[] = {nullptr};
m_d3dContext->OMSetRenderTargets(ARRAYSIZE(nullViews),
nullViews, nullptr);
m_d3dRenderTargetViewComp = nullptr;
m_d3dRenderTargetViewWin = nullptr;
m_d3dDepthStencilView = nullptr;
#ifdef TEMPLATE_USING_D2D
m_d2dContext->SetTarget(nullptr);
m_d2dTargetBitmapCoreWindow = nullptr;
m_d2dTargetBitmapComposition = nullptr;
#endif
m_d3dContext->Flush();
}
// This method is called in the event handler for the
LogicalDpiChanged event.
void RenderObject::SetDpi(float dpi)
{
if (dpi != m_dpi)
{
// Save the updated DPI value.
m_dpi = dpi;
#ifdef TEMPLATE_USING_D2D
// Update Direct2D's stored DPI.
m_d2dContext->SetDpi(m_dpi, m_dpi);
#endif
// Often a DPI change implies a window size change.
In some cases Windows will issue
// both a size changed event and a DPI changed event.
In this case, the resulting bounds
// will not change, and the window resize code will only
be executed once.
UpdateForWindowSizeChange();
}
}
// This method is called in the event handler for the SizeChanged event.
void RenderObject::UpdateForWindowSizeChange()
{
// Only handle window size changed if there is no pending DPI change.
if (m_dpi != DisplayProperties::LogicalDpi)
{
return;
}
if (m_window->Bounds.Width != m_windowBounds.Width ||
m_window->Bounds.Height != m_windowBounds.Height ||
m_displayOrientation != DisplayProperties::CurrentOrientation)
{
DiscardViews();
CreateWindowSizeDependentResources();
}
}
// Method to deliver the final image to the display.
void RenderObject::Present()
{
// The application may optionally specify "dirty" or "scroll"
// rects to improve efficiency in certain scenarios.
DXGI_PRESENT_PARAMETERS parameters = {0};
// The first argument instructs DXGI to block until VSync,
putting the application
// to sleep until the next VSync. This ensures we don't waste
any cycles rendering
// frames that will never be displayed to the screen.
HRESULT hr;
if (m_usePanel)
{
hr = m_swapChainComposition->Present1(1, 0, ¶meters);
// Discard the contents of the render target.
// This is a valid operation only when the existing contents will be entirely
// overwritten. If dirty or scroll rects are used, this call should be removed.
m_d3dContext->DiscardView(m_d3dRenderTargetViewComp.Get());
}
else
{
hr = m_swapChainCoreWindow->Present1(1, 0, ¶meters);
m_d3dContext->DiscardView(m_d3dRenderTargetViewWin.Get());
}
// Discard the contents of the depth stencil.
m_d3dContext->DiscardView(m_d3dDepthStencilView.Get());
// If the device was removed either by a disconnect or a driver upgrade, we
// must recreate all device resources.
if (hr == DXGI_ERROR_DEVICE_REMOVED)
{
HandleDeviceLost();
}
else
{
DX::ThrowIfFailed(hr);
}
}
// Method to convert a length in device-independent pixels (DIPs) to a
length in physical pixels.
float RenderObject::ConvertDipsToPixels( _In_ float dips )
{
static const float dipsPerInch = 96.0f;
return floorf(dips * DisplayProperties::LogicalDpi / dipsPerInch +
0.5f); // Round to nearest integer.
} **
***SimpleDirect3DApps*))
***#include "pch.h"
#include "Common_DirectX\DirectXHelper.h"
#include "$safeprojectname$.h"
using namespace Windows::ApplicationModel::Core;
using namespace Windows::ApplicationModel::Activation;
using namespace Windows::UI::ApplicationSettings;
using namespace Windows::UI::Core;
using namespace Windows::Foundation;
using namespace Microsoft::WRL;
using namespace DirectX;
// The main function is only used to initialize our IFrameworkView class.
[Platform::MTAThread]
int main(Platform::Array<Platform::String^>^)
{
auto direct3DApplicationSource = ref new Direct3DApplicationSource();
CoreApplication::Run(direct3DApplicationSource);
return 0;
}
IFrameworkView^ Direct3DApplicationSource::CreateView()
{
return ref new $safeprojectname$();
}
$safeprojectname$::$safeprojectname$() :
m_visible(true),
m_paused(true)
{
}
// The first method called when the IFrameworkView is being created.
void $safeprojectname$::Initialize(CoreApplicationView^ applicationView)
{
// Register event handlers for app lifecycle. This example includes
Activated, so that we
// can make the CoreWindow active and start rendering the cube.
applicationView->Activated +=
ref new TypedEventHandler<CoreApplicationView^,
IActivatedEventArgs^>(
[this](Windows::ApplicationModel::Core::CoreApplicationView^
applicationView, Windows::ApplicationModel::
Activation::IActivatedEventArgs^ args)
{
// Run() won't start until the CoreWindow is activated.
CoreWindow::GetForCurrentThread()->Activate();
});
}
void $safeprojectname$::Load(Platform::String^ entryPoint)
{
}
// Called when the CoreWindow object is created (or re-created).
void $safeprojectname$::SetWindow(CoreWindow^ window)
{
// Register event handlers with the CoreWindow object.
window->SizeChanged +=
ref new TypedEventHandler<CoreWindow^,
WindowSizeChangedEventArgs^>(
[this](Windows::UI::Core::CoreWindow^ sender, Windows::UI::Core::WindowSizeChangedEventArgs^ args)
{
// Notify the rendering controller to set up new swap chains (and so on).
m_renderer.UpdateForWindowSizeChange();
});
window->VisibilityChanged +=
ref new TypedEventHandler<CoreWindow^, VisibilityChangedEventArgs^>(
[this](CoreWindow^ sender, VisibilityChangedEventArgs^ args)
{
m_paused = !sender->Visible;
m_visible = sender->Visible;
});
// Add an event handler to pause when the charms bar is activated.
CoreWindow::GetForCurrentThread()->Activated +=
ref new TypedEventHandler<CoreWindow^, WindowActivatedEventArgs^>(
[this] (CoreWindow^ sender, Windows::UI::Core::WindowActivatedEventArgs^ args)
{
switch (args->WindowActivationState)
{
case Windows::UI::Core::CoreWindowActivation
State::Deactivated:
m_paused = true;
break;
case CoreWindowActivationState::CodeActivated:
case CoreWindowActivationState::PointerActivated:
m_paused = false;
break;
}
});
// Add event handlers to recognize input.
window->KeyDown += ref new TypedEventHandler
<CoreWindow^, KeyEventArgs^>(
[this](CoreWindow^ sender, KeyEventArgs^ args)
{
switch (args->VirtualKey)
{
case Windows::System::VirtualKey::Escape:
// For example, pause when the escape key is pressed.
m_paused = !m_paused;
break;
default:
m_paused = false;
break;
}
});
window->PointerPressed += ref new TypedEventHandler
<CoreWindow^, PointerEventArgs^>(
[this](CoreWindow^ sender, PointerEventArgs^ args)
{
m_paused = false;
});
// If your app has internet-based functionality, uncomment the following
// code to add a Settings charm for the privacy policy.
/*
SettingsPane::GetForCurrentView()->CommandsRequested +=
ref new TypedEventHandler<SettingsPane^,
SettingsPaneCommandsRequestedEventArgs^>(
[this](SettingsPane^ sender,
SettingsPaneCommandsRequestedEventArgs^ args)
{
args->Request->ApplicationCommands->Append(
ref new SettingsCommand(
"privacyPolicy",
"Privacy Policy",
ref new Windows::UI::Popups::
UICommandInvokedHandler([=](Windows::UI::
Popups::IUICommand^ command)
{
// The URI to launch
// Be sure to replace this string with the URL
to your privacy policy.
auto uri = ref new Windows::Foundation::
Uri("<insert web url to your privacy policy here>");
// Launch the URI
concurrency::task<bool> launchUriOperation(Windows::System::Launcher::LaunchUriAsync(uri));
launchUriOperation.then([](bool success){});
})));
});
*/
// If your app has an app bar, uncomment the following code
to recognize
// the app bar gesture.
// If your DirectX app needs to use an app bar, you can create one by
// drawing it on the screen, recognizing input, and adding appropriate
// animations for showing/hiding the app bar.
/*
auto edgeGestures = Windows::UI::Input::Edge
Gesture::GetForCurrentView();
edgeGestures->Completed += ref new TypedEventHandler
<Windows::UI::Input::EdgeGesture^, Windows::UI::Input::Edge
GestureEventArgs^>(
[this](Windows::UI::Input::EdgeGesture^ gesture,
Windows::UI::Input::EdgeGestureEventArgs^ args)
{
// TODO: Add code here to raise your app bar implementation.
});
*/
// Set up rendering using Direct3D 11.1.
m_renderer.Initialize(window);
// Set initial conditions for animation.
m_renderer.Update(0, 0, 0.f, 0.f);
}
// This method is called after the window becomes active.
void $safeprojectname$::Run()
{
// Windows Store apps should not exit. App lifecycle events
are used instead.
while (true)
{
if (m_visible)
{
// Update the timer.
m_timer.Update();
if (!m_paused)
{
// Update the renderer if the animation isn't paused
m_renderer.Update(m_timer.TickDelta(), m_timer.TimeDelta(),
m_timer.LeftoverTime(), m_lastFrameTime);
}
// Process window events.
CoreWindow::GetForCurrentThread()->Dispatcher->ProcessEvents(CoreProcessEventsOption::ProcessAllIfPresent);
// Render the frame.
m_renderer.Render();
// Measure how long the frame took to render before drawing the
HUD and presenting the frame.
m_lastFrameTime = m_timer.MeasureFrameTime();
// Render the overlay.
m_renderer.RenderHud(m_paused);
// Swap the back buffer to the screen, and wait the app's
main thread until the next VSync.
m_renderer.Present();
}
else
{
CoreWindow::GetForCurrentThread()->Dispatcher->ProcessEvents(CoreProcessEventsOption::ProcessOneAndAllPending);
}
}
}
// Required for IFrameworkView.
// Terminate events do not cause Uninitialize to be called.
It will be called if your IFrameworkView
// class is torn down while the app is in the foreground.
void $safeprojectname$::Uninitialize()
{
} ***
***SimpleDirect3DApp.vcxproj.filters***
***<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns=
"http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup>
<Filter Include="Common_DirectX">
<UniqueIdentifier>$guid2$</UniqueIdentifier>
</Filter>
<Filter Include="Assets">
<UniqueIdentifier>$guid3$</UniqueIdentifier>
</Filter>
</ItemGroup>
<ItemGroup>
<ClInclude Include="Common_DirectX\DirectXHelper.h">
<Filter>Common_DirectX</Filter>
</ClInclude>
<ClInclude Include="Common_DirectX\FpsCounter.h">
<Filter>Common_DirectX</Filter>
</ClInclude>
<ClInclude Include="Common_DirectX\StepTimer.h">
<Filter>Common_DirectX</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<Image Include="Assets\Logo.png">
<Filter>Assets</Filter>
</Image>
<Image Include="Assets\SmallLogo.png">
<Filter>Assets</Filter>
</Image>
<Image Include="Assets\StoreLogo.png">
<Filter>Assets</Filter>
</Image>
<Image Include="Assets\SplashScreen.png">
<Filter>Assets</Filter>
</Image>
<Image Include="Assets\sdklogo.png">
<Filter>Assets</Filter>
</Image>
</ItemGroup>
</Project> ***
***SimpleDirect3DApp***
***#pragma once
#include "Common_DirectX\\StepTimer.h"
#include "RenderObject.h"
[Windows::Foundation::Metadata::WebHostHiddenAttribute]
ref class $safeprojectname$ sealed : public Windows::
ApplicationModel::Core::IFrameworkView
{
public:
$safeprojectname$();
// IFrameworkView methods.
virtual void Initialize(Windows::ApplicationModel::Core::
CoreApplicationView^ applicationView);
virtual void SetWindow(Windows::UI::Core::CoreWindow^ window);
virtual void Load(Platform::String^ entryPoint);
virtual void Run();
virtual void Uninitialize();
private:
RenderObject m_renderer; // The rendering class.
StepTimer m_timer; // Rendering loop timer.
bool m_windowClosed;
bool m_paused;
bool m_visible;
float m_lastFrameTime;
};
[Windows::Foundation::Metadata::WebHostHiddenAttribute]
ref class Direct3DApplicationSource sealed : Windows::ApplicationModel::Core::IFrameworkViewSource
{
public:
virtual Windows::ApplicationModel::Core::IFrameworkView^ CreateView();
}; ***
***SimplePixelShader.hlsl***
//// THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF
//// ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO
//// THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
//// PARTICULAR PURPOSE.
////
//// Copyright (c) Microsoft Corporation. All rights reserved
struct PixelShaderInput
{
float4 pos : SV_POSITION;
float3 color : COLOR0;
};
// A pass-through for the (blended) color data.
float4 main(PixelShaderInput input) : SV_TARGET
{
return float4(input.color,1.0f);
}
****
**<PackageManifest Version="2.0.0" xmlns=
"http://schemas.microsoft.com/developer/vsx-schema/2011">
<Metadata>
<Identity Id="GDC2013GameTemplates..
282844d1-1219-4d9b-a990-8ed263e3159d" Version=
"1.01" Language="en-US" Publisher="Microsoft Windows SDK" />
<DisplayName>GDC 2013 Game Templates</DisplayName>
<Description xml:space="preserve">Create realtime,
graphics-intensive Windows Store games using DirectX and
native code.</Description>
<License>ms-lpl-1.1.rtf</License>
<GettingStartedGuide>http://go.microsoft.com/fwlink/?prd=
11966</GettingStartedGuide>
<Icon>game_template.ico</Icon>
<PreviewImage>GDC2013GameTemplates.png</PreviewImage>
<Tags>Direct3D, Direct2D, DirectX, XAML, Windows Store,
app, game, template, graphics</Tags>
</Metadata>
<Installation>
<InstallationTarget Version="[11.0,12.0)" Id=
"Microsoft.VisualStudio.Premium" />
<InstallationTarget Version="[11.0,12.0)" Id=
"Microsoft.VisualStudio.Pro" />
<InstallationTarget Version="[11.0,12.0)" Id=
"Microsoft.VisualStudio.VSWinExpress" />
<InstallationTarget Version="[11.0,12.0)" Id=
"Microsoft.VisualStudio.Ultimate" />
</Installation>
<Dependencies>
<Dependency Id="Microsoft.Windows.DevelopmentKit.Metro"
DisplayName="Microsoft Windows 8.0 Metro style app SDK"
Version="[8.0,9.0)" />
</Dependencies>
<Assets>
<Asset Type="Microsoft.VisualStudio.ProjectTemplate" Path=
"ProjectTemplates" />
</Assets>
</PackageManifest> ****
<?xml version="1.0" encoding="utf-8" ?>
<Default Extension="vsixmanifest" ContentType="text/xml" />
<Default Extension="png" ContentType="application/octet-stream" />
<Default Extension="ico" ContentType="application/octet-stream" />
<Default Extension="rtf" ContentType="text/richtext" />
<Default Extension="zip" ContentType="application/zip" />
</Types>
**
GDC 2013 Windows Developer
Content Direct3D Game Templates
Introduction
The Windows Developer Content GDC 2013 Direct3D game templates are a set of Visual Studio 2012 templates for Windows Store Direct3D apps. The GDC 2013 versions of the content incorporate code from these templates in the coding examples.
The ZIP file includes a single VSIX with three templates:
- DirectX game (CoreWindow). This template constructs a basic CoreWindow view provider with a game-development friendly layout that demonstrates DirectX 11.1 and C++ coding best practices for Windows Store apps.
- DirectX game (XAML). This template uses the XAML framework with SwapChainBackgroundPanel to display Direct3D 11.1 rendering output. It demonstrates DirectX 11.1 and C++ coding best practices for Windows Store apps with XAML.
- DirectX game (XAML and CoreWindow). This template creates two swap chains – one with a CoreWindow view provider and the other with the XAML framework and SwapChainBackgroundPanel – and allows you to dynamically switch between the two based on game state or user input.
The following GDC 2013 documentation incorporates these samples:
Prepare your Windows Store DirectX game programming environment
Port from DirectX 9 to Windows Store
Port from OpenGL ES 2.0 to Direct3D 11.1
Using the templates
To use these templates, download the ZIP file and open it. Extract the file GDC2013GameTemplates.vsix and double-click on it. This will install the templates. If Visual Studio 2012 was open when you ran the VSIX installer, close it and re-open it. When you go to FILE->New Project, the three templates will appear under the Visual C++ project node.
NOTE The VSIX installer must be extracted from the archive before installation. The SLN and VCXPROJ files exist only to meet validation requirements and can be ignored.
Source Code Files
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&
沒有留言:
張貼留言
if you like make fds, wellcome you here~~anytime***
my free place for everyones who want the good software,
come & download them~ wellcome!!