2012-09-12 160 views
0

我只是开始3D,所以我有一个关于绘画pretransformed东西到屏幕上的问题。Pretransformed纹理多边形

我能想出如何利用一些教程绘制在pretransformed形成有色的多边形,但我只是不明白怎么纹理他们...是,可能吗?如果是这样如何?

我现在拥有的一切:

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); 
} 
+0

[标题不需要标签](http://meta.stackexchange.com/questions/19190/should-questions-include-tags-in-their-titles) – Default

回答

1

相反的VertexPositionColor,使用VertexPositionColorTexture为您的顶点,而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

+0

谢谢:)这是正是我一直在试图做! – NewProger