User Tools

Site Tools


tutorial_202_20-_20rendering_20a_20triangle

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

tutorial_202_20-_20rendering_20a_20triangle [2018/03/31 13:19]
127.0.0.1 external edit
tutorial_202_20-_20rendering_20a_20triangle [2018/04/13 22:29]
richardrussell Added syntax highlighting
Line 7: Line 7:
 \\  The source files, libraries etc. may be downloaded from [[http://​www.rtr.myzen.co.uk/​D3D11tutorial.zip|here]].\\ \\  \\  The source files, libraries etc. may be downloaded from [[http://​www.rtr.myzen.co.uk/​D3D11tutorial.zip|here]].\\ \\ 
 ===== Input Layout ===== ===== Input Layout =====
-\\  The GPU must know about the vertex layout in order to extract correct attributes from the buffer. To accomplish this requires the use of an input layout:\\ \\ +\\  The GPU must know about the vertex layout in order to extract correct attributes from the buffer. To accomplish this requires the use of an input layout: 
 + 
 +<code bb4w> ​
         REM Define the input layout:         REM Define the input layout:
         DIM layout{(0)} = D3D11_INPUT_ELEMENT_DESC{}         DIM layout{(0)} = D3D11_INPUT_ELEMENT_DESC{}
Line 25: Line 27:
         REM Set the input layout:         REM Set the input layout:
         SYS ID3D11DeviceContext.IASetInputLayout%,​ pImmediateContext%,​ pVertexLayout%         SYS ID3D11DeviceContext.IASetInputLayout%,​ pImmediateContext%,​ pVertexLayout%
-\\ +</​code>​ 
 ===== Vertex Layout ===== ===== Vertex Layout =====
-\\  In this tutorial, we are only working with the position of the vertices. Therefore, we define our vertex structure with a single field of the type XMFLOAT3. This type is a vector of three floating-points components, which is typically the data type used for position in 3D:\\ \\ +\\  In this tutorial, we are only working with the position of the vertices. Therefore, we define our vertex structure with a single field of the type XMFLOAT3. This type is a vector of three floating-points components, which is typically the data type used for position in 3D: 
 + 
 +<code bb4w>
         DIM SimpleVertex{} = XMFLOAT3{}         DIM SimpleVertex{} = XMFLOAT3{}
-\\ +</​code>​ 
 ===== Creating Vertex Buffer ===== ===== Creating Vertex Buffer =====
-\\  One thing that we will need to do during initialization is to create the vertex buffer that holds the vertex data. The coordinates in the vertices array are chosen so that we see a triangle in the middle of our application window when rendered with our shaders:\\ \\ +\\  One thing that we will need to do during initialization is to create the vertex buffer that holds the vertex data. The coordinates in the vertices array are chosen so that we see a triangle in the middle of our application window when rendered with our shaders: 
 + 
 +<code bb4w>
         REM Create vertex buffer:         REM Create vertex buffer:
         DIM vertices{(2)} = SimpleVertex{}         DIM vertices{(2)} = SimpleVertex{}
Line 62: Line 70:
         SYS ID3D11DeviceContext.IASetVertexBuffers%,​ pImmediateContext%,​ 0, 1, \         SYS ID3D11DeviceContext.IASetVertexBuffers%,​ pImmediateContext%,​ 0, 1, \
         \                                   ​^pVertexBuffer%,​ ^stride%, ^offset%         \                                   ​^pVertexBuffer%,​ ^stride%, ^offset%
-\\ +</​code>​ 
 ===== Primitive Topology ===== ===== Primitive Topology =====
-\\  Primitive topology refers to how the GPU obtains the three vertices it requires to render a triangle. What if we want to render two triangles? One way is to send 6 vertices to the GPU. The first three vertices define the first triangle and the second three vertices define the second triangle. This topology is called a triangle list:\\ \\ +\\  Primitive topology refers to how the GPU obtains the three vertices it requires to render a triangle. What if we want to render two triangles? One way is to send 6 vertices to the GPU. The first three vertices define the first triangle and the second three vertices define the second triangle. This topology is called a triangle list: 
 + 
 +<code bb4w>
         REM Set primitive topology:         REM Set primitive topology:
         SYS ID3D11DeviceContext.IASetPrimitiveTopology%,​ pImmediateContext%,​ D3D11_PRIMITIVE_TOPOLOGY_TRIANGLELIST         SYS ID3D11DeviceContext.IASetPrimitiveTopology%,​ pImmediateContext%,​ D3D11_PRIMITIVE_TOPOLOGY_TRIANGLELIST
-\\ +</​code>​ 
 ===== Rendering the Triangle ===== ===== Rendering the Triangle =====
-\\  The final item missing is the code that does the actual rendering of the triangle. We have created two shaders to for rendering, the vertex shader and pixel shader. The vertex shader is responsible for transforming the individual vertices of the triangles to their correct locations and the pixel shader is responsible for calculating the final output colour for each pixel of the triangle. This is covered in more detail in the next tutorial:\\ \\ +\\  The final item missing is the code that does the actual rendering of the triangle. We have created two shaders to for rendering, the vertex shader and pixel shader. The vertex shader is responsible for transforming the individual vertices of the triangles to their correct locations and the pixel shader is responsible for calculating the final output colour for each pixel of the triangle. This is covered in more detail in the next tutorial: 
 + 
 +<code bb4w>
         REM Render a triangle:         REM Render a triangle:
         SYS ID3D11DeviceContext.VSSetShader%,​ pImmediateContext%,​ pVertexShader%,​ NULL, 0         SYS ID3D11DeviceContext.VSSetShader%,​ pImmediateContext%,​ pVertexShader%,​ NULL, 0
         SYS ID3D11DeviceContext.PSSetShader%,​ pImmediateContext%,​ pPixelShader%,​ NULL, 0         SYS ID3D11DeviceContext.PSSetShader%,​ pImmediateContext%,​ pPixelShader%,​ NULL, 0
         SYS ID3D11DeviceContext.Draw%,​ pImmediateContext%,​ 3, 0         SYS ID3D11DeviceContext.Draw%,​ pImmediateContext%,​ 3, 0
 +</​code>​
tutorial_202_20-_20rendering_20a_20triangle.txt · Last modified: 2018/04/13 22:29 by richardrussell