我在Xna上用类“ DrawUserIndexPrimitive ”绘制纹理时遇到了一些问题。
我可以毫无问题地绘制我的立方体/模型。但我想在我的立方体上绘制不同的纹理。 我循环应用于我的不同立方体的不同纹理的每个“ID”。但它不起作用。我使用不同于我的类“GraphicData”的IndexBuffer应用缓冲区和vertexPosition。
要应用的最终纹理在我的所有立方体上都相同
谢谢
这是我的“Draw”功能代码
public void drawWorld(GameTime gameTime)
{
if (needToDraw)
{
int index = 0;
foreach (GraphicData data in graphicData)
{
effet.LightingEnabled = false;
effet.VertexColorEnabled = false;
effet.TextureEnabled = true;
effet.FogEnabled = false;
effet.FogStart = arcadia.camera.NearPlane;
effet.FogEnd = arcadia.camera.FarPlane;
effet.FogColor = new Vector3(1, 1, 1);
effet.View = arcadia.camera.View;
effet.Projection = arcadia.camera.Projection;
effet.Texture = data.Texture2D;
//I hardcoded with a condition for check that the texture changes well in my loop
/*
if (index == 0)
{
effet.Texture = Game.Content.Load<Texture2D>("Models\\Ground\\Land\\ground_land_text1");
}
else
{
effet.Texture = Game.Content.Load<Texture2D>("Models\\Ground\\Land\\ground_land_text2");
}
*/
foreach (EffectPass pass in effet.CurrentTechnique.Passes)
{
pass.Apply();
//Initialize et envoie à la carte graphique le buffer et les vertices
if (data.vertexBuffer != null && data.indexBuffer != null)
{
Game.GraphicsDevice.SetVertexBuffer(data.vertexBuffer);
Game.GraphicsDevice.Indices = data.indexBuffer;
Game.GraphicsDevice.DrawUserIndexedPrimitives(PrimitiveType.TriangleList, data.vertexPosition, 0, data.vertexPosition.Length, data.indices, 0, data.indices.Length / 3);
}
}
index++;
}
}
}