Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- window = CoreWindow::GetForCurrentThread( );
- Window::width = window->Bounds.Width;
- Window::height = window->Bounds.Height;
- // Define temporary pointers to a device and a device context
- ComPtr<ID3D11Device> d3dDevice11;
- ComPtr<ID3D11DeviceContext> d3dDeviceContext11;
- // Create the device and device context objects
- D3D11CreateDevice(
- nullptr,
- D3D_DRIVER_TYPE_HARDWARE,
- nullptr,
- 0,
- nullptr,
- 0,
- D3D11_SDK_VERSION,
- &d3dDevice11,
- nullptr,
- &d3dDeviceContext11 );
- // Convert the pointers from the DirectX 11 versions to the DirectX 11.1 versions
- d3dDevice11.As( &d3dDevice );
- d3dDeviceContext11.As( &d3dDeviceContext );
- // obtain the DXGI factory
- ComPtr<IDXGIDevice1> dxgiDevice;
- d3dDevice.As( &dxgiDevice );
- ComPtr<IDXGIAdapter> dxgiAdapter;
- dxgiDevice->GetAdapter( &dxgiAdapter );
- ComPtr<IDXGIFactory2> dxgiFactory;
- dxgiAdapter->GetParent( __uuidof( IDXGIFactory2 ), &dxgiFactory );
- // set up the swap chain description
- DXGI_SWAP_CHAIN_DESC1 scd = { 0 };
- scd.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT; // how the swap chain should be used
- scd.BufferCount = 2; // a front buffer and a back buffer
- scd.Format = DXGI_FORMAT_B8G8R8A8_UNORM; // the most common swap chain format
- scd.SwapEffect = DXGI_SWAP_EFFECT_FLIP_SEQUENTIAL; // the recommended flip mode
- scd.SampleDesc.Count = 1; // disable anti-aliasing
- dxgiFactory->CreateSwapChainForCoreWindow(
- d3dDevice.Get( ), // address of the device
- reinterpret_cast<IUnknown*>( window ), // address of the window
- &scd, // address of the swap chain description
- nullptr, // advanced
- &swapchain ); // address of the new swap chain pointer
- // get a pointer directly to the back buffer
- ComPtr<ID3D11Texture2D> backbuffer;
- swapchain->GetBuffer( 0, __uuidof( ID3D11Texture2D ), &backbuffer );
- // create a render target pointing to the back buffer
- d3dDevice->CreateRenderTargetView( backbuffer.Get( ), nullptr, &rendertarget );
- // set the viewport
- D3D11_VIEWPORT viewport = { 0 };
- viewport.TopLeftX = 0;
- viewport.TopLeftY = 0;
- viewport.Width = Window::width;
- viewport.Height = Window::height;
- viewport.MinDepth = 0; // the closest an object can be on the depth buffer is 0.0
- viewport.MaxDepth = 1; // the farthest an object can be on the depth buffer is 1.0
- d3dDeviceContext->RSSetViewports( 1, &viewport );
- // DIRECT 2D stuff
- D2D1_FACTORY_OPTIONS options;
- ZeroMemory( &options, sizeof( D2D1_FACTORY_OPTIONS ) );
- D2D1CreateFactory(
- D2D1_FACTORY_TYPE_SINGLE_THREADED,
- __uuidof( ID2D1Factory2 ),
- &options,
- &d2dFactory
- );
- ComPtr<IDXGIDevice3> dxgiDevice2;
- HRESULT hr;
- hr = d3dDevice.As( &dxgiDevice2 );
- hr = d2dFactory->CreateDevice( dxgiDevice2.Get(), d2dDevice.GetAddressOf() );
- hr = d2dDevice->CreateDeviceContext(
- D2D1_DEVICE_CONTEXT_OPTIONS_NONE,
- &d2dDeviceContext
- );
Advertisement
Add Comment
Please, Sign In to add comment