Guest User

Untitled

a guest
Jan 15th, 2014
695
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.09 KB | None | 0 0
  1.  
  2.     window = CoreWindow::GetForCurrentThread( );
  3.     Window::width = window->Bounds.Width;
  4.     Window::height = window->Bounds.Height;
  5.    
  6.     // Define temporary pointers to a device and a device context
  7.     ComPtr<ID3D11Device> d3dDevice11;
  8.     ComPtr<ID3D11DeviceContext> d3dDeviceContext11;
  9.  
  10.     // Create the device and device context objects
  11.     D3D11CreateDevice(
  12.         nullptr,
  13.         D3D_DRIVER_TYPE_HARDWARE,
  14.         nullptr,
  15.         0,
  16.         nullptr,
  17.         0,
  18.         D3D11_SDK_VERSION,
  19.         &d3dDevice11,
  20.         nullptr,
  21.         &d3dDeviceContext11 );
  22.  
  23.     // Convert the pointers from the DirectX 11 versions to the DirectX 11.1 versions
  24.     d3dDevice11.As( &d3dDevice );
  25.     d3dDeviceContext11.As( &d3dDeviceContext );
  26.  
  27.     // obtain the DXGI factory
  28.     ComPtr<IDXGIDevice1> dxgiDevice;
  29.     d3dDevice.As( &dxgiDevice );
  30.     ComPtr<IDXGIAdapter> dxgiAdapter;
  31.     dxgiDevice->GetAdapter( &dxgiAdapter );
  32.     ComPtr<IDXGIFactory2> dxgiFactory;
  33.     dxgiAdapter->GetParent( __uuidof( IDXGIFactory2 ), &dxgiFactory );
  34.  
  35.     // set up the swap chain description
  36.     DXGI_SWAP_CHAIN_DESC1 scd = { 0 };
  37.     scd.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT;    // how the swap chain should be used
  38.     scd.BufferCount = 2;                                  // a front buffer and a back buffer
  39.     scd.Format = DXGI_FORMAT_B8G8R8A8_UNORM;              // the most common swap chain format
  40.     scd.SwapEffect = DXGI_SWAP_EFFECT_FLIP_SEQUENTIAL;    // the recommended flip mode
  41.     scd.SampleDesc.Count = 1;                             // disable anti-aliasing
  42.  
  43.     dxgiFactory->CreateSwapChainForCoreWindow(
  44.         d3dDevice.Get( ),                                  // address of the device
  45.         reinterpret_cast<IUnknown*>( window ),        // address of the window
  46.         &scd,                                       // address of the swap chain description
  47.         nullptr,                                    // advanced
  48.         &swapchain );                                // address of the new swap chain pointer
  49.  
  50.     // get a pointer directly to the back buffer
  51.     ComPtr<ID3D11Texture2D> backbuffer;
  52.     swapchain->GetBuffer( 0, __uuidof( ID3D11Texture2D ), &backbuffer );
  53.  
  54.     // create a render target pointing to the back buffer
  55.     d3dDevice->CreateRenderTargetView( backbuffer.Get( ), nullptr, &rendertarget );
  56.  
  57.  
  58.     // set the viewport
  59.     D3D11_VIEWPORT viewport = { 0 };
  60.  
  61.     viewport.TopLeftX = 0;
  62.     viewport.TopLeftY = 0;
  63.     viewport.Width = Window::width;
  64.     viewport.Height = Window::height;
  65.     viewport.MinDepth = 0;    // the closest an object can be on the depth buffer is 0.0
  66.     viewport.MaxDepth = 1;    // the farthest an object can be on the depth buffer is 1.0
  67.  
  68.     d3dDeviceContext->RSSetViewports( 1, &viewport );
  69.  
  70.     // DIRECT 2D stuff
  71.  
  72.         D2D1_FACTORY_OPTIONS options;
  73.         ZeroMemory( &options, sizeof( D2D1_FACTORY_OPTIONS ) );
  74.  
  75.         D2D1CreateFactory(
  76.             D2D1_FACTORY_TYPE_SINGLE_THREADED,
  77.             __uuidof( ID2D1Factory2 ),
  78.             &options,
  79.             &d2dFactory
  80.             );
  81.  
  82.         ComPtr<IDXGIDevice3> dxgiDevice2;
  83.  
  84.         HRESULT hr;
  85.        
  86.         hr = d3dDevice.As( &dxgiDevice2 );
  87.  
  88.         hr = d2dFactory->CreateDevice( dxgiDevice2.Get(), d2dDevice.GetAddressOf() );
  89.  
  90.         hr = d2dDevice->CreateDeviceContext(
  91.             D2D1_DEVICE_CONTEXT_OPTIONS_NONE,
  92.             &d2dDeviceContext
  93.             );
Advertisement
Add Comment
Please, Sign In to add comment