当前位置:网站首页>Directx-- draw hexagon (entity type)
Directx-- draw hexagon (entity type)
2022-07-21 22:55:00 【Freak587】
Preparation stage :
The process is as follows :
Equipment creation preparation stage :
ComPtr<ID3DBlob> blob;
// Create vertex shaders
HR(CreateShaderFromFile(L"HLSL\\VS_Hexagon.cso", L"HLSL\\VS_Hexagon.hlsl", "VS", "vs_5_0", blob.ReleaseAndGetAddressOf()));
m_pDevice->CreateVertexShader(blob->GetBufferPointer(), blob->GetBufferSize(), nullptr, m_pVertexShader.GetAddressOf());
// Create input layout
m_pDevice->CreateInputLayout(VertexPosColor::inputLayout, ARRAYSIZE(VertexPosColor::inputLayout),
blob->GetBufferPointer(), blob->GetBufferSize(), m_pVertexLayout.GetAddressOf());
// Create pixel shaders
CreateShaderFromFile(L"HLSL\\PS_Hexagon.cso", L"HLSL\\PS_Hexagon.hlsl", "PS", "ps_5_0", blob.ReleaseAndGetAddressOf());
m_pDevice->CreatePixelShader(blob->GetBufferPointer(), blob->GetBufferSize(), nullptr, m_pPixelShader.GetAddressOf());
// Describe the vertex description area
D3D11_BUFFER_DESC vbd;
ZeroMemory(&vbd, sizeof(vbd));
vbd.Usage = D3D11_USAGE_IMMUTABLE;
vbd.ByteWidth = sizeof vertices;
vbd.BindFlags = D3D11_BIND_VERTEX_BUFFER;
vbd.CPUAccessFlags = 0;
// Vertex buffer data source
D3D11_SUBRESOURCE_DATA InitData;
ZeroMemory(&InitData, sizeof(InitData));
InitData.pSysMem = vertices;
m_pDevice->CreateBuffer(&vbd, &InitData, m_pVertexBuffer.GetAddressOf());
Bind device context stage :
UINT stride = sizeof(VertexPosColor); // Number of bytes crossed
UINT offset = 0; // Starting offset
// Bind shader
m_pContext->VSSetShader(m_pVertexShader.Get(), nullptr, 0);
m_pContext->PSSetShader(m_pPixelShader.Get(), nullptr, 0);
// Set the element type
m_pContext->IASetPrimitiveTopology(D3D11_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP);
// Set the input layout
m_pContext->IASetInputLayout(m_pVertexLayout.Get());
// Bind vertex buffer
m_pContext->IASetVertexBuffers(0, 1, m_pVertexBuffer.GetAddressOf(), &stride, &offset);
Element type :
DirectX11 There are many element types in , The following pictures are easy to understand what the element type is :
Whether it is the simplest one-dimensional graph or the more complex multi-dimensional graph , It's all a little 、 Line 、 Surface composition , With primitives , We can pass through the dot 、 Line 、 Triangles and polygons form a multivariate image .
Here are some dx11 Element types and meanings that can be called in :
Element type | meaning |
---|---|
D3D11_PRIMITIVE_TOPOLOGY_POINTLIST | Assemble according to a series of points |
D3D11_PRIMITIVE_TOPOLOGY_LINESTRIP | Assemble according to a series of line segments , Every two adjacent vertices ( Or the vertex corresponding to two adjacent indexes of the index array ) Form a line segment |
D3D11_PRIMITIVE_TOPOLOGY_LINELIST | Assemble according to a series of line segments , Every two vertices ( Or the vertex corresponding to every two indexes of the index array ) Form a line segment |
D3D11_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP | Assemble according to a series of triangles , Every three adjacent vertices ( Or the vertex corresponding to the three adjacent indexes of the index array ) Make a triangle |
D3D11_PRIMITIVE_TOPOLOGY_TRIANGLELIST | Assemble according to a series of triangles , Every three vertices ( Or the vertex corresponding to every three indexes of the index array ) Make a triangle |
D3D11_PRIMITIVE_TOPOLOGY_LINELIST_ADJ | Every time 4 A set of vertices , Draw only No 2 Vertices and the 3 A line of vertices ( Or index array every 4 Indexes are grouped , Only draw index modules 4 Remainder is 2 and 3 Connection of ) |
D3D11_PRIMITIVE_TOPOLOGY_LINESTRIP_ADJ | Draw all line segments except the beginning and end ( Or the index array does not draw the index 0 and 1 Connection of , as well as n-2 and n-1 Connection of ) |
D3D11_PRIMITIVE_TOPOLOGY_TRIANGLELIST_ADJ | Every time 6 A set of vertices , Draw only No 1、3、5 A triangle of vertices ( Or index array every 6 Indexes are grouped , Only draw index modules 6 Remainder is 0, 2, 4 The triangle of ) |
D3D11_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP_ADJ | Discard all index modules 2 Is an odd number of vertices or indexes , The rest goes Triangle Strip The draw |
The first way to draw ( By element type TRIANGLESTRIP):
Set the number of drawing vertices :
Set vertex :
Set the element type :
The second way to draw ( By element type TRIANGLELIST):
Set the number of drawing vertices :
Set vertex :
Set the element type :
design sketch :
summary :
When we use TRIANGLESTRIP Element type , We need to 6 Draw a regular hexagon with vertices , While using TRIANGLELIST Element type , You need to draw 12 vertices .
because TRIANGLESTRIP After every three vertices form a triangle , The next triangle can use the first two vertices and then add a vertex to draw another triangle , in other words , We can draw 4 Draw two triangles with two vertices .
and TRIANGLELIST The primitive type needs to create a triangle every three vertices , Even if you draw 4 vertices , You can draw a triangle . Needless to say , because 4 Less than 6, and 2 A triangle needs 6 vertices , Three triangles need 12 vertices ——
remarks :
Vertices must be created clockwise .
In general , Triangle vertices are created clockwise , It's facing the camera . If the triangle vertices are arranged counterclockwise, it means that the current triangle faces the camera . Triangles facing away from the camera will be eliminated , Do not rasterize . This is called backface culling
边栏推荐
- D3D函数说明
- Wechat team sharing: how does the wechat background do not crash under massive concurrent requests
- STL初步了解
- 437. Path sum III
- Force deduction record: dynamic programming 1 basic topic - 509 Fibonacci number, 70 climbing stairs, 746 climbing stairs with minimum cost, 62 different paths, 63 different paths II, 343 integer spli
- 力扣记录:动态规划5子序列问题(1)——300 最长上升子序列,1143 最长公共子序列,1035 不相交的线,674 最长连续递增序列,718 最长重复子数组,53 最大子序和
- Sharing of live video technology: understand the push-pull streaming architecture and transmission protocols of mainstream live video systems
- 二叉树之伸展树的c#实现
- D - AND and SUM (AtCoder Beginner Contest 238)
- 2022acm summer training weekly report (III)
猜你喜欢
CocosCreator 3.x 环境搭建
[oops framework] supporting game configuration data generation + data object code generator plug-in
IM开发技术分享:浅谈IM系统中离线消息、历史消息的最佳实践
994. Rotten oranges
74. Search two-dimensional matrix
Probability theory - maximum likelihood estimation
Leetcode hash
Cocos Creator 3.2 中实现2D地图3D人物45度角RPG游戏完整效果
FXS与FXO:有什么区别以及它是如何工作的
局域网电话软件系统功能与应用
随机推荐
Watermelon book chapter 2 Notes - Performance Measurement
支持 CocosCreator 3.x 第三方库
D3D函数说明
力扣记录:动态规划5子序列问题(3)回文——647 回文子串,516 最长回文子序列
IM开发技术分享:浅谈IM系统中离线消息、历史消息的最佳实践
完成mysql数据库主从复制集群的搭建教程
不同规模下呼叫中心的系统搭建解决方案
CocosCreator3.x 接入腾讯游戏联机对战引擎笔记
【oops-framework】配套热更新插件
2022acm summer training weekly report (I)
Window常用消息
Directx11--窗口初始化(win32)
Cocos Creator 3.x 绘制扇形网格组件
11th week ACM training report
9th week ACM training report
局域网电话软件系统功能与应用
windows mysql 5.7+ 修改表名大小写敏感属性
Windows MySQL 5.7+ modify the case sensitive attribute of table name
Playable Director (TimeLine) 3D游戏的开场动画制作
什么是IMS(IP多媒体子系统)