# Cubes drawing on top of each other

In follow up of my previous question: Limit the number of draw calls

I've lowered my draw calls to only 58 a frame!! But now I have another problem. I have 2500 cubes all drawn in the same position. I have no idea why. Everything that was done in my previous question works fine. This is my draw method that draws my chunk.

    public void Draw(BasicEffect effect, ThirdPersonCam cam)
{
device.SetVertexBuffer(vertexBuffer);
device.Indices = indexBuffer;

foreach (EffectPass pass in effect.CurrentTechnique.Passes)
{
no++;
pass.Apply();
effect.VertexColorEnabled = false;
effect.TextureEnabled = true;
effect.Texture = grass;

Matrix center = Matrix.CreateTranslation(new Vector3(-0.5f, -0.5f, -0.5f));
Matrix scale = Matrix.CreateScale(1f);
Matrix translate = Matrix.CreateTranslation(cubePosition);

effect.World = center * scale * translate;
effect.View = cam.view;
effect.Projection = cam.proj;

effect.FogEnabled = true;
effect.FogColor = Color.CornflowerBlue.ToVector3();
effect.FogStart = 1.0f;
effect.FogEnd = 50.0f;

device.DrawIndexedPrimitives(PrimitiveType.TriangleList, 0, 0, 8, 0, 12);
}


There might be some problems with the way the code is ordered in the method, but this is after moving things around. Changing the values in my DrawIndexedPrimitives line to vertices.Count and cubes.Count draws more cubes, but very strangely. There's 4 rows of 50 and then another row with just 10

• I don't mean to offend you or anything, but since you seem to have a lot of problems with somewhat simple problems, I'd recommend you to make simpler 2D games before trying to make complex 3D games (even though voxel engine is somewhat easy to make, it's still a lot harder than, say, 2D tile/isometric engine). – user9790 Jul 14 '13 at 15:24
• I've made a couple 2D games including a tile scroller. I just can't find any good tutorials on what I'm looking for. After I get this engine going, the rest will be easy – Christian Frantz Jul 14 '13 at 15:26
• Are you putting multiple cubes in one buffer? If you're batching, your World matrix is applying only a single cube's position to the whole buffer. You need to translate the cube vertices before putting them into the batch buffer, or use instancing. (The former is better, as you will want to cull cube faces intelligently anyway.) You didn't give enough information for me to know if that's the answer or not. – Sean Middleditch Jul 14 '13 at 16:15
• They're all going into one buffer. I thought that the vertices were translated when they were being put into the buffer? – Christian Frantz Jul 14 '13 at 16:18
• The question I linked in this question shows how its being done – Christian Frantz Jul 14 '13 at 16:22

It's (probably) your DrawIndexedPrimitives call. The correct arguments should be:
device.DrawIndexedPrimitives(PrimitiveType.TriangleList,

Using the Count values from the lists used to create the buffers in the first place (as per your previous question).