1 / 51

Developing a Windows Store app using C++ and DirectX

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.

Download Presentation

Developing a Windows Store app using C++ and DirectX

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Developing a Windows Store app using C++ and DirectX Phil Napieralski Program Manager 3-109

  2. Agenda • Fundamentals (DirectX) • What is XAML? Why interop? • More fundamentals (C++) • Registering events • Windows Store app features • Making money

  3. 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

  4. Fundamentals (DirectX)

  5. DirectX fundamentals • Set up Direct3D device and context • Use the Direct3D device structure for low-frequency operations • Use the Context structure for high-frequency operations • Set up your shaders • Set up the swap chain

  6. The Direct3D device • D3D11CreateDevice( • /* … */ • &device, // Returns the Direct3D device created. • &m_featureLevel, // Returns feature level of the device. • &context // Returns the device immediate context. • )

  7. Shaders • structSimpleVertex { • 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, … );

  8. 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... • Without XAML • dxgiFactory->CreateSwapChainForCoreWindow( • m_d3dDevice.Get(), • reinterpret_cast<IUnknown*>(window), • &swapChainDesc, • nullptr, • &m_swapChain • )  

  9. 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 ... • Without XAML • dxgiFactory->CreateSwapChainForCoreWindow( • m_d3dDevice.Get(), • reinterpret_cast<IUnknown*>(window), • &swapChainDesc, • nullptr, • &m_swapChain • )  

  10. What is XAML? Why interop?

  11. In-box controls for Windows Store apps Button Grid Text box Clear button Spell checking Check box Radio button Progress ring Progress bar Hyperlink Combo box Context menu Flyout Password Reveal button ListView Semantic Zoom Rating Slider FlipView List box Scroll bar Toggle switch Tooltip Panning indicator App bar

  12. 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 To XAML or not to XAML?

  13. Comparison: DirectX vs. XAML • Demo

  14. XAML interop scenarios • SwapChainBackgroundPanel • Example: XAML for UI/HUD, Direct3D for graphics • See XAML DirectX 3D shooting game sample on MSDN

  15. XAML interop scenarios • SurfaceImageSource • Example: Use DirectX inside a XAML element See XAML SurfaceImageSource DirectX Interop Sample on MSDN

  16. XAML interop scenarios • VirtualSurfaceImageSource • Example: Bing maps for the Windows Store See May talk by Jesse Bishop, “Combining XAML and DirectX in Windows Store apps”

  17. More fundamentals (C++)

  18. CoreWindow and IFrameworkView • CoreWindow • Replacement for Win32 hWnd • Manages screen layout • Provides app input • Using event handler model • IFrameworkView • Effectively the new App Object class • Enables OS to initialize app, deliver core OS resources • You will implement 5 methods

  19. IFrameworkView methods Initialize Load Run Uninitialize SetWindow • Called on application launch • Register application events here • OS assigns CoreWindowto 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

  20. Required IFrameworkView methods • refclassMyFrameworkView : publicIFrameworkView • { • public:  • // IFrameworkView Methods • virtualvoid Initialize(CoreApplicationView^ applicationView); • virtualvoid SetWindow(CoreWindow^ window); • virtualvoid Load(String^ entryPoint); • virtualvoid Run(); • virtualvoid Uninitialize(); • // ...

  21. Registering events

  22. Where to register events • Initialize method • Application-wide events • Example: Suspend and resume • SetWindow method • App window-specific events • Example: Window-size-changed and input events

  23. There are many events • Suspend • Resume • PointerPressed • PointerMoved • KeyDown • KeyUp • SizeChanged • …

  24. Registering the SizeChanged event • m_window->SizeChanged += refnew • TypedEventHandler<CoreWindow^,WindowSizeChangedEventArgs^> ( • this, • &Framework::OnWindowSizeChanged • );

  25. The SizeChanged event • voidFramework::OnWindowSizeChanged(CoreWindow^ sender, WindowSizeChangedEventArgs^ args) • { usingWindows::UI::ViewManagement; if(ApplicationView::Value == ApplicationViewState::Snapped) { /* snapped specific code */ } /* respond to new window size … */ • } • // See Snap sample on MSDN

  26. Process Lifetime Management (PLM) events • CoreApplication::Suspending += • refnewEventHandler<SuspendingEventArgs^>(this, &Framework::OnSuspending); • CoreApplication::Resuming += • refnewEventHandler<Platform::Object^>(this, &Framework::OnResuming); • // ... • voidFramework::OnSuspending(Platform::Object^ sender, SuspendingEventArgs^ args) { • // Save app state here • } • voidFramework::OnResuming(Platform::Object^ sender, Platform::Object^ args) { • // Restore app state here • }

  27. Get going quickly

  28. Getting started • Use the Visual Studio 2012 templates for a quick start • Direct3D template for pure C++ and DirectX • Direct2D template for added XAML support • Reference the samples • Need a feature? Copy and paste from the corresponding sample! • Use the documentation at dev.windows.com

  29. Templates • Demo

  30. Windows Store app features

  31. Live tiles • usingnamespace Windows::UI::Notifications; • usingnamespace Windows::Data::Xml::Dom; • autotileXml = refnewXmlDocument(); • tileXml->LoadXml("<tile>"…"</tile>"); • TileUpdateManager::CreateTileUpdaterForApplication()->Update( • refnewTileNotification(tileXml) • ); • See App tiles and badges sample on MSDN

  32. Using templates for binding • tileXmlString = "<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

  33. Toast • usingnamespace Windows::UI::Notifications; • usingnamespace Windows::Data::Xml::Dom; • auto toastXml = refnewXmlDocument(); • auto toastXmlString = "<toast>”…”</toast>"; • toastXml->LoadXml(toastXmlString); • auto toast = refnewToastNotification(toastXml); • ToastNotificationManager::CreateToastNotifier()->Show(toast);

  34. Scheduled toast • toastXml->LoadXml(toastXmlString); • auto toast = refnewToastNotification(toastXml); • auto cal = refnew Windows::Globalization::Calendar(); • cal->SetToNow(); • cal->AddSeconds(7); • ToastNotificationManager::CreateToastNotifier()->AddToSchedule(refnewScheduledToastNotification(toastXml,cal->GetDateTime())); • // Remember to declare toast in your app manifest!

  35. App bar and edge gestures • In C++, EdgeGesture->Completedevent fires in three cases • Swipe up from bottom (or down from top) of touch screen • Windows logo key+Z on keyboard • Right mouse button click • Draw app bar using Direct2D

  36. The edge gesture event • usingnamespaceWindows::UI::Input; • EdgeGesture::GetForCurrentView()->Completed += refnew • TypedEventHandler<EdgeGesture^, EdgeGestureEventArgs^>( • this, &InputController::OnCompleted • ); • void InputController::OnCompleted(EdgeGesture^,EdgeGestureEventArgs^){ • // Check device orientation and draw app bar… • }

  37. Charms (Share) • usingnamespace Windows::ApplicationModel::DataTransfer; • DataTransferManager::GetForCurrentView()->DataRequested += refnew • 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!“); /* … */ • });

  38. Charms (Settings) • usingnamespace Windows::UI::ApplicationSettings; • SettingsPane::GetForCurrentView()->CommandsRequested += • refnewTypedEventHandler<SettingsPane^,SettingsPaneCommandsRequestedEventArgs^>( • &MyApp::OnCommandsRequested • );

  39. More charms (Settings) • using namespace Windows::UI::ApplicationSettings; • void MyApp::OnCommandsRequested(SettingsPane^ settingsPane, • SettingsPaneCommandsRequestedEventArgs^ args) • { • UICommandInvokedHandler^ handler = • refnewUICommandInvokedHandler(this, &Scenario::onAudio); • SettingsCommand^ audioCommand = • refnewSettingsCommand("audioPage", "audio", handler); • // Make it visible • args->Request->ApplicationCommands->Append(audioCommand); • // Add additional settings ... • }

  40. More charms (Settings) • voidScenario::OnAudio(IUICommand^ command) { • // Draw audio settings using Direct2D ... • } • Source code from App Settings Sample on MSDN

  41. Saving data • Windows::Storage::ApplicationDatafor 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

  42. Saving to local hard drive • auto settingsValues = • Windows::Storage::ApplicationData::Current->LocalSettings->Values; • float m_time = • safe_cast<IPropertyValue^>( • settingsValues->Lookup(“time") • )->GetSingle(); • settingsValues->Insert(“time", • PropertyValue::CreateSingle(m_time) • );

  43. Saving to the cloud • auto 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

  44. Making money

  45. Handling trials • Select a time period for your trial • Let the Windows Store handle the rest

  46. Using the Windows Store API • Store API is in Windows::ApplicationModel::Store • Use CurrentApp::LicenseInformationto 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

  47. Marble Maze • Demo

  48. Time to code • Get 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 templates • Live tiles • Toast • AppBar/EdgeGesture • Saving data locally and to the cloud • Features that can help you make money (for example, trials and in-app purchases)

  49. Resources • Previous talks • “Combining XAML and DirectX in Windows Store apps” by Jesse Bishop • “Monetization Strategies for Windows 8 Games” by ShaiHinitz • Other resources at //Build • Check out the graphics talks (Build 3-112 and 3-113) • Build 3-101 for more info about live tiles and toast • Build 3-126 for more info about app state • Build 3-121 for more info about how to make money Please submit session evals on the Build Windows 8 App or at http://aka.ms/BuildSessions

  50. Resources • 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 Please submit session evals by using the Build Windows 8 app or at http://aka.ms/BuildSessions

More Related