0

我只是从 3D 开始,所以我有一个关于在屏幕上绘制预转换的东西的问题。

通过使用一些教程,我能够弄清楚如何以预转换形式绘制彩色多边形,但我就是不明白如何对它们进行纹理化......这可能吗?如果有怎么办?

我现在拥有的:

private void TestVertices()
{
 vertices = new VertexPositionColor[3];
 vertices[0].Position = new Vector3(-0.5f, -0.5f, 0f);
 vertices[0].Color = Color.Red;
 vertices[1].Position = new Vector3(0, 0.5f, 0f);
 vertices[1].Color = Color.Green;
 vertices[2].Position = new Vector3(0.5f, -0.5f, 0f);
 vertices[2].Color = Color.Blue;
}

protected override void Draw(GameTime gameTime)
{
     device.Clear(Color.DarkSlateBlue);
     effect.CurrentTechnique = effect.Techniques["Pretransformed"];
     foreach (EffectPass pass in effect.CurrentTechnique.Passes)
     {
         pass.Apply();
         device.DrawUserPrimitives(PrimitiveType.TriangleList, vertices, 0, 1, VertexPositionColor.VertexDeclaration);
     }
     base.Draw(gameTime);
}
4

1 回答 1

1

而不是VertexPositionColorVertexPositionColorTexture用于您的顶点,并将TextureCoordinate成员设置为每个轴上 0 到 1 之间的值。

绘制时,设置GraphicsDevice.Texture[0]为您要使用的纹理。

确保您的像素着色器执行以下操作:

// in the header:
sampler myTexture : register(s0);

// in your shader function:
float4 outputColor = input.Color * tex2D(myTexture, input.TexCoord);

如果您正在使用BasicEffect,则等效于使用VertexPositionColorTexture,将 设置BasicEffect.Texture为您的纹理,然后设置BasicEffect.TextureEnabled = true

于 2012-09-12T08:05:30.170 回答