Create overlays with Direct2D

[ This article is for Windows 8.x and Windows Phone 8.x developers writing Windows Runtime apps. If you’re developing for Windows 10, see the latest documentation ]

The WDC DirectX game learning template has an OverlayManager class that manages and displays a set of Direct2D overlays, which are drawn over the Direct3D content. You can implement the abstract base class Overlay in your own overlays and add them to the manager.

OverlayManager class

The OverlayManager class holds a std::vector of Overlay class objects. It forwards update, render, and resource method calls to each of these objects.

The following line adds overlay class instances to the manager:

    // This code adds the overlays to the overlay manager.
    std::vector<std::shared_ptr<Overlay>> overlays;

Overlay class

The Overlay class is an abstract class for Direct2D overlays. The OverlayManager class calls these methods on each overlay class in the vector:

  • CreateDeviceDependentResources()
  • ReleaseDeviceDependentResources()
  • Update(DX::StepTimer const& timer)
  • Render()

Here's the definition of the Overlay abstract class:

    // Renders an overlay to the screen.
    // Abstract class.
    class Overlay
        Overlay(const std::shared_ptr<DX::DeviceResources>& deviceResources) { m_deviceResources = deviceResources; };
        virtual void CreateDeviceDependentResources() PURE;
        virtual void ReleaseDeviceDependentResources() PURE;
        virtual void Update(DX::StepTimer const& timer) PURE;
        virtual void Render() PURE;

        // Cached pointer to device resources.
        std::shared_ptr<DX::DeviceResources> m_deviceResources;

Use the WDC DirectX game learning template