Game Development Stack Exchange is a question and answer site for professional and independent game developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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?

share|improve this question
just used that feature via gameengines sorry :D – Ali.S Jun 3 '11 at 21:23
Gajet: What...? – Olhovsky Jun 4 '11 at 5:43
Balk: What technologies are you using? C++? XNA? – Olhovsky Jun 4 '11 at 5:46
I'm using directX 9 C++. – Balk Jun 5 '11 at 20:57
up vote 2 down vote accepted

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.

share|improve this answer
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. – Balk Jun 5 '11 at 21:01
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 :) – Olhovsky Jun 5 '11 at 21:07

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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