developing a windows store app using c++ and directx
DESCRIPTION
Developing a Windows Store app using C++ and DirectX. Phil Napieralski Program Manager 3-109. Agenda. Fundamentals (DirectX) What is XAML? Why interop ? More fundamentals (C++) Registering events Windows Store app features Making money. Graphics language of choice. - PowerPoint PPT PresentationTRANSCRIPT
![Page 1: Developing a Windows Store app using C++ and DirectX](https://reader035.vdocuments.site/reader035/viewer/2022062314/56812cab550346895d915919/html5/thumbnails/1.jpg)
Developing a Windows Store app using C++ and DirectXPhil NapieralskiProgram Manager3-109
![Page 2: Developing a Windows Store app using C++ and DirectX](https://reader035.vdocuments.site/reader035/viewer/2022062314/56812cab550346895d915919/html5/thumbnails/2.jpg)
Fundamentals (DirectX)What is XAML? Why interop?More fundamentals (C++)Registering eventsWindows Store app featuresMaking money
Agenda
![Page 3: Developing a Windows Store app using C++ and DirectX](https://reader035.vdocuments.site/reader035/viewer/2022062314/56812cab550346895d915919/html5/thumbnails/3.jpg)
Graphics language of choice
HTML5, JavaScript and CSS3
C# or Visual Basic .NET and XAML
Immersive 3D using DirectX 11.1
Combination of DirectX 11.1 and XAML
![Page 4: Developing a Windows Store app using C++ and DirectX](https://reader035.vdocuments.site/reader035/viewer/2022062314/56812cab550346895d915919/html5/thumbnails/4.jpg)
Fundamentals (DirectX)
![Page 5: Developing a Windows Store app using C++ and DirectX](https://reader035.vdocuments.site/reader035/viewer/2022062314/56812cab550346895d915919/html5/thumbnails/5.jpg)
DirectX fundamentalsSet up Direct3D device and contextUse the Direct3D device structure for low-frequency operationsUse the Context structure for high-frequency operations
Set up your shaders
Set up the swap chain
![Page 6: Developing a Windows Store app using C++ and DirectX](https://reader035.vdocuments.site/reader035/viewer/2022062314/56812cab550346895d915919/html5/thumbnails/6.jpg)
D3D11CreateDevice( /* … */ &device, // Returns the Direct3D device created. &m_featureLevel, // Returns feature level of the device. &context // Returns the device immediate context.)
The Direct3D device
![Page 7: Developing a Windows Store app using C++ and DirectX](https://reader035.vdocuments.site/reader035/viewer/2022062314/56812cab550346895d915919/html5/thumbnails/7.jpg)
struct SimpleVertex {
XMFLOAT3 pos;
XMFLOAT3 color;
};
// Create the shaders
m_d3dDevice->CreateVertexShader( … );
m_d3dDevice->CreatePixelShader( … );
// Define the input to the vertex shader
m_d3dDevice->CreateInputLayout( … &vertexShaderByteCode, &layoutdesc, … );
Shaders
![Page 8: Developing a Windows Store app using C++ and DirectX](https://reader035.vdocuments.site/reader035/viewer/2022062314/56812cab550346895d915919/html5/thumbnails/8.jpg)
Without XAML
dxgiFactory->CreateSwapChainForCoreWindow(
m_d3dDevice.Get(),
reinterpret_cast<IUnknown*>(window),
&swapChainDesc,
nullptr,
&m_swapChain
)
The swap chain
With XAML (SwapChainBackgroundPanel)
dxgiFactory->CreateSwapChainForComposition(
m_d3dDevice.Get(),
&swapChainDesc,
nullptr,
&m_swapChain
)
// Get XAML element into ComPtr<ISwapChainBackgroundPanelNative>
// Set its swap chain...
![Page 9: Developing a Windows Store app using C++ and DirectX](https://reader035.vdocuments.site/reader035/viewer/2022062314/56812cab550346895d915919/html5/thumbnails/9.jpg)
Without XAML
dxgiFactory->CreateSwapChainForCoreWindow(
m_d3dDevice.Get(),
reinterpret_cast<IUnknown*>(window),
&swapChainDesc,
nullptr,
&m_swapChain
)
The swap chain
With XAML (SwapChainBackgroundPanel)
dxgiFactory->CreateSwapChainForComposition(
m_d3dDevice.Get(),
&swapChainDesc,
nullptr,
&m_swapChain
)
// Get XAML element into ComPtr<ISwapChainBackgroundPanelNative> ...
// Set its swap chain ...
![Page 10: Developing a Windows Store app using C++ and DirectX](https://reader035.vdocuments.site/reader035/viewer/2022062314/56812cab550346895d915919/html5/thumbnails/10.jpg)
What is XAML? Why interop?
![Page 11: Developing a Windows Store app using C++ and DirectX](https://reader035.vdocuments.site/reader035/viewer/2022062314/56812cab550346895d915919/html5/thumbnails/11.jpg)
In-box controls for Windows Store apps
App bar
List box
Hyperlink
Check boxProgress bar
Text box
Password
Progress ring
Tooltip
GridButton
FlipView
Combo box
Scroll bar
Context menu
Slider
Toggle switch
Semantic Zoom
Panning indicator
Rating
ListView
Flyout
Radio button
Clear button
Reveal button
Spell checking
![Page 12: Developing a Windows Store app using C++ and DirectX](https://reader035.vdocuments.site/reader035/viewer/2022062314/56812cab550346895d915919/html5/thumbnails/12.jpg)
To XAML or not to XAML?
XAML interoperates nicely with DirectX in various scenarios
Combine ease of XAML for 2D, power of DirectX for 3D
Make the XAML interop decision up front
![Page 13: Developing a Windows Store app using C++ and DirectX](https://reader035.vdocuments.site/reader035/viewer/2022062314/56812cab550346895d915919/html5/thumbnails/13.jpg)
Demo
Comparison: DirectX vs. XAML
![Page 14: Developing a Windows Store app using C++ and DirectX](https://reader035.vdocuments.site/reader035/viewer/2022062314/56812cab550346895d915919/html5/thumbnails/14.jpg)
SwapChainBackgroundPanelExample: XAML for UI/HUD, Direct3D for graphics
XAML interop scenarios
See XAML DirectX 3D shooting game sample on MSDN
![Page 15: Developing a Windows Store app using C++ and DirectX](https://reader035.vdocuments.site/reader035/viewer/2022062314/56812cab550346895d915919/html5/thumbnails/15.jpg)
SurfaceImageSourceExample: Use DirectX inside a XAML element
XAML interop scenarios
See XAML SurfaceImageSource DirectX Interop Sample on MSDN
![Page 16: Developing a Windows Store app using C++ and DirectX](https://reader035.vdocuments.site/reader035/viewer/2022062314/56812cab550346895d915919/html5/thumbnails/16.jpg)
VirtualSurfaceImageSourceExample: Bing maps for the Windows Store
XAML interop scenarios
See May talk by Jesse Bishop, “Combining XAML and DirectX in Windows Store apps”
![Page 17: Developing a Windows Store app using C++ and DirectX](https://reader035.vdocuments.site/reader035/viewer/2022062314/56812cab550346895d915919/html5/thumbnails/17.jpg)
More fundamentals (C++)
![Page 18: Developing a Windows Store app using C++ and DirectX](https://reader035.vdocuments.site/reader035/viewer/2022062314/56812cab550346895d915919/html5/thumbnails/18.jpg)
CoreWindow and IFrameworkViewCoreWindowReplacement for Win32 hWndManages screen layoutProvides app inputUsing event handler model
IFrameworkViewEffectively the new App Object classEnables OS to initialize app, deliver core OS resourcesYou will implement 5 methods
![Page 19: Developing a Windows Store app using C++ and DirectX](https://reader035.vdocuments.site/reader035/viewer/2022062314/56812cab550346895d915919/html5/thumbnails/19.jpg)
IFrameworkView methods
Called on application launch
Register application events here
OS assigns CoreWindow to your app
Register window events here
Parameter tells us from where the app was launched
Put your rendering loop in here
3 seconds to get here to start handling events
Rarely executed
Generally leave empty
Initialize Load Run UninitializeSetWindow
![Page 20: Developing a Windows Store app using C++ and DirectX](https://reader035.vdocuments.site/reader035/viewer/2022062314/56812cab550346895d915919/html5/thumbnails/20.jpg)
ref class MyFrameworkView : public IFrameworkView{public: // IFrameworkView Methods virtual void Initialize(CoreApplicationView^ applicationView); virtual void SetWindow(CoreWindow^ window); virtual void Load(String^ entryPoint); virtual void Run(); virtual void Uninitialize();
// ...
Required IFrameworkView methods
![Page 21: Developing a Windows Store app using C++ and DirectX](https://reader035.vdocuments.site/reader035/viewer/2022062314/56812cab550346895d915919/html5/thumbnails/21.jpg)
Registering events
![Page 22: Developing a Windows Store app using C++ and DirectX](https://reader035.vdocuments.site/reader035/viewer/2022062314/56812cab550346895d915919/html5/thumbnails/22.jpg)
Where to register eventsInitialize methodApplication-wide eventsExample: Suspend and resume
SetWindow methodApp window-specific eventsExample: Window-size-changed and input events
![Page 23: Developing a Windows Store app using C++ and DirectX](https://reader035.vdocuments.site/reader035/viewer/2022062314/56812cab550346895d915919/html5/thumbnails/23.jpg)
There are many eventsSuspendResumePointerPressedPointerMovedKeyDownKeyUpSizeChanged…
![Page 24: Developing a Windows Store app using C++ and DirectX](https://reader035.vdocuments.site/reader035/viewer/2022062314/56812cab550346895d915919/html5/thumbnails/24.jpg)
m_window->SizeChanged += ref new
TypedEventHandler<CoreWindow^,WindowSizeChangedEventArgs^> (
this,
&Framework::OnWindowSizeChanged
);
Registering the SizeChanged event
![Page 25: Developing a Windows Store app using C++ and DirectX](https://reader035.vdocuments.site/reader035/viewer/2022062314/56812cab550346895d915919/html5/thumbnails/25.jpg)
void Framework::OnWindowSizeChanged(CoreWindow^ sender, WindowSizeChangedEventArgs^ args)
{
using Windows::UI::ViewManagement;if(ApplicationView::Value == ApplicationViewState::Snapped) {
/* snapped specific code */}/* respond to new window size … */
}
// See Snap sample on MSDN
The SizeChanged event
![Page 26: Developing a Windows Store app using C++ and DirectX](https://reader035.vdocuments.site/reader035/viewer/2022062314/56812cab550346895d915919/html5/thumbnails/26.jpg)
CoreApplication::Suspending += ref new EventHandler<SuspendingEventArgs^>(this, &Framework::OnSuspending);
CoreApplication::Resuming += ref new EventHandler<Platform::Object^>(this, &Framework::OnResuming);
// ...
void Framework::OnSuspending(Platform::Object^ sender, SuspendingEventArgs^ args) { // Save app state here}
void Framework::OnResuming(Platform::Object^ sender, Platform::Object^ args) { // Restore app state here}
Process Lifetime Management (PLM) events
![Page 27: Developing a Windows Store app using C++ and DirectX](https://reader035.vdocuments.site/reader035/viewer/2022062314/56812cab550346895d915919/html5/thumbnails/27.jpg)
Get going quickly
![Page 28: Developing a Windows Store app using C++ and DirectX](https://reader035.vdocuments.site/reader035/viewer/2022062314/56812cab550346895d915919/html5/thumbnails/28.jpg)
Getting startedUse the Visual Studio 2012 templates for a quick startDirect3D template for pure C++ and DirectXDirect2D template for added XAML support
Reference the samplesNeed a feature? Copy and paste from the corresponding sample!
Use the documentation at dev.windows.com
![Page 29: Developing a Windows Store app using C++ and DirectX](https://reader035.vdocuments.site/reader035/viewer/2022062314/56812cab550346895d915919/html5/thumbnails/29.jpg)
Demo
Templates
![Page 30: Developing a Windows Store app using C++ and DirectX](https://reader035.vdocuments.site/reader035/viewer/2022062314/56812cab550346895d915919/html5/thumbnails/30.jpg)
Windows Store app features
![Page 31: Developing a Windows Store app using C++ and DirectX](https://reader035.vdocuments.site/reader035/viewer/2022062314/56812cab550346895d915919/html5/thumbnails/31.jpg)
Live tilesusing namespace Windows::UI::Notifications;using namespace Windows::Data::Xml::Dom;
auto tileXml = ref new XmlDocument();tileXml->LoadXml("<tile>"…"</tile>");
TileUpdateManager::CreateTileUpdaterForApplication()->Update(ref new TileNotification(tileXml)
);
See App tiles and badges sample on MSDN
![Page 32: Developing a Windows Store app using C++ and DirectX](https://reader035.vdocuments.site/reader035/viewer/2022062314/56812cab550346895d915919/html5/thumbnails/32.jpg)
Using templates for bindingtileXmlString = "<tile>"+ "<visual>”+ "<binding template=‘TileWideText03'>"+ "<text id='1'>My first tile notification!</text>"+ "</binding>"+ "</visual>"+ "</tile>";
// See Build 3-101, “Alive with activity” by Kraig Brockschmidt
See App tiles and badges sample on MSDN
![Page 33: Developing a Windows Store app using C++ and DirectX](https://reader035.vdocuments.site/reader035/viewer/2022062314/56812cab550346895d915919/html5/thumbnails/33.jpg)
Toastusing namespace Windows::UI::Notifications;using namespace Windows::Data::Xml::Dom;
auto toastXml = ref new XmlDocument();auto toastXmlString = "<toast>”…”</toast>";toastXml->LoadXml(toastXmlString);
auto toast = ref new ToastNotification(toastXml);
ToastNotificationManager::CreateToastNotifier()->Show(toast);
![Page 34: Developing a Windows Store app using C++ and DirectX](https://reader035.vdocuments.site/reader035/viewer/2022062314/56812cab550346895d915919/html5/thumbnails/34.jpg)
Scheduled toasttoastXml->LoadXml(toastXmlString);
auto toast = ref new ToastNotification(toastXml);
auto cal = ref new Windows::Globalization::Calendar();cal->SetToNow();cal->AddSeconds(7);ToastNotificationManager::CreateToastNotifier()->AddToSchedule(ref new ScheduledToastNotification(toastXml,cal->GetDateTime()));
// Remember to declare toast in your app manifest!
![Page 35: Developing a Windows Store app using C++ and DirectX](https://reader035.vdocuments.site/reader035/viewer/2022062314/56812cab550346895d915919/html5/thumbnails/35.jpg)
App bar and edge gesturesIn C++, EdgeGesture->Completed event fires in three casesSwipe up from bottom (or down from top) of touch screenWindows logo key+Z on keyboardRight mouse button click
Draw app bar using Direct2D
![Page 36: Developing a Windows Store app using C++ and DirectX](https://reader035.vdocuments.site/reader035/viewer/2022062314/56812cab550346895d915919/html5/thumbnails/36.jpg)
using namespace Windows::UI::Input;
EdgeGesture::GetForCurrentView()->Completed += ref new
TypedEventHandler<EdgeGesture^, EdgeGestureEventArgs^>(
this, &InputController::OnCompleted
);
void InputController::OnCompleted(EdgeGesture^,EdgeGestureEventArgs^){
// Check device orientation and draw app bar…
}
The edge gesture event
![Page 37: Developing a Windows Store app using C++ and DirectX](https://reader035.vdocuments.site/reader035/viewer/2022062314/56812cab550346895d915919/html5/thumbnails/37.jpg)
Charms (Share)using namespace Windows::ApplicationModel::DataTransfer;DataTransferManager::GetForCurrentView()->DataRequested += ref new TypedEventHandler<DataTransferManager^,DataRequestedEventArgs^>( &App::onShare );
void App::onShare(DataTransferManager^ sender, DataRequestedEventArgs^ args){auto requestData = args->Request->Data;requestData->Properties->Title = "High Score";requestData->Properties->Description = “My High Score";requestData->SetText(“I just got a new high score!“);
/* … */});
![Page 38: Developing a Windows Store app using C++ and DirectX](https://reader035.vdocuments.site/reader035/viewer/2022062314/56812cab550346895d915919/html5/thumbnails/38.jpg)
Charms (Settings)using namespace Windows::UI::ApplicationSettings;SettingsPane::GetForCurrentView()->CommandsRequested += ref new TypedEventHandler<SettingsPane^,SettingsPaneCommandsRequestedEventArgs^>(
&MyApp::OnCommandsRequested );
![Page 39: Developing a Windows Store app using C++ and DirectX](https://reader035.vdocuments.site/reader035/viewer/2022062314/56812cab550346895d915919/html5/thumbnails/39.jpg)
More charms (Settings)using namespace Windows::UI::ApplicationSettings;void MyApp::OnCommandsRequested(SettingsPane^ settingsPane, SettingsPaneCommandsRequestedEventArgs^ args){ UICommandInvokedHandler^ handler = ref new UICommandInvokedHandler(this, &Scenario::onAudio);
SettingsCommand^ audioCommand = ref new SettingsCommand("audioPage", "audio", handler);
// Make it visible args->Request->ApplicationCommands->Append(audioCommand);
// Add additional settings ...}
![Page 40: Developing a Windows Store app using C++ and DirectX](https://reader035.vdocuments.site/reader035/viewer/2022062314/56812cab550346895d915919/html5/thumbnails/40.jpg)
More charms (Settings)void Scenario::OnAudio(IUICommand^ command) { // Draw audio settings using Direct2D ...}
Source code from App Settings Sample on MSDN
![Page 41: Developing a Windows Store app using C++ and DirectX](https://reader035.vdocuments.site/reader035/viewer/2022062314/56812cab550346895d915919/html5/thumbnails/41.jpg)
Saving dataWindows::Storage::ApplicationData for app data
Use File I/O or cloud services for big data
If the app crashes, don’t load this data!
Data physically at %localappdata%\packages
![Page 42: Developing a Windows Store app using C++ and DirectX](https://reader035.vdocuments.site/reader035/viewer/2022062314/56812cab550346895d915919/html5/thumbnails/42.jpg)
Saving to local hard driveauto settingsValues = Windows::Storage::ApplicationData::Current->LocalSettings->Values;float m_time = safe_cast<IPropertyValue^>(
settingsValues->Lookup(“time") )->GetSingle();settingsValues->Insert(“time", PropertyValue::CreateSingle(m_time));
![Page 43: Developing a Windows Store app using C++ and DirectX](https://reader035.vdocuments.site/reader035/viewer/2022062314/56812cab550346895d915919/html5/thumbnails/43.jpg)
Saving to the cloudauto settingsValues = Windows::Storage::ApplicationData::Current->RoamingSettings->Values;float m_time = safe_cast<IPropertyValue^>(
settingsValues->Lookup(“time") )->GetSingle();settingsValues->Insert(“time", PropertyValue::CreateSingle(m_time));
// See Build 3-126, “The Story of State” by Kraig Brockschmidt
![Page 44: Developing a Windows Store app using C++ and DirectX](https://reader035.vdocuments.site/reader035/viewer/2022062314/56812cab550346895d915919/html5/thumbnails/44.jpg)
Making money
![Page 45: Developing a Windows Store app using C++ and DirectX](https://reader035.vdocuments.site/reader035/viewer/2022062314/56812cab550346895d915919/html5/thumbnails/45.jpg)
Select a time period for your trial
Let the Windows Store handle the rest
Handling trials
![Page 46: Developing a Windows Store app using C++ and DirectX](https://reader035.vdocuments.site/reader035/viewer/2022062314/56812cab550346895d915919/html5/thumbnails/46.jpg)
Using the Windows Store APIStore API is in Windows::ApplicationModel::Store
Use CurrentApp::LicenseInformation to check trial information
When testing, use CurrentAppSimulator
Check out the following resources for more information:Build 3-121, “Making money with your app on the Windows Store” by Drew Robbins“Monetization Strategies for Windows 8 Games” by Shai Hinitz from GDC 2012
![Page 47: Developing a Windows Store app using C++ and DirectX](https://reader035.vdocuments.site/reader035/viewer/2022062314/56812cab550346895d915919/html5/thumbnails/47.jpg)
Demo
Marble Maze
![Page 48: Developing a Windows Store app using C++ and DirectX](https://reader035.vdocuments.site/reader035/viewer/2022062314/56812cab550346895d915919/html5/thumbnails/48.jpg)
Time to codeGet Windows RTM trial and Visual Studio 2012 from dev.windows.com
Get going quickly with the templates
Understand where the fundamentals fit in
Try adding Windows Store features to the templatesLive tilesToastAppBar/EdgeGestureSaving data locally and to the cloudFeatures that can help you make money (for example, trials and in-app purchases)
![Page 49: Developing a Windows Store app using C++ and DirectX](https://reader035.vdocuments.site/reader035/viewer/2022062314/56812cab550346895d915919/html5/thumbnails/49.jpg)
Previous talks“Combining XAML and DirectX in Windows Store apps” by Jesse Bishop“Monetization Strategies for Windows 8 Games” by Shai Hinitz
Other resources at //BuildCheck out the graphics talks (Build 3-112 and 3-113)Build 3-101 for more info about live tiles and toastBuild 3-126 for more info about app stateBuild 3-121 for more info about how to make money
Resources
Please submit session evals on the Build Windows 8 App or at http://aka.ms/BuildSessions
![Page 50: Developing a Windows Store app using C++ and DirectX](https://reader035.vdocuments.site/reader035/viewer/2022062314/56812cab550346895d915919/html5/thumbnails/50.jpg)
• Develop: http://msdn.microsoft.com/en-US/windows/apps/br229512
• Design: http://design.windows.com/
• Samples: http://code.msdn.microsoft.com/windowsapps/Windows-8-Modern-Style-App-Samples
• Videos: http://channel9.msdn.com/Windows
Resources
Please submit session evals by using the Build Windows 8 appor at http://aka.ms/BuildSessions
![Page 51: Developing a Windows Store app using C++ and DirectX](https://reader035.vdocuments.site/reader035/viewer/2022062314/56812cab550346895d915919/html5/thumbnails/51.jpg)
© 2012 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are or may be registered trademarks and/or trademarks in the U.S. and/or other countries.The information herein is for informational purposes only and represents the current view of Microsoft Corporation as of the date of this presentation. Because Microsoft must respond to changing market conditions, it should not be interpreted to be a commitment on the part of Microsoft, and Microsoft cannot guarantee the accuracy of any information provided after the date of this presentation. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS PRESENTATION.