Example #1
0
GameWindow::GameWindow(GameWindow & gameWindow)
{
    GameWindow(gameWindow.getWidth(),gameWindow.getHeight(),gameWindow.getName());
}
Example #2
0
   bool D3D11Device::create(GameWindow& window)
   {
      window.initDevice(*this);

      ASSERT_PTR(m_d3dDevice);
      ASSERT_PTR(m_d3dContext);
      ASSERT_PTR(m_swapChain);

      // create and set rasterizer
      D3D11_RASTERIZER_DESC desc;
      ZeroMemory(&desc, sizeof(desc));
      desc.FillMode = D3D11_FILL_SOLID;
      desc.CullMode = D3D11_CULL_NONE;
      desc.DepthClipEnable = FALSE;

      ID3D11RasterizerState* prasterizerstate;
      m_d3dDevice->CreateRasterizerState(&desc, &prasterizerstate);
      m_d3dContext->RSSetState(prasterizerstate);

      if ( !Device::create(window) )
      {
         return false;
      }

      // Initialize Direct2D resources.
      D2D1_FACTORY_OPTIONS options;
      ZeroMemory(&options, sizeof(D2D1_FACTORY_OPTIONS));

#if defined(_DEBUG)
      // If the project is in a debug build, enable Direct2D debugging via SDK Layers.
      options.debugLevel = D2D1_DEBUG_LEVEL_INFORMATION;
#endif

      // Initialize the Direct2D Factory.
      HRESULT hr = D2D1CreateFactory(D2D1_FACTORY_TYPE_SINGLE_THREADED, __uuidof(ID2D1Factory3), &options, reinterpret_cast<void**>(&m_d2dFactory));
      if ( FAILED(hr) )
      {
         return false;
      }

      // Create the Direct2D device object and a corresponding context.
      IDXGIDevice* dxgiDevice;
      m_d3dDevice->QueryInterface<IDXGIDevice>(&dxgiDevice);
      hr = m_d2dFactory->CreateDevice(dxgiDevice, &m_d2dDevice);
      if ( FAILED(hr) )
      {
         return false;
      }

      hr = m_d2dDevice->CreateDeviceContext(D2D1_DEVICE_CONTEXT_OPTIONS_NONE, &m_d2dContext);
      if ( FAILED(hr) )
      {
         return false;
      }

      // Initialize the DirectWrite Factory.
      hr = DWriteCreateFactory(DWRITE_FACTORY_TYPE_SHARED, __uuidof(IDWriteFactory3), reinterpret_cast<IUnknown**>(&m_dwriteFactory));
      if ( FAILED(hr) )
      {
         return false;
      }

      mpFontCollection = new D3DFontCollection();
      if ( !mpFontCollection->initialize(m_dwriteFactory) )
      {
         return false;
      }      
      
      return createWindowSizeDependendResources(window.getWidth(), window.getHeight());
   }