Jump to content

  • Log In with Google      Sign In   
  • Create Account

How to use z axis as depth for 2d quads


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
No replies to this topic

#1 MahanGM   Members   -  Reputation: 136

Like
0Likes
Like

Posted 25 June 2014 - 05:39 PM

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, 25 June 2014 - 05:42 PM.


Sponsor:



Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS