How to use z axis as depth for 2d quads

Started by
-1 comments, last by MahanGM 9 years, 10 months ago

I've been drawing primitives recently and I have problem with rendering order. I was expecting by setting different z values for my quads, I'd get a kind of depth system. I'm not sure what I'm doing wrong or even my theory is true.

I simply create my vertices:


Vertex2D vertices[] = {
    {0, 0, 0, color, 0, 0},
    {rect.Width(), 0, 0, color, 1, 0},
    {0, rect.Height(), 0, color, 0, 1},
    {rect.Width(), rect.Height(), 0, color, 1, 1},
    {rect.Width(), 0, 0, color, 1, 0},
};

Then I set translation for them:


D3DXMATRIX translationMatrix;
D3DXMatrixTranslation(&translationMatrix, rect.X() - 0.5f, rect.Y() - 0.5f, depth);

device->SetTransform(D3DTS_WORLD, &translationMatrix);

And finally draw.

Before this, I was using D3DXSprite to draw sprites and I was drawing shapes with the Direct3D device itself. There was a depth problem between primitives drawn by Direct3D device and sprites drawn by D3DXSprite so I decided to switch to textured quads for sprite drawing and eliminate D3DXSprite. D3DXSprite had a front to back depth sort flag that could manage different z values, I don't know if there is a magical way to achieve what D3DXSprite is offering or it's just a simple vector sort, I just need to know what's the solution.

Thanks.

This topic is closed to new replies.

Advertisement