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?

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

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.

  • \$\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\$ – Game_Overture Jun 5 '11 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 Jun 5 '11 at 21:07

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.