DirectX11 viewport

  • Tags : directx11
  • time :
Viewport
  1. What is a viewport? What is its purpose ?

    For example, in some racing games, if players want to play a multiplayer game on the same machine, we need to split the screen to display the screen of each player (as shown in the figure below), so that each split screen is a viewport. In single player or non multi screen games, it is usually the entire screen. In this case, we only need to simply set the width and height of the viewport to the width and height of the D3D swap chain


    .

  2. How to create a viewport ?

    Viewports fill D3D11 by creating_ Create the VIEWPORT structure. The structure has width, height, minimum depth (near cutting plane), maximum depth (far cutting plane), and upper left corner coordinates. The near clipping plane will eliminate objects that need to be rendered in front of it, while the far clipping plane is used to eliminate any objects behind it. This created the famous visual object. Visual volume is an important concept in 3D graphics, where depth is widely used.

  3. How to bind a viewport to the device environment ?

    Set the number of viewport objects and array of viewport objects during the rasterization phase through RSSetViewports in the device environment.

The following code shows how to create and set up a full screen viewport:

     D3D11_VIEWPORT viewport; 
viewport.Width = static_cast<float>(width); 
viewport.Height = static_cast<float>(height); 
viewport.MinDepth = 0.0f; 
viewport.MaxDepth = 1.0f; 
viewport.TopLeftX = 0.0f; 
viewport.TopLeftY = 0.0f; 
d3dContext_->RSSetViewports( 1, &viewport );