• 9
• 10
• 9
• 10
• 10

D3D Font, over the top of a sprite?

This topic is 2956 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

Recommended Posts

I have a very simple question hopefully someone can provide me a decent answer to, googling seems to come up with nothing. I have a sprite and a D3DFONT ( LPD3DXFONT which i then create using D3DXCreateFont and draw ) it all works fine, but the problem is my text is never drawn ontop of the sprite, its always the text *below* the sprite. Without creating my own font class rather than using built in direct x one is there any solution to this? Is it possible to control the layers of what is drawn first in d3d a sprite or text?

Share on other sites
Do you End or Flush the sprite before you draw the font text?
sprite->Begin(...);sprite->Draw(...);sprite->End(...); // or sprite->Flush();font->DrawText(...);

Share on other sites
I end my sprite rather than flush.

http://msdn.microsoft.com/en-us/library/microsoft.windowsmobile.directx.direct3d.sprite.flush.aspx

What sort of result will flushing have? Trying it in code seemed to make no real difference.

My classes for drawing text and sprites are called at different times between my render call but ordering ( fonts later ) seems to make no difference.

Share on other sites
Post your code for drawing the sprite and the text. I've tried to reproduce your problem, but, if I always draw the sprite first, followed by the text, it works fine.

Do you set the sprite position Z-value to 0? Don't think that makes a difference, but I haven't seen your code.

Share on other sites
After trying flush and doing some small swap around i have got it working! Thanks for your help, much appreciated.

Could you explain why flush affects the order of rendering?

Share on other sites
I'm not an expert on the internals, but I believe sprites don't render until End or Flush is called. Then they have their own way of deciding the order in which multiple draws (between Start/End) are rendered.

Even if you don't use the same sprite for the font->DrawText, the text will get rendered at the time of the font->DrawText call. Then, on sprite->End, it renders over the text.