How to Create Your First

Slides:



Advertisements
Similar presentations
Introduction to the Windows Runtime (WinRT) Ben Dewey Tallan, Inc.
Advertisements

Creating Windows Store Apps. 1. Overview of Windows Store applications 2. Worked example 3. Adding controls and event handlers Contents 2.
FireMonkey Deep Dive The Next Generation of Business Application Development.
Windows 8 Introduction Mark Rosenberg Development Instructor New Horizons.
Essentials of Developing Windows Phone Apps Chinthaka Dissanayake Tech Lead Exilesoft.
Platform for building Windows Store Apps Agu Suur Frontend Developer Axinom.
Introducing the UWP.
Windows Core OS Services JavaScript (Chakra) C C++ C# VB Metro style apps Communication & Data Application Model Devices & Printing WinRT APIs Graphics.
Advanced Windows 8 Apps Using JavaScript Jump Start Exam Prep Advanced Windows 8 Apps Using JavaScript Jeremy Foster Microsoft Developer Evangelist.
There has never been a better time to build a game that targets PC, tablets, phone and Xbox!
Creating a Cutting-Edge Game for Windows Tablets Chas. Boyd Windows Graphics

OPTIMIZING AND DEBUGGING GRAPHICS APPLICATIONS WITH AMD'S GPU PERFSTUDIO 2.5 GPG Developer Tools Gordon Selley Peter Lohrmann GDC 2011.
You can use 3D graphics to enhance and differentiate your Metro style app.
Visual Studio 11 for Game Developers Boris Jabes Senior Program Manager Microsoft Corporation.
High Performance in Broad Reach Games Chas. Boyd
Computer for Health Sciences
Windows.Net Programming Series Preview. Course Schedule CourseDate Microsoft.Net Fundamentals 01/13/2014 Microsoft Windows/Web Fundamentals 01/20/2014.
2 A First Look at Windows Presentation Foundation Everywhere ("WPF/E") Joe Stegman Lead Program Manager Microsoft Corporation.
Platform for Metro Style Apps Michael Platt Senior Director Microsoft Corp.
Building Windows 8 Apps with HTML & JavaScript Jaime Rodriguez Principal
Effective WinRT with C++ Tips and tricks for developing WinRT applications in C++
Angelo Chan Kamran Bilgrami. Agenda ● WinJS - What and Why ● Modern Apps ● WinRT Architecture ● Demos o Controls o Data Bindings o Program LifeCycle Management.
Beautiful Sites and Apps Easy-to-build, Touch-First Interactivity Engaging Page Layouts Better Client/Server Data Transfer Powerful Local Data and Offline.
Windows Reimagine d Windows 8 Data explosion Browser-based apps Natural interaction Ubiquitous connectivity Personal devices in the.
$10B in game software per year worldwide 145M active gamers in US alone Over 50% of all current ‘apps’ are games Windows is now spanning an even broader.
London April 2005 London April 2005 Creating Eyeblaster Ads The Rich Media Platform The Rich Media Platform Eyeblaster.
Developing Cross-Platform Applications with Visual Studio 2015
Windows 8 Hot or Not Piotr Włodek. Agenda MetroCharms Contracts WinRT App Execution Environment Motion Summary.
Jeff From 5 to 8 building Windows 8 Apps with HTML5 and JavaScript.
Developing the Game User Interface (UI) Lesson 5.
App structure options Select feature levels to support D3D_FEATURE_LEVEL featureLevels[] = { D3D_FEATURE_LEVEL_11_1, D3D_FEATURE_LEVEL_11_0,
The Windows Runtime (WinRT) is the shared runtime and API space used by store apps across the Windows platform (phone and client) 5 Common WinRT.
Windows 8 Apps Guy Burstein Technical Evangelist, Microsoft
Windows Core OS Services JavaScript (Chakra) C C++ C# VB Metro style apps Communication & Data Application Model Devices & Printing WinRT APIs Graphics.
Windows Runtime Deep Dive Brendan Forster Senior Developer, ASP.NET/IIS DEV317.
Build advanced touch apps in Windows 8
D3D11CreateDevice( /* … */ &device, // Returns the Direct3D device created. &m_featureLevel, // Returns feature level of the device. &context.
Developing ASP.NET AJAX Controls with Silverlight Barry Gervin Microsoft Regional Director John Bristowe Developer Advisor, Microsoft.
Windows Store apps… lots of choices Windows Store Apps Communication & Data Application Model Devices & Printing WinRT APIs Graphics & Media JavaScript.
Overview Windows Core OS Services JavaScript (Chakra) C C++ C# VB Metro style Apps Communication & Data Application Model Devices & Printing WinRT.
Computer Graphics 3 Lecture 6: Other Hardware-Based Extensions Benjamin Mora 1 University of Wales Swansea Dr. Benjamin Mora.
Windows 8 Ronnie Saurenmann Technical Evangelist Microsoft Switzerland
Building Windows Runtime Components in C++ Harry Pierson Program Manager, Windows Runtime Experience Team Microsoft Corporation.
Metro Style Applications Metro style design and Inspirations.
Eric Strittmatter COSC 480 – Spring 2012 Previewing.
Communication & Data Devices & Printing WinRT APIs DirectX & Media Windows 8 Desktop Apps C C++ Win32 C# VB. NET SL HTML JavaScrip t Internet Explorer.
The Windows 10 App platform: an introduction to the UWP Andy Wigley b:
What is the Windows Runtime? Devices Sensor s Geolocation Portabl e NFC Communications & Data Contracts XML Web SMS Networking Notifications Local.
丁建文 國立高雄應用科大資管系副教授 兼任計網中心軟體發展組組長 跨平台行動應用軟體開發技術 : HTML5 & Mobile JavaScript Framework 暨南大學.
Copyright © 2010 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 1: Introduction to Computers and Programming.
Eric Strittmatter COSC 380 – Spring 2012 Previewing.
What is DirectX? DirectX is built by Microsoft as a collection of API’s (Application Programming Interfaces) for the purpose of multimedia processing.
The Universal Windows Platform
6/2/2018 4:08 AM BRK3327 Ten things you didn't know about building .NET UWP apps in Visual Studio 2017 Daniel Jacobson Program Manager – Visual Studio.
Windows Phone 8.1 New Features
Platform for Metro Style Apps
Build /24/2018 © 2014 Microsoft Corporation. All rights reserved. Microsoft, Windows, and other product names are or may be registered trademarks.
A lap around DirectX game development tools
DotnetConf 11/14/2018 3:27 AM © 2016 Microsoft Corporation. All rights reserved. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE.
Using the Windows Runtime from JavaScript
.NET and .NET Core 7. XAML Pan Wuming 2017.
Metro style apps using XAML: What you need to know
Tooling and Diagnostics
Windows Runtime internals: understanding "Hello World"
Introducing Metro style device apps
Build /23/2019 © 2012 Microsoft Corporation. All rights reserved. Microsoft, Windows, and other product names are or may be registered trademarks.
Platform for Metro style Apps
Leveraging existing code in Metro style apps
Combining XAML and DirectX
Presentation transcript:

How to Create Your First Windows 8 Metro-style Game Chas. Boyd Principal Program Manager Microsoft Corporation

How to Create Your First Windows 8 Metro-style Game Windows 8 metro-style apps are a huge new opportunity for all developers. Learn about the core components of the Windows8 platform specifically provided for metro-style games and how you can assemble them into your ideal game experience. Learn the latest tips and best practices for game graphics, input & animation, sound effects, and asset loading.

Three Presentations Today Step by Step through Game Development How to set up the game How to code it <- You are here How to optimize it

Agenda Quick summary of the platform Step through the process of development from a programmer’s perspective: App Initialization Opening a Window Rendering Graphics Loading and Saving Adding Input Controls Adding Sound Effects Adding an Art Pipeline This talk’s sample code is in C++

Platform Overview

Windows Kernel Services Metro style apps Desktop apps C C++ Win32 C# VB .NET SL HTML JavaScript Internet Explorer View C C++ DX XAML C# VB JavaScript HTML / CSS Model Controller Communication & Data Devices & Printing WinRT APIs Graphics & Media System Services Application Model Kernel Windows Kernel Services

Windows 8 Game Platform Technologies Your Killer Game Graphics Movies & Cut Scenes Game Input Audio Local Services Connected Services Tools Direct3D DirectX Video Pointer Point WASAPI PLM Windows Live Visual Studio Direct2D Media Foundation Sensor API XAudio2 AppData Windows Store Asset Viewers HTML XInput Contracts Xbox LIVE Asset Processors XAML

Windows Runtime All WinRT APIs are native WinRT APIs feel natural in C++, C#/VB, and JavaScript Reuse of portable C++ code just works WinRT APIs provide rich access to devices, OS, and services HTML5/CSS/JavaScript and XAML are great for Metro style apps Providing a rich set of controls Native DirectX is great for Metro style apps

Visual Studio Updated C++ language support File->New Project templates for native DirectX C++ apps DirectX HLSL shader compilation and syntax highlighting Packaging compiled HLSL shaders into the .appx package Support for other asset types in MSBuild and previewer Visualization, processing and packaging of Textures, meshes, shaders, and audio Debugging DirectX API calls

C++/Cx Win32 WRL WinRT CoCreateInstance ComPtr<IObject> Foo^ foo = ref new Foo() QueryInterface foo.As(&bar) N/A AddRef / Release std::vector Platform::Array<>^

Chapter 1/6 App Initialization

App Model – Activation ref class MyApp : public IFrameworkView {         MyApp();       // IFrameworkView Methods     virtual void Initialize(CoreApplicationView^ applicationView);     virtual void SetWindow(CoreWindow^ window);     virtual void Load(String^ entryPoint);     virtual void Run();     virtual void Uninitialize();

Activation – Run void MyApp::Run() { auto dispatcher = CoreWindow::GetForCurrentThread()->Dispatcher; while (!m_windowClosed) dispatcher->ProcessEvents(CoreProcessEventsOption::ProcessAllIfPresent); m_renderer->Update(); m_renderer->Render(); m_renderer->Present(); }

App Activation Timeline Splash Screen Loading Screen Menu Screen Gameplay - OS Loads your App App Loads Loading Screen App is running Load() Run()

Handling Window Events Chapter 2/6 Handling Window Events

ViewStates Widescreen (1366 x 768+) Portrait Snap view (required) Minimum (1024 x 768) Portrait Snap view (required)

ViewStates void MyApp::SetWindow(CoreWindow^ window) {     window->SizeChanged +=      ref new TypedEventHandler<CoreWindow^, WindowSizeChangedEventArgs^>( this, &MyApp::OnWindowSizeChanged);       ApplicationView::GetForCurrentView()->ViewStateChanged +=      ref new TypedEventHandler <ApplicationView^, ApplicationViewStateChangedEventArgs^>( this, &MyApp::OnViewStateChanged); }

Resize Handler void DirectXApp::OnWindowSizeChanged( _In_ CoreWindow^ sender, _In_ WindowSizeChangedEventArgs^ args ) { if (m_window->Bounds.Width != m_windowBounds.Width || m_window->Bounds.Height != m_windowBounds.Height) m_d2dContext->SetTarget(nullptr); m_d2dTargetBitmap = nullptr; m_renderTargetView = nullptr; m_depthStencilView = nullptr; CreateWindowSizeDependentResources(); }

Window Activation – Focus Changed void MyApp::OnWindowActivationChanged( CoreWindow^ sender, WindowActivatedEventArgs^ args) { auto state = args->WindowActivationState; if(state == CoreWindowActivationState::Deactivated) OutputDebugString("Focus Lost"); if(state == CoreWindowActivationState::CodeActivated || state == CoreWindowActivationState::PointerActivated) OutputDebugString("Focus Regained"); }

Rotation Preferences { DisplayOrientations::None; // Enable rotation by OS/Accelerometer DisplayOrientations::Landscape; // Lock rotation by OS/Accelerometer DisplayOrientations::LandscapeFlipped; // and enable this orientation DisplayOrientations::Portrait; DisplayOrientations::PortraitFlipped; } using namespace Windows::Graphics::Display; DisplayProperties::AutoRotationPreferences = DisplayOrientations::Landscape | DisplayOrientations::LandscapeFlipped;

Chapter 3/6 Rendering Graphics

3D Graphics via Direct3D 11 3D Graphics uses the same API as on Desktop/Classic WinRT API set includes only the latest DirectX 11 syntax DirectX 11 API supports multiple hardware generations via FeatureLevels: Feature_Level_9, Feature_Level_10, Feature_Level_11 Direct3D 11 updated for Windows 8

Creating a swap chain Windows::UI::Core::CoreWindow^ coreWindow; // app’s core window Microsoft::WRL::ComPtr<ID3D11Device1> d3dDevice; // renderer Microsoft::WRL::ComPtr<IDXGISwapChain1> dxgiSwapChain; // front/back buffers of RT // Obtain the final swap chain for this window from the DXGI factory. dxgiFactory->CreateSwapChainForImmersiveWindow( d3dDevice.Get(), // the Direct3D device that will render to it DX::GetIUnknown(coreWindow), // IUnknown interface on our core window &swapChainDesc, // double or triple buffered, stereo, etc. nullptr, // allow on all displays &dxgiSwapChain // the resulting swap chain object );

void myApp::Render() { m_d3dContext->OMSetRenderTargets( // rebind every frame! 1, m_renderTargetView.GetAddressOf(), m_depthStencilView.Get() ); if (!m_loadingComplete) // only draw the cube once it's loaded return; // (this is async) 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()); m_d3dContext->VSSetConstantBuffers( 0, 1, m_constantBuffer.GetAddressOf() ); m_d3dContext->VSSetShader( m_vertexShader.Get(), nullptr, 0 ); m_d3dContext->PSSetShader( m_pixelShader.Get(), m_d3dContext->DrawIndexed( m_indexCount, 0, 0 ); }

Chapter 4/7 Loading and Saving

Process Lifetime Management Suspend/Resume App gets 5 seconds to work after suspend message Apps are not notified before they are terminated Running App suspending Suspended App Terminated App User Launches App Low Memory resuming Apps are notified when they have been resumed

Concurrency Tasks using namespace Concurrency; float f = 1.0f; thread float f = 1.0f; task<int>([=]() { return foo(f); }).then([](int x) bar(x); }).then(baz); // task defined with capturing lambda // continuation lambda argument is return value of previous // continuation using existing function baz()

State Persistence – Saving void MyApp::OnSuspending(Object^ sender, SuspendingEventArgs^ args) {     SuspendingDeferral^ deferral = args->SuspendingOperation->GetDeferral();       task<void>([=]()     {         auto localState = ApplicationData::Current->LocalSettings->Values;         auto roamingState = ApplicationData::Current->RoamingSettings->Values;         localState->Insert( "GameTime", PropertyValue::CreateSingle(m_gameTime));         roamingState->Insert( "MaxLevel", PropertyValue::CreateUInt32(m_maxLevelUnlocked));     }).then([=]()         deferral->Complete();     }); }

State Persistence – Loading void MyApp::Load(String^ entryPoint) {     LoadMyGameStateAsync().then([=]()     {         auto localState = ApplicationData::Current->LocalSettings->Values;         auto roamingState = ApplicationData::Current->RoamingSettings->Values;         m_gameTime = safe_cast<IPropertyValue^> (localState->Lookup("GameTime"))->GetSingle();         m_maxLevelUnlocked = safe_cast<IPropertyValue^> (roamingState->Lookup("MaxLevel"))->GetUInt32();     }).then([=]()         m_loadingComplete = true;     }); }

File Input / Output task<byte*> LoadSkyAsync() { auto folder = Package::Current->InstalledLocation; return task<StorageFile^>( folder->GetFileAsync("sky.dds")).then([](StorageFile^ file){ return FileIO::ReadBufferAsync(file); }).then([](IBuffer^ buffer){ auto fileData = ref new Array<byte>(buffer->Length); DataReader::FromBuffer(buffer)->ReadBytes(fileData); return fileData->Data; }); } ... LoadSkyAsync().then([=](byte* skyTextureData) CreateTexture(skyTextureData); m_loadingComplete = true;

Chapter 5/7 Adding Input

Mouse and Touch Input win->PointerPressed += ref new TypedEventHandler<CoreWindow^,PointerEventArgs^> (this, &LonLatController::OnPointerPressed); void LonLatController::OnPointerPressed( _In_ CoreWindow^ sender, _In_ PointerEventArgs^ args ) { float2 position = float2( // position of contact args->CurrentPoint->Position.X, args->CurrentPoint->Position.Y ); m_lonLatLastPoint = position; // save for use in controller m_lonLatPointerID = args->CurrentPoint->PointerId; }

Polling for Keyboard Input // Arrow keys or WASD example auto upKeyState = window->GetKeyAsyncState(VirtualKey::Up); auto wKeyState = window->GetAsyncKeyState(VirtualKey::W); if (upKeyState & CoreVirtualKeyStates::Down || wKeyState & CoreVirtualKeyStates::Down) { m_playerPosition.y += 1.0f; }

Sensor fusion inputs and outputs 3D Accelerometer Pass-Through Accelerometer 3D Gyro Gyro 3D Magnetometer Sensor Fusion Compass Inclinometer Device Orientation

Reading orientation sensor data using Windows::Devices::Sensors; // Get current reading from sensor OrientationSensorReading^ orientationReading = m_orientationsensor->GetCurrentReading(); SensorQuaternion^ quat = orientationReading->Quaternion; // Transform quaternion from device orientation space to world space // Orientation space is Z-up, right-handed coordinate system // World space is Y-up, left-handed coordinate system XMVECTOR orientationQuat = XMVectorSet(-quat->X, quat->Z, quat->Y, -quat->W); // Create a rotation matrix from the quaternion // This matrix can be used to rotate an object inside the scene to match // the rotation of the device XMMATRIX rotXMMatrix = XMMatrixRotationQuaternion(orientationQuat);

Game Controller Input Windows 8 supports Xbox360 -compatible controllers Check out new ControllerSketch sample Demonstrates game controller usage from JavaScript app

Game Controller Button Input if ( m_xinputState.Gamepad.wButtons & XINPUT_GAMEPAD_A ) { m_aButtonWasPressed = true; } else if ( m_aButtonWasPressed ) m_aButtonWasPressed = false; // Trigger once, only on button release TriggerSoundEffect();

Game Controller D-pad Input SHORT thumbLeftX = inputState.Gamepad.sThumbLX; if (abs(thumbLeftX) < XINPUT_GAMEPAD_LEFT_THUMB_DEADZONE) thumbLeftX = 0; SHORT thumbLeftY = inputState.Gamepad.sThumbLY; if (abs(thumbLeftY) < XINPUT_GAMEPAD_LEFT_THUMB_DEADZONE) thumbLeftY = 0; combinedTiltX += (float)thumbLeftX / 32768.0f; combinedTiltY += (float)thumbLeftY / 32768.0f;

Chapter 6/7 Adding Sound Effects

Sound Effects // Create the XAudio2 engine and mastering voice on the default audio device XAudio2Create(&m_audioEngine); m_audioEngine->CreateMasteringVoice(&m_masteringVoice); // Load all audio data for the sound effect into a single in-memory buffer MediaLoader soundFile(ref new Platform::String(SOUND_FILE)); m_soundEffectBuffer = soundFile.ReadAll(); // Create a single source voice for a sound effect m_audioEngine->CreateSourceVoice(&m_sourceVoice, &(soundFile.GetOutputWaveFormatEx())); // Trigger sound effect: queue in-memory buffer for playback and start the voice XAUDIO2_BUFFER buf = {0}; buf.AudioBytes = m_soundEffectBuffer.size(); buf.pAudioData = &m_soundEffectBuffer[0]; buf.Flags = XAUDIO2_END_OF_STREAM; m_sourceVoice->SubmitSourceBuffer(&buf); m_sourceVoice->Start();

Creating an Asset Pipeline Chapter 7/7 Creating an Asset Pipeline

Package Author-time Asset Build Step Packager Run-time Asset shader.hlsl fxc shader.cso Package texture.bmp dxtex texture.dds myApp .appx mesh.obj obj2vbo mesh.vbo music.wav myTool music.wma

Package Bindable Run-time Loader Component API object Asset Installer App Bindable API object Run-time Asset Loader Component Installer shader.cso D3D Shader Package texture.dds myApp .appx Texture Loader Texture mesh.vbo Mesh Loader VertexBuffer music.wma myTool Stream

Pro Dev Hints Find commands in the IDE via the search textport Set up a multi-monitor dev PC with a touch monitor as the primary To work with the samples, set a breakpoint inside the DX::ThrowIfFailed() macro in DirectSample.h line 18

Time to Act Biggest opportunity. Ever. Windows 8 Consumer Preview is now available. Check out the store. Go build great games. http://dev.windows.com

Q & A

4/20/2017 10:57 AM © 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. © 2010 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.