1
\$\begingroup\$

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

\$\endgroup\$
  • 1
    \$\begingroup\$ 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). \$\endgroup\$ – user9790 Jul 14 '13 at 15:24
  • \$\begingroup\$ 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 \$\endgroup\$ – Christian Frantz Jul 14 '13 at 15:26
  • \$\begingroup\$ 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. \$\endgroup\$ – Sean Middleditch Jul 14 '13 at 16:15
  • \$\begingroup\$ They're all going into one buffer. I thought that the vertices were translated when they were being put into the buffer? \$\endgroup\$ – Christian Frantz Jul 14 '13 at 16:18
  • \$\begingroup\$ The question I linked in this question shows how its being done \$\endgroup\$ – Christian Frantz Jul 14 '13 at 16:22
1
\$\begingroup\$

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

device.DrawIndexedPrimitives(PrimitiveType.TriangleList,
        0, 0, vertices.Count, 0, indices.Count / 3);

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

See the documentation on MSDN.

\$\endgroup\$
  • \$\begingroup\$ That worked!! Only 56 draw calls a frame finally \$\endgroup\$ – Christian Frantz Jul 14 '13 at 16:33
  • \$\begingroup\$ @ChristianFrantz Glad to hear it :) \$\endgroup\$ – Andrew Russell Jul 14 '13 at 16:36

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.