# How to use z axis as depth for 2d quads

This topic is 1515 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

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.

Edited by MahanGM

1. 1
2. 2
3. 3
4. 4
frob
15
5. 5

• 16
• 12
• 20
• 12
• 19
• ### Forum Statistics

• Total Topics
632167
• Total Posts
3004527

×