如果你想画你的纹理中,你不能使用spritebatch非矩形的方式。但绘制多边形也不难,你可以使用BasicEffect,所以你不必担心着色器。 开始通过设置你的顶点和索引数组:
BasicEffect basicEffect = new BasicEffect(device);
basicEffect.Texture = myTexture;
basicEffect.TextureEnabled = true;
VertexPositionTexture[] vert = new VertexPositionTexture[4];
vert[0].Position = new Vector3(0, 0, 0);
vert[1].Position = new Vector3(100, 0, 0);
vert[2].Position = new Vector3(0, 100, 0);
vert[3].Position = new Vector3(100, 100, 0);
vert[0].TextureCoordinate = new Vector2(0, 0);
vert[1].TextureCoordinate = new Vector2(1, 0);
vert[2].TextureCoordinate = new Vector2(0, 1);
vert[3].TextureCoordinate = new Vector2(1, 1);
short[] ind = new short[6];
ind[0] = 0;
ind[1] = 2;
ind[2] = 1;
ind[3] = 1;
ind[4] = 2;
ind[5] = 3;
BasicEffect是伟大的一个标准的着色器,你可以用它来绘制纹理,颜色,甚至适用于照明到它。
VertexPositionTexture是如何设置顶点缓冲区。
您可以使用VertexPositionColor,如果你只想要的颜色和VertexPositionColorTexture如果你想两者。 (用颜色着色纹理)。
的IND阵列说,在什么顺序绘制两个三角形组成的四边形。
然后在你的循环渲染你这样做:
foreach (EffectPass effectPass in basicEffect.CurrentTechnique.Passes) {
effectPass.Apply();
device.DrawUserIndexedPrimitives<VertexPositionTexture>(PrimitiveType.TriangleList, vert, 0, vert.Length, ind, 0, ind.Length/3);
}
这就是它! 这是一个非常简短的介绍,我建议你玩这个,如果你陷入困境,这里有大量的教程和信息,谷歌是你的朋友。
如果您设置的目标矩形大于源矩形,则使用spritebatch将拉伸纹理。如果您只想渲染其中的一部分,您还可以设置不覆盖整个纹理的源矩形。你是否需要使用textrued?或者你想达到什么目的? –
是的,纹理也应该倾斜,这是我的问题。 – mick