Direct to Windows Store... The DirectX C++ Game Project Template and Getting Started Guide
- Posted: Dec 04, 2013 at 6:00 AM
- 13,165 Views
In today's Windows Wednesday post, Jim Galasyn highlights a new DirectX Game Project Template and its Getting Started Guide...
Are you creating a game for the Windows Store? If you’re looking for high-performance, you’ll need to code it in C++ and DirectX. These project templates give you a big head start:
Get them here.
The Windows Developer Content DirectX game learning template sample extends the basic DirectX app template with features that help you understand DirectX and C++ as a game development environment. Note that the Getting Started guide has more info on using this template.
The template adds the following:
- InputManager: Consolidated input from touch, mouse, keyboard, and Xbox controllers.
- Virtual analog controls: A basic virtual controller with tracked-touch analog control and digital buttons.
- OverlayManager: Add and manage multiple Direct2D overlays for a Direct3D scene.
- SoundPlayer: Add rudimentary sound effects and play music as background audio. Updates to Direct3D resource management.
Here's how to get started with the WDC DirectX simple game template:
- Download and extract the ZIP file. Then install by double-clicking on the VSIX.
- Verify the installation by launching Microsoft Visual Studio 2013. Go to FILE > New > Project and select "DirectX game" from under Templates > Visual C++ in the New Project dialog.
- Create a project, then build and run the solution. Use BUILD > Build Solution and, after the build completes, DEBUG > Start Debugging. Or press F7 to build, then F5 after the build completes.
- Test input one of several ways: run the project on a touch-capable device, plug in an Xbox controller, or use the arrow keys and left mouse button.
Here's a brief description of the template components.
DirectX device resources
The DeviceResources class wraps DirectX device creation. It creates and configures a device and context, a swap chain, render targets, and so on. It also handles screen rotation and device resets. Study this class to learn how DirectX 11 works and how it manages the device; you’ll need to revise this code if (for example) you add deferred rendering, or change the swap chain format.
To use DeviceResources, initialize it and store it in a shared pointer. Send copies of the pointer to rendering classes; they can call methods to get the device, context, drawing buffers, and so on. These classes will create resources on the GPU - register them to get device reset events from DeviceResources so they can reload if needed. The only extension to this class is support for hardware overlays.
Multiple input sources
InputManager uses Windows APIs to get player input from touch, mouse/keyboard, and Xbox controllers. It processes input from all these sources and returns state for game actions, such as "move" (analog data) and "jump” (digital button state). You can modify PLAYER_ACTION_TYPES in InputManager.h to start adding actions for your game, and revise the code as needed to assign buttons and keys to those actions.
Process user input from InputManager by calling GetPlayersActions during your game loop’s update phase. This tells InputManager to resolve input events and return a set of player actions. Main.cpp shows how to get the data; for processing code, see Main and the virtual controller. You should only call GetPlayersActions once per frame; store the data and use that copy for the duration of the frame.
A sample virtual analog controller is included that recognizes touch input and displays using an overlay. Control areas are defined with touch regions. The regions are defined in Main.cpp and send to both the InputManager and the virtual controller overlay. Examine this code and learn how to add touch regions appropriate to your game.
The OverlayManager class holds a std::vector of Overlay class objects. It forwards update, render, and resource method calls to each of the included overlays. Create your own overlay by inheriting the Overlay base class provided with the template, then adding your overlay to the vector.
Play a sound effect
The SoundPlayer class is minimal. It exists to let you experiment with audio right away, and to demonstrate setting up XAudio2 in a Windows Store game. This class is not a full audio engine.
Main.cpp shows how to set up the SoundPlayer and use it to play media files. Use the PlaySound function by providing a path to the sound effect file; it will play the sound effect, categorizing it for Windows as a game sound effect. Use PlayMusic, again providing a filename, and it will play. Note that music is categorized for Windows as background audio.
Creating a DirectX game for the Windows Store is a challenging undertaking for a new developer. However, it can also be extremely rewarding. In this series of topics, we quickly review the concepts and steps you must take to start on the road to developing a game using DirectX and C++.
Let's get started.
What skills do I need?
To develop a game in DirectX for the Windows Store, you must have a few basic skills. Specifically, you must be able to:
- Read and write modern C++ code (C++11 helps the most), and have familiarity with basic C++ design principles and patterns, such as templates and the factory model. You must also be familiar with common C++ libraries, such as the Standard Template Library, specifically the casting operators, pointer types, and the various data structure template types (such as std::vector).
- Understand basic geometry, trigonometry, and linear algebra. Much of the code you will find in the examples assumes you understand these forms of mathematics and their common rules.
- Possess a passing familiarity with the Windows Runtime and its core APIs, especially those in Windows::UI::Core, Windows::ApplicationModel, and Microsoft::WRL. Especially Microsoft::WRL::ComPtr (smart pointer).
- Understand the foundations of graphics and graphics technology, particularly 3D graphics. While DirectX itself has its own terminology and jargon, it still builds atop a well-established understanding of general 3D graphics principles.
Of course, you must have Windows 8.1 and possess a good understanding of its primary UI features, as well! You'll encounter a lot of documentation that assumes some understanding of:
- Process lifetime (PLM), which includes suspend and resume event handling and behaviors
- Screen orientation, and the support for both portrait and landscape modes
- Windows, also called "app views," which define the region of a screen owned by an app for drawing and update
- View providers, as discussed in How to set up your app to display a view
Get Visual Studio Express 2013 for Windows
As with other Windows Store apps, the journey of a thousand miles starts with Microsoft Visual Studio Express 2013 for Windows. Specifically, the one for Windows Store apps, not Desktop apps. (You can find Microsoft Visual Studio Express 2013 for Windows Desktop here.)
If you haven't done so, download and install it. It has all the tools you need to get started.
Templates are your friends!
When you create a new C++ project (FILE > New > Project... or Ctrl-Shift-N), the dialogue presents you with a number of choices. For purposes of this documentation, choose DirectX app as your template.
Use the Visual Studio 2013 DirectX templates
Take a tour of the DirectX app template and learn more about the basic graphics processing pipeline! These topics review the graphics and graphics device specific code in the template.
Use the WDC DirectX game learning template
Build upon the DirectX app template with the WDC DirectX game learning template. Learn how to play sounds, incorporate multiple control models, and work with Direct2D for overlays and heads-up displays.
You've got your starting point, now let's see your game magic!