2012-09-12 135 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