Sign in to follow this  

How to use z axis as depth for 2d quads

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.



Edited by MahanGM

Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this