developing a windows store app using c and directx n.
Download
Skip this Video
Loading SlideShow in 5 Seconds..
Developing a Windows Store app using C++ and DirectX PowerPoint Presentation
Download Presentation
Developing a Windows Store app using C++ and DirectX

Loading in 2 Seconds...

play fullscreen
1 / 51

Developing a Windows Store app using C++ and DirectX - PowerPoint PPT Presentation


  • 165 Views
  • Uploaded on

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.

loader
I am the owner, or an agent authorized to act on behalf of the owner, of the copyrighted work described.
capcha
Download Presentation

PowerPoint Slideshow about 'Developing a Windows Store app using C++ and DirectX' - pleasance-roche


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.While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.


- - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - -
Presentation Transcript
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

Agenda

  • Fundamentals (DirectX)
  • What is XAML? Why interop?
  • More fundamentals (C++)
  • Registering events
  • Windows Store app features
  • Making money
graphics language of choice
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
directx f undamentals
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
the direct3d device
The Direct3D device
  • D3D11CreateDevice(
  • /* … */
  • &device, // Returns the Direct3D device created.
  • &m_featureLevel, // Returns feature level of the device.
  • &context // Returns the device immediate context.
  • )
shaders
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, … );
the swap chain
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
  • )  
the swap chain1
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
  • )  
in box controls for windows store apps
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

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

To XAML or not to XAML?
xaml interop scenarios
XAML interop scenarios
  • SwapChainBackgroundPanel
    • Example: XAML for UI/HUD, Direct3D for graphics
  • See XAML DirectX 3D shooting game sample on MSDN
xaml i nterop scenarios
XAML interop scenarios
  • SurfaceImageSource
    • Example: Use DirectX inside a XAML element

See XAML SurfaceImageSource DirectX Interop Sample on MSDN

xaml i nterop scenarios1
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”

corewindow and iframeworkview
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
iframeworkview methods
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
required iframeworkview methods
Required IFrameworkView methods
  • refclassMyFrameworkView : publicIFrameworkView
  • {
  • public: 
  • // IFrameworkView Methods
  • virtualvoid Initialize(CoreApplicationView^ applicationView);
  • virtualvoid SetWindow(CoreWindow^ window);
  • virtualvoid Load(String^ entryPoint);
  • virtualvoid Run();
  • virtualvoid Uninitialize();
  • // ...
where to register events
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
there are many events
There are many events
  • Suspend
  • Resume
  • PointerPressed
  • PointerMoved
  • KeyDown
  • KeyUp
  • SizeChanged
registering the sizechanged event
Registering the SizeChanged event
  • m_window->SizeChanged += refnew
  • TypedEventHandler<CoreWindow^,WindowSizeChangedEventArgs^> (
  • this,
  • &Framework::OnWindowSizeChanged
  • );
the sizechanged event
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
process lifetime management plm events
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
  • }
getting started
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
live tiles
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
using templates for binding
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
toast
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);
scheduled toast
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!
app bar and edge gestures
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
the edge gesture event
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…
  • }
charms share
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!“);

/* … */

  • });
charms settings
Charms (Settings)
  • usingnamespace Windows::UI::ApplicationSettings;
  • SettingsPane::GetForCurrentView()->CommandsRequested +=
  • refnewTypedEventHandler<SettingsPane^,SettingsPaneCommandsRequestedEventArgs^>(
  • &MyApp::OnCommandsRequested
  • );
more charms settings
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 ...
  • }
more charms settings1
More charms (Settings)
  • voidScenario::OnAudio(IUICommand^ command) {
  • // Draw audio settings using Direct2D ...
  • }
  • Source code from App Settings Sample on MSDN
saving data
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
saving to local hard drive
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)
  • );
saving to the cloud
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
handling trials
Handling trials
  • Select a time period for your trial
  • Let the Windows Store handle the rest
using the windows store api
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
time to c ode
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)
resources

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

resources1

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