2
\$\begingroup\$

I need the ability to order the drawing of sprites and fonts. Some sprites need to be drawn behind and some in front of text. My problem is that my sprites and fonts use separate Begin() End() calls so I can't simply order the draw calls.

How is sorting generally done in DX9?

\$\endgroup\$
4
  • \$\begingroup\$ just used that feature via gameengines sorry :D \$\endgroup\$
    – Ali1S232
    Commented Jun 3, 2011 at 21:23
  • \$\begingroup\$ Gajet: What...? \$\endgroup\$
    – Olhovsky
    Commented Jun 4, 2011 at 5:43
  • \$\begingroup\$ Balk: What technologies are you using? C++? XNA? \$\endgroup\$
    – Olhovsky
    Commented Jun 4, 2011 at 5:46
  • \$\begingroup\$ I'm using directX 9 C++. \$\endgroup\$ Commented Jun 5, 2011 at 20:57

1 Answer 1

2
\$\begingroup\$

You say that you can't order your sprite drawing because they use separate begin/end calls.

The solution is to separate them into as many begin/end blocks as you need in order to get the sprites into the sorted order that you need.

If this is performance critical and you're trying to reduce state changes, then you can use the same shader to draw your fonts and sprites (fonts are also really just sprites). However, I'm guessing that this is premature optimization.

\$\endgroup\$
2
  • \$\begingroup\$ I'm always constantly concerned with performance, and wanted to avoid any unnecessary begin/end calls. I guess that's just how it has to be in the fixed function pipeline? I guess I should learn shaders now. \$\endgroup\$ Commented Jun 5, 2011 at 21:01
  • \$\begingroup\$ You might be prematurely optimizing. Are we worried about a few extra begin/end calls, or dozens/hundreds of extra calls? Can you really not sort into a few draw calls? You might incur an extra cost in the shader by sharing a shader between font and sprite drawing, depending on what you're doing, but you'd gain some CPU time. That might be worth it, it might not, it depends on your application. This is why some people say that premature optimization is the root of all evil :) \$\endgroup\$
    – Olhovsky
    Commented Jun 5, 2011 at 21:07

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .