I'm having some problem to draw textures with class "DrawUserIndexPrimitive" on Xna.
I can draw my cubes / models without problem. But I want to draw different textures on my cubes. I loop on each "ID" of a different texture applied to my different cube. But it does not work. I apply every time buffer and vertexPosition with IndexBuffer different from my class "GraphicData."
the final texture to be applied is the same on all my cubes
thank you
Here is my code for function "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;
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++;
}
}
}