gpt4 book ai didi

c++ - DirectX11 纹理坐标和顶点

转载 作者:行者123 更新时间:2023-11-28 01:47:46 33 4
gpt4 key购买 nike

我是 StackOverflow 的新手。

我正在从 Beginning Directx11 一书中学习 DirectX11,我是一个完全的初学者,但我确实了解 C++。我遇到过纹理坐标及其使用方式,但我不明白用于指定顶点的代码片段。下面是代码:

// the structure used to store the vertices
struct VertexPos
{
XMFLOAT3 pos;
XMFLOAT2 tex0;
};

// some code before reaching this point
...
VertexPos vertices[] =
{
{ XMFLOAT3( 1.0f, 1.0f, 1.0f ), XMFLOAT2( 1.0f, 1.0f ) },
{ XMFLOAT3( 1.0f, -1.0f, 1.0f ), XMFLOAT2( 1.0f, 0.0f ) },
{ XMFLOAT3( -1.0f, -1.0f, 1.0f ), XMFLOAT2( 0.0f, 0.0f ) },

{ XMFLOAT3( -1.0f, -1.0f, 1.0f ), XMFLOAT2( 0.0f, 0.0f ) },
{ XMFLOAT3( -1.0f, 1.0f, 1.0f ), XMFLOAT2( 0.0f, 1.0f ) },
{ XMFLOAT3( 1.0f, 1.0f, 1.0f ), XMFLOAT2( 1.0f, 1.0f ) },
};
...

// shader file
Texture2D colorMap_ : register( t0 );
SamplerState colorSampler_ : register( s0 );


struct VS_Input
{
float4 pos : POSITION;
float2 tex0 : TEXCOORD0;
};

struct PS_Input
{
float4 pos : SV_POSITION;
float2 tex0 : TEXCOORD0;
};


PS_Input VS_Main( VS_Input vertex )
{
PS_Input vsOut = ( PS_Input )0;
vsOut.pos = vertex.pos;
vsOut.tex0 = vertex.tex0;

return vsOut;
}

我不明白为什么要指定 6 个位置。如果是做一个矩形,是不是可以指定4个值,由两个三角形做一个矩形?这会加载纹理图像并显示它,我想知道顶点是如何工作的(如果可能的话,使用指定每个顶点位置的绘图)。

最佳答案

我会说这个例子使用真正的三角形(每个三角形 3 个顶点在一起 6),如果你想要 4 个顶点和两个三角形,你可以使用 Triangle Strip https://en.wikipedia.org/wiki/Triangle_strip

关于c++ - DirectX11 纹理坐标和顶点,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44241288/

33 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com