[英]DirectX11 texture coordinates and vertices
我是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
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.