title: XNA - Drawing Quads (and primitives) in right order
body: <p>I'm fairly new to 3D-stuff in XNA and unfortunately I have encountered a problem I can't find the solution for. (Don't even know what the problem is).</p>
  
  <p>To cut it short: I am drawing quads in my game using:</p>
  
  <pre><code>        effect.World = Matrix.Identity *
              Matrix.CreateRotationX(Rotation.X) *
              Matrix.CreateRotationY(Rotation.Y) *
              Matrix.CreateRotationZ(Rotation.Z) *
              Matrix.CreateTranslation(Position);
  
          // Apply camera-matrixes
          effect.View = viewMatrix;
          effect.Projection = projectionMatrix;
  
          graphics.VertexDeclaration = vertDec;
  
          // Begin effect drawing
          effect.Begin();
          foreach (EffectPass pass in
              effect.CurrentTechnique.Passes)
          {
              pass.Begin();
              graphics.DrawUserIndexedPrimitives
                  &lt;VertexPositionNormalTexture&gt;(
                  PrimitiveType.TriangleList,
                  quad.Vertices, 0, 4,
                  quad.Indexes, 0, 2);
              pass.End();
          }
  
          effect.End();
  </code></pre>
  
  <p>My effect also has these properties:</p>
  
  <pre><code>        this.effect.TextureEnabled = true;
          this.effect.Texture = texture;
  </code></pre>
  
  <p>And it works. My quad is drawn nicely and me is happy. However there is one slight problem. If one quad is behind another quad or regular model the way that determines which is drawn on top is the order that I draw them in.</p>
  
  <p>Lets say I draw Quad A before Quad B, then B will be shown as on top of Quad A even if it is 40 units lesser in the Z-axis. Looks very confusing I must say! ;)</p>
  
  <p>Now I haven't had any problem like this with my regular meshes, it is when primitives are involved things get this messy. The very same problem goes for drawing regular lines:</p>
  
  <pre><code>            graphics.DrawUserIndexedPrimitives&lt;VertexPositionColor&gt;(
                  PrimitiveType.LineStrip,
                  pointList,
                  0,  // vertex buffer offset to add to each element of the index buffer
                  6,  // number of vertices in pointList
                  new short[] { 0, 1 },  // the index buffer
                  0,  // first index element to read
                  1   // number of primitives to draw
  </code></pre>
  
  <p>So what I'm asking really is:</p>
  
  <p><strong>A) Is this normal? Should I build a special engine which decides when to draw what?</strong> <em>I can easily work around this in my project by drawing stuff at the right time but I can imagine a game where I could not. A fps for example couldn't draw its billboards all over the place! ;)</em></p>
  
  <p><strong>B) If this is not normal, what could be the cause and what would be a solution/good way to debug the error.</strong></p>
  
  <p>I would appreciate any help to sort this out! :)</p>