Create overlays with Direct2D

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;
    overlays.push_back(m_debugTextRenderer);
    overlays.push_back(m_virtualControllerRenderer);
    m_overlayManager->SetOverlays(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
    {
    public:
        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;

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

Related topics

Use the WDC DirectX game learning template

 

 

Show:
© 2015 Microsoft