[英]Pretransformed textured polygons
I'm only starting with 3D so I have a question about drawing pretransformed stuff onto the screen. 我只是从3D开始,所以我对在屏幕上绘制预先转换的内容有疑问。
I was able to figure out how to draw colored polygons in pretransformed form by using some tutorials, but I just can't understand how to texture them... Is that even possible? 通过使用一些教程,我能够弄清楚如何以预变换的形式绘制彩色多边形,但我只是不明白如何对它们进行纹理处理……甚至可能吗? If so how? 如果可以,怎么办?
What I have now: 我现在所拥有的:
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;
}
and 和
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);
}
Instead of VertexPositionColor
, use VertexPositionColorTexture
for your vertices, and set the TextureCoordinate
member to a value between 0 and 1 on each axis. 代替VertexPositionColor
,将VertexPositionColorTexture
用作顶点,并将每个轴上的TextureCoordinate
成员设置为0到1之间的值。
When drawing, set GraphicsDevice.Texture[0]
to the texture you want to use. 绘制时,将GraphicsDevice.Texture[0]
设置为要使用的纹理。
Ensure that your pixel shader does something like this: 确保您的像素着色器执行以下操作:
// in the header:
sampler myTexture : register(s0);
// in your shader function:
float4 outputColor = input.Color * tex2D(myTexture, input.TexCoord);
If you are using BasicEffect
, the equivalent is to use VertexPositionColorTexture
, set the BasicEffect.Texture
to your texture, and set BasicEffect.TextureEnabled = true
. 如果使用的是BasicEffect
,则等效于使用VertexPositionColorTexture
,将BasicEffect.Texture
设置为您的纹理,然后将BasicEffect.TextureEnabled = true
设置。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.